我正在尝试将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的创建者this article,但似乎无法解决问题。
以下例外情况:
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:
谢谢!
答案 0 :(得分:2)
我认为这不是与部署项目相关的。我复制了这个问题,但在安装了install-package AutoMapper.NET35
后就消失了