简体   繁体   中英

Unit Tests pass fine if run one at a time, FileLoadException if run “All Tests in Solution”

I'm trying to unit test some of my classes and having a problem where running the tests individually works fine 100% of the time, but if I run them in bulk / using the "All Tests in Solution" option every single test for one of my files fails with the error:

System.IO.FileLoadException was unhandled by user code
  Message=Could not load file or assembly 'Microsoft.Practices.Prism, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Source=ServicesModuleTests
  FileName=Microsoft.Practices.Prism, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null

I've been trying to figure out why for a long time and have tried searching online but haven't found anyone with this same problem.

Here is a quick example of my code:

RegistryService File:

public class RegistryService
{
    protected ILoggerFacadeExtended _Logger { get; set; }
    protected IConnectivityService _Connectivity { get; set; }

    [ImportingConstructor]
    public RegistryService(ILoggerFacadeExtended logger, IConnectivityService connectivity)
    {
        this._Logger = logger;
        this._Connectivity = connectivity;
    }

    public string GetRegistryPath(RegistryHive hive, string path)
    {
        string registryPath = string.Format("{0}\\{1}", GetRegistryHiveString(hive), path.Trim('\\'));
        _Logger.DebugWithFormat("Found registry path: {0}", registryPath);
        return registryPath;
    }

    private string GetRegistryHiveString(RegistryHive hive)
    {
        switch (hive)
        {
            case RegistryHive.ClassesRoot:
                return "HKEY_CLASSES_ROOT";
            case RegistryHive.CurrentConfig:
                return "HKEY_CURRENT_CONFIG";
            case RegistryHive.CurrentUser:
                return "HKEY_CURRENT_USER";
            case RegistryHive.DynData:
                return "HKEY_DYN_DATA";
            case RegistryHive.LocalMachine:
                return "HKEY_LOCAL_MACHINE";
            case RegistryHive.PerformanceData:
                return "HKEY_PERFORMANCE_DATA";
            case RegistryHive.Users:
                return "HKEY_USERS";
        }
        throw new ArgumentOutOfRangeException("hive");
    }
}

Test File:

private RegistryService CreateMockedRegistryService()
{
    return new RegistryService(MockRepository.GenerateMock<ILoggerFacadeExtended>(), MockRepository.GenerateMock<IConnectivityService>());
}

[TestMethod()]
public void GetRegistryPathTest_ClassesRoot()
{
    RegistryService target = CreateMockedRegistryService();
    RegistryHive hive = RegistryHive.ClassesRoot;
    string path = @"Something\SomethingElse\";
    string expected = @"HKEY_CLASSES_ROOT\Something\SomethingElse";
    string actual;
    actual = target.GetRegistryPath(hive, path);
    Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void GetRegistryPathTest_CurrentConfig()
{
    RegistryService target = CreateMockedRegistryService();
    RegistryHive hive = RegistryHive.CurrentConfig;
    string path = @"Something\SomethingElse\";
    string expected = @"HKEY_CURRENT_CONFIG\Something\SomethingElse";
    string actual;
    actual = target.GetRegistryPath(hive, path);
    Assert.AreEqual(expected, actual);
}

I've dumbed down the code to try to show what I'm doing without taking up too much space here. I can run these one by one without issue, but receive the exception when run all together.

我通过卸载其他单元测试项目然后运行测试直到它工作来解决它,显然其中一个使用了一些较旧的棱镜引用并且这些文件被包含而不是更新的文件,这个问题现在在我删除并重新读取后解决了参考文献。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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