using AutoMapper; using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Modularity; using Volo.Abp.TestBase; using Xunit; using IObjectMapper = Volo.Abp.ObjectMapping.IObjectMapper; namespace Volo.Abp.AutoMapper { public class AutoMapper_ConfigurationValidation_Tests : AbpIntegratedTest { private readonly IObjectMapper _objectMapper; public AutoMapper_ConfigurationValidation_Tests() { _objectMapper = ServiceProvider.GetRequiredService(); } [Fact] public void Should_Validate_Configuration() { _objectMapper.Map(new MySourceClass {Value = "42"}).Value.ShouldBe("42"); _objectMapper.Map(new MySourceClass {Value = "42"}).ValueNotMatched.ShouldBe(null); } [DependsOn(typeof(AbpAutoMapperModule))] public class Module : AbpModule { public override void ConfigureServices(IServiceCollection services) { services.Configure(options => { options.UseStaticMapper = false; options.AddProfile(true); options.AddProfile(); }); } } public class ValidatedProfile : Profile { public ValidatedProfile() { CreateMap(); } } public class NonValidatedProfile : Profile { public NonValidatedProfile() { CreateMap(); } } public class MySourceClass { public string Value { get; set; } } public class MyClassValidated { public string Value { get; set; } } public class MyClassNonValidated { public string ValueNotMatched { get; set; } } } }