我正在尝试将 AutoMapper 与使用 DeploymentItem 属性的单元测试一起使用,以便在运行时读取文件。
这是我的代码:
[TestClass]
public class UnitTest1
{
[TestMethod]
[DeploymentItem("Samples/demo.csv")]
public void TestMethod1()
{
Mapper.CreateMap<A, B>();
// test logic
}
}
class A
{
public string PropA { get; set; }
public bool PropB { get; set; }
}
class B
{
public string PropA { get; set; }
public bool PropB { get; set; }
}
我在这一行遇到错误:
Mapper.CreateMap<A, B>();
但是当我删除 DeploymentItem 属性时,测试就可以正常工作。
我已经从 AutoMapper 的创建者那里阅读了这篇文章,但似乎并没有解决这个问题。
异常详情如下:
System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=The type initializer for 'AutoMapper.TypeMapFactory' threw an exception.
Source=AutoMapper
TypeName=AutoMapper.TypeMapFactory
StackTrace:
at AutoMapper.TypeMapFactory..ctor()
at AutoMapper.Mapper.<.cctor>b__0()
at AutoMapper.Internal.LazyFactory.LazyImpl`1.get_Value()
at AutoMapper.Mapper.get_ConfigurationProvider()
at AutoMapper.Mapper.get_Configuration()
at AutoMapper.Mapper.CreateMap[TSource,TDestination]()
at TNS.T4.MVC.Tests.Mocks.UnitTest1.TestMethod1() in c:\tns.visualstudio.com\Research Platform\Development\T4\TNS.T4.MVC.Tests\Mocks\UnitTest1.cs:line 13
InnerException: System.PlatformNotSupportedException
HResult=-2146233031
Message=This type is not supported on this platform IDictionaryFactory
Source=AutoMapper
StackTrace:
at AutoMapper.Internal.PlatformAdapter.Resolve[T](Boolean throwIfNotFound)
at AutoMapper.TypeMapFactory..cctor()
InnerException:
谢谢!