AutoMapper使用DeploymentItem属性进行单元测试无法工作 - PlatformNotSupportedException

4
我正在尝试在使用DeploymentItem属性的单元测试中使用AutoMapper,以便在运行时读取文件。
这是我的代码:
    [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: 

谢谢!


欢迎来到SO,Javier。 - Brian
关于这个问题,您确定移除DeploymentItem属性后测试仍然能够正常工作吗?我在没有DeploymentItem属性的情况下仍然遇到了相同的错误。 - Spock
Raj,感谢您的回答。我在一个新项目上再次复制了错误,仍然得到相同的错误。有趣的是,我正在使用带有.Net 4.5和resharper 7.1.3完整版的VS 2012 11.0.60315.01 Update 2,仍然遇到与上述相同的情况。 - Javier Capello
1个回答

2

我认为这与部署项目无关。我复制了该问题,但在安装install-package AutoMapper.NET35后问题消失了。


我已经安装了AutoMapper包,并且刚刚安装了你提到的那个,起到了作用。谢谢! - Javier Capello

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接