コード例 #1
0
        private IEnumerable <UnitTestElement> GetTests(string source)
        {
            var pluginPath = Path.GetDirectoryName(GetType().Assembly.Location);
            var sourcePath = Path.GetDirectoryName(source);
            var paths      = new[] { pluginPath, sourcePath };

            // Set up a separate app domain to avoid locking files.
            using (new AssemblyResolver(paths))
                using (var testDomain = Dispose.Of(AppDomain.CreateDomain($"{nameof(MSTestAutomationDiscoverer)}: {Path.GetFileName(source)}",
                                                                          AppDomain.CurrentDomain.Evidence,
                                                                          new AppDomainSetup
                {
                    ApplicationBase = pluginPath,
                    ShadowCopyFiles = "true",
                    ShadowCopyDirectories = sourcePath,
                    AppDomainInitializer = InitializeDomain,
                    AppDomainInitializerArguments = paths,
                    LoaderOptimization = LoaderOptimization.MultiDomain,
                    DisallowBindingRedirects = false
                }), AppDomain.Unload))
                {
                    var testSink = (ITestSink)testDomain.Value.CreateObject <TestSink>();
                    testDomain.Value.SetData("source", source);
                    testDomain.Value.SetData("testSink", testSink);
                    testDomain.Value.DoCallBack(DiscoverTests);
                    return(testSink.Tests);
                }
        }