Resharper runs UnitTest from different location

前端 未结 10 774
清歌不尽
清歌不尽 2020-12-01 15:46

When I run unit tests with Visual Studio it works fine, because it runs from project directory where all assemblies are. But when I run it with resharper it

10条回答
  •  青春惊慌失措
    2020-12-01 16:14

    Try this code for loading (see below). It will lookup assemblies independent of test runner.

    private static string[] assemblyLookupPath = new[]
    {
        AppDomain.CurrentDomain.BaseDirectory, 
        Environment.CurrentDirectory,
        Assembly.GetExecutingAssembly().Location
    }.Distinct().ToArray();
    
    public static void Assembly Load(string fileName)
    {
         var filePath = assemblyLookupPath
             .Select(f=>Path.Combine(f, fileName))
             .Where(File.Exists)
             .FirstOrDefault();
    
         /*do here null checks and raise errors, write logs, etc*/
    
         return Assembly.LoadFrom(filePath )
    }
    

提交回复
热议问题