第一次使用 MSTest 运行单元测试时,自动映射器出现错误

发布于 2024-09-02 04:25:14 字数 815 浏览 5 评论 0原文

第一次在 VS 2008 (MSTest) 中运行单元测试时,我们遇到了 Automapper 错误。 “缺少类型映射配置或不受支持的映射。抛出了‘AutoMapper.AutoMapperMappingException’类型的异常”

如果我们重新运行测试(“运行检查的测试”),那么它们都会通过。 4 个开发人员中只有 2 个遇到此问题。我们尝试向“Bootstrapper”添加超时,但这不起作用。有人遇到这个问题吗?

引导程序代码如下所示:

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;
        }

    }
}

We are getting an Automapper error the FIRST time we run our Unit Tests in VS 2008 (MSTest).
"Missing type map configuration or unsupported mapping. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown"

If we re-run the tests ("Run Checked Tests") then they all pass. Only 2 out of the 4 developers are having this issue. 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;
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望她远 2024-09-09 04:25:14

想出了解决办法。我们没有在每个单元测试中将 IsConfigured 设置为 false(废话)。仍然不确定为什么它可以在某些机器上运行。

Figured out the solution. We where not setting IsConfigured to false on each unit test (Duh). Still not sure why it was working on some machines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文