简体   繁体   English

第一次我们使用MSTest运行单元测试时出现Automapper错误

[英]Automapper error first time we run Unit Tests with MSTest

We are getting an Automapper error the FIRST time we run our Unit Tests in VS 2008 (MSTest). 第一次在VS 2008(MSTest)中运行单元测试时,我们遇到了Automapper错误。 "Missing type map configuration or unsupported mapping. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown" “缺失型地图配置或不支持的映射。类型的异常‘AutoMapper.AutoMapperMappingException’被抛出”

If we re-run the tests ("Run Checked Tests") then they all pass. 如果我们重新运行测试(“运行检查的测试”),则它们全部通过。 Only 2 out of the 4 developers are having this issue. 4个开发人员中只有2个出现此问题。 We tried adding a timeout to our "Bootstrapper" but that did not work. 我们尝试将超时添加到“引导程序”中,但这没有用。 Anyone run into this problem? 有人遇到这个问题吗?

Bootstrapper code looks like this: 引导程序代码如下所示:

public static class AutoMapperConfiguration
{
    public static bool IsConfigured { get; set; }
    public static bool IsConfiguring { get; set; }

    public static void Configure()
    {
        do
        {
            Thread.Sleep(10);
        } while (IsConfiguring);

        if (!IsConfigured)
        {
            IsConfiguring = true;
            Mapper.Reset();
            Mapper.Initialize(x => x.AddProfile<DataContractProfile>());
            IsConfiguring = false;
            IsConfigured = true;
        }

    }
}

Figured out the solution. 找出解决方案。 We where not setting IsConfigured to false on each unit test (Duh). 我们在那里没有设置IsConfigured为false,每个单元测试(杜)。 Still not sure why it was working on some machines. 仍然不确定为什么它可以在某些机器上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM