単体テストがあります-セットアップで AutoMapperConfiguration を実行します。次に、実際にマッピングを行うクラスのコンストラクターで IMappingEngine をプライベート プロパティとして設定します。このプロパティを使用すると単体テストは失敗しますが、automapper の静的メソッドを使用すると問題なく動作します。実際のプログラムを実行すると、両方の方法が正常に機能します。私が見ることができる唯一の違いは、単体テストが別のアセンブリにあることです。CLS 準拠がオンになっています。
public class AutomapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<AclassMappingProfile>();
});
}
public static void Reset()
{
Mapper.Reset();
}
}
public class AssetModelFactoryTests
{
[SetUp]
public void SetUp()
{
AutomapperConfiguration.Configure();
}
[Test]
public void TestA()
{
var a = new A();
}
}
public class A
{
private IMappingEngine _mappingEngine;
public A()
{
_mappingEngine = Mapper.Engine;
}
public void DoA()
{
Mapper.Map<Destination>(source); //works
_mappingEngine.Map<Destionation>(source); //Throws mapping not supported
}
}