我如何对AfterMap与IMappingAction注入服务一起使用的配置文件进行单元测试。
映射配置文件.cs
public MappingProfile()
{
CreateMap<string, string>()
.ConvertUsing<Core.Converter.TrimStringValueConverter>();
CreateMap<TestModel, TestEntity>(
.AfterMap<AfterMapAction>();
}
Run Code Online (Sandbox Code Playgroud)
AfterMapAction.cs
public class AfterMapAction: IMappingAction<TestModel, TestEntity>
{
private readonly IAfterMapService _afterMapService ;
public AfterMapAction(IAfterMapService aftermapService)
{
_afterMapService = afterMapService ?? throw new ArgumentNullException(nameof(afterMapService));
}
public void Process(TestModel, TestEntity destination, ResolutionContext context)
{
var somevalue = _afterMapService.DoAction(source);
...
}
}
Run Code Online (Sandbox Code Playgroud)
测试.cs
[TestMethod]
public void AutoMapperTest()
{
// Arrange
var model = new TestModel { Id = "4711" , Name = "Test" };
var mapper = …Run Code Online (Sandbox Code Playgroud)