我想使用AutoMapper與我的單元測試,使用DeploymentItem屬性爲了在運行時讀取文件。使用DeploymentItem屬性不工作的AutoMapper單元測試 - PlatformNotSupportedException
這裏是我的代碼:
[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:
謝謝!
歡迎來到SO,Javier。 – Brian
謝謝Brian :) –
註冊: - 「但是當我刪除DeploymentItem屬性時,測試工作正常。」你確定嗎。即使沒有DeploymentItem屬性 – Spock