使用自动映射器使用部署项属性进行单元测试不起作用 - PlatformNotSupportedException
本文关键字:单元测试 PlatformNotSupportedException 不起作用 映射 部署 属性 | 更新日期: 2023-09-27 18:35:35
我正在尝试将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>();
但是当我删除部署项属性时,测试工作正常。
我已经阅读了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:
谢谢!
我认为这与部署项目无关。我复制了该问题,但在安装安装包AutoMapper.NET35后消失了