How do I test an Automapper ITypeConverter Converter with a ResolutionContext?
I have a complicated converter and want to test it explicitly.
It needs an argument ResolutionContext which I cannot get to, nor create nor mock.
Is it possible?
public class MyConverter : ITypeConverter<SourceType, TargetType>
{
public TargetType Convert(SourceType source, TargetType destination, ResolutionContext context)
{
...complicated code...
}
}
Edit/Clarification: I am trying to not call myMapper.Map(... but these only the ´MyConverter.Convert` function.
I know it can be considered the wrong-way-to-test as one should only test public methods and this class/method is only public due to technical reasons and should really be private from OO point of view. But that discussion is for another forum.
The source code of the
TypeConverterunit tests of AutoMapper itself show that they follow the regular flow:MapperConfiguration.Mapperfrom it.Mapoverloads.By doing so AutoMapper takes care of passing a
ResolutionContextto theConvertmethod.Below code shows how the
Convertmethod receives aResolutionContextwith a preconfiguredItemsdictionary.