示例#1
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            if (verifyAssembliesOnDisk)
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);

#if PLATFORM_DOTNET
            CanUseAppDomains = false;
#else
            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            appDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

            var testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
                assemblyInfo = appDomain.CreateObject<IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);

            framework = appDomain.CreateObject<ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XunitFrontController"/> class.
        /// </summary>
        /// <param name="appDomainSupport">Determines whether tests should be run in a separate app domain.</param>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <param name="shadowCopy">If set to <c>true</c>, runs tests in a shadow copied app domain, which allows
        /// tests to be discovered and run without locking assembly files on disk.</param>
        /// <param name="shadowCopyFolder">The path on disk to use for shadow copying; if <c>null</c>, a folder
        /// will be automatically (randomly) generated</param>
        /// <param name="sourceInformationProvider">The source information provider. If <c>null</c>, uses the default (<see cref="T:Xunit.VisualStudioSourceInformationProvider"/>).</param>
        /// <param name="diagnosticMessageSink">The message sink which received <see cref="IDiagnosticMessage"/> messages.</param>
        public XunitFrontController(AppDomainSupport appDomainSupport,
                                    string assemblyFileName,
                                    string configFileName = null,
                                    bool shadowCopy = true,
                                    string shadowCopyFolder = null,
                                    ISourceInformationProvider sourceInformationProvider = null,
                                    IMessageSink diagnosticMessageSink = null)
        {
            this.appDomainSupport = appDomainSupport;
            this.assemblyFileName = assemblyFileName;
            this.configFileName = configFileName;
            this.shadowCopy = shadowCopy;
            this.shadowCopyFolder = shadowCopyFolder;
            this.sourceInformationProvider = sourceInformationProvider;
            this.diagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            Guard.FileExists("assemblyFileName", assemblyFileName);

            if (this.sourceInformationProvider == null)
            {
#if NETSTANDARD1_1
                this.sourceInformationProvider = new NullSourceInformationProvider();
#else
                this.sourceInformationProvider = new VisualStudioSourceInformationProvider(assemblyFileName);
#endif
                toDispose.Push(this.sourceInformationProvider);
            }

        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Xunit2Discoverer"/> class.
 /// </summary>
 /// <param name="appDomainSupport">Determines whether tests should be run in a separate app domain.</param>
 /// <param name="sourceInformationProvider">The source code information provider.</param>
 /// <param name="assemblyInfo">The assembly to use for discovery</param>
 /// <param name="xunitExecutionAssemblyPath">The path on disk of xunit.execution.dll; if <c>null</c>, then
 /// the location of xunit.execution.dll is implied based on the location of the test assembly</param>
 /// <param name="shadowCopyFolder">The path on disk to use for shadow copying; if <c>null</c>, a folder
 /// will be automatically (randomly) generated</param>
 /// <param name="diagnosticMessageSink">The message sink which received <see cref="IDiagnosticMessage"/> messages.</param>
 /// <param name="verifyAssembliesOnDisk">Determines whether or not to check for the existence of assembly files.</param>
 public Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string xunitExecutionAssemblyPath = null,
                         string shadowCopyFolder = null,
                         IMessageSink diagnosticMessageSink = null,
                         bool verifyAssembliesOnDisk = true)
     : this(appDomainSupport, sourceInformationProvider, assemblyInfo, null, xunitExecutionAssemblyPath ?? GetXunitExecutionAssemblyPath(appDomainSupport, assemblyInfo), null, true, shadowCopyFolder, diagnosticMessageSink, verifyAssembliesOnDisk)
 { }
示例#4
0
 // Used by Xunit2 when initializing for both discovery and execution.
 internal Xunit2Discoverer(AppDomainSupport appDomainSupport,
                           ISourceInformationProvider sourceInformationProvider,
                           string assemblyFileName,
                           string configFileName,
                           bool shadowCopy,
                           string shadowCopyFolder = null,
                           IMessageSink diagnosticMessageSink = null,
                           bool verifyAssembliesOnDisk = true)
     : this(appDomainSupport, sourceInformationProvider, null, assemblyFileName, GetXunitExecutionAssemblyPath(appDomainSupport, assemblyFileName, verifyAssembliesOnDisk), configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink, verifyAssembliesOnDisk)
 { }
示例#5
0
 protected static void Go(string assemblyFileName, Stream stream, AppDomainSupport appDomainSupport,
     Action<XunitFrontController, TestAssemblyConfiguration, ClientWriter> action)
 {
     using (AssemblyHelper.SubscribeResolve())
     using (var xunit = new XunitFrontController(appDomainSupport, assemblyFileName, shadowCopy: false))
     using (var writer = new ClientWriter(stream))
     {
         var configuration = ConfigReader.Load(assemblyFileName);
         action(xunit, configuration, writer);
     }
 }
 protected static void Go(string assemblyFileName, Stream stream, AppDomainSupport appDomainSupport,
                          Action <XunitFrontController, TestAssemblyConfiguration, ClientWriter> action)
 {
     //using (AssemblyHelper.SubscribeResolve())
     using (var xunit = new XunitFrontController(appDomainSupport, assemblyFileName, shadowCopy: false))
         using (var writer = new ClientWriter(stream))
         {
             var configuration = ConfigReader.Load(assemblyFileName);
             action(xunit, configuration, writer);
         }
 }
示例#7
0
            public static void ValidValues(
                string value,
                AppDomainSupport expected)
            {
                var commandLine = TestableCommandLine.Parse("assemblyName.dll", "no-config.json", "-appdomains", value);

                foreach (var assembly in commandLine.Project.Assemblies)
                {
                    Assert.Equal(expected, assembly.Configuration.AppDomain);
                }
            }
示例#8
0
文件: Xunit2.cs 项目: jbhensley/xunit
        static string GetXunitExecutionAssemblyPath(
            AppDomainSupport appDomainSupport,
            string assemblyFileName,
            bool verifyTestAssemblyExists)
        {
            Guard.ArgumentNotNullOrEmpty(assemblyFileName);
            if (verifyTestAssemblyExists)
            {
                Guard.FileExists(assemblyFileName);
            }

            return(GetExecutionAssemblyFileName(appDomainSupport, Path.GetDirectoryName(assemblyFileName) !));
        }
示例#9
0
 AssemblyRunner2(AppDomainSupport appDomainSupport,
                 string assemblyFileName,
                 TaskCompletionSource <string> tcs,
                 CancellationToken cancellationToken,
                 string configFileName   = null,
                 bool shadowCopy         = true,
                 string shadowCopyFolder = null)
 {
     this.tcs = tcs;
     this.cancellationToken = cancellationToken;
     this.assemblyFileName  = assemblyFileName;
     controller             = new XunitFrontController(appDomainSupport, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink: MessageSinkAdapter.Wrap(this));
     configuration          = ConfigReader.Load(assemblyFileName, configFileName);
 }
示例#10
0
文件: Xunit1.cs 项目: zvirja/xunit
 /// <summary>
 /// Initializes a new instance of the <see cref="Xunit1"/> class.
 /// </summary>
 /// <param name="appDomainSupport">Determines whether tests should be run in a separate app domain.</param>
 /// <param name="sourceInformationProvider">Source code information provider.</param>
 /// <param name="assemblyFileName">The test assembly.</param>
 /// <param name="configFileName">The test assembly configuration file.</param>
 /// <param name="shadowCopy">If set to <c>true</c>, runs tests in a shadow copied app domain, which allows
 /// tests to be discovered and run without locking assembly files on disk.</param>
 /// <param name="shadowCopyFolder">The path on disk to use for shadow copying; if <c>null</c>, a folder
 /// will be automatically (randomly) generated</param>
 public Xunit1(AppDomainSupport appDomainSupport,
               ISourceInformationProvider sourceInformationProvider,
               string assemblyFileName,
               string configFileName   = null,
               bool shadowCopy         = true,
               string shadowCopyFolder = null)
 {
     this.appDomainSupport          = appDomainSupport;
     this.sourceInformationProvider = sourceInformationProvider;
     this.assemblyFileName          = assemblyFileName;
     this.configFileName            = configFileName;
     this.shadowCopy       = shadowCopy;
     this.shadowCopyFolder = shadowCopyFolder;
 }
示例#11
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);

#if NETFRAMEWORK
            // Only safe to assume the execution reference is copied in a desktop project
            if (verifyAssembliesOnDisk)
            {
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);
            }

            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#else
            CanUseAppDomains = false;
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            AppDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

#if NETFRAMEWORK
            var runnerUtilityAssemblyLocation = Path.GetDirectoryName(typeof(AssemblyHelper).Assembly.GetLocalCodeBase());
            assemblyHelper = AppDomain.CreateObjectFrom <AssemblyHelper>(typeof(AssemblyHelper).Assembly.Location, typeof(AssemblyHelper).FullName, runnerUtilityAssemblyLocation);
#endif

            TestFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
            {
                assemblyInfo = AppDomain.CreateObject <IAssemblyInfo>(TestFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);
            }

            Framework = AppDomain.CreateObject <ITestFramework>(TestFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);

            RemoteDiscoverer = Framework.GetDiscoverer(assemblyInfo);
        }
示例#12
0
文件: Xunit2.cs 项目: modai888/xunit
        /// <summary>
        /// Initializes a new instance of the <see cref="Xunit2"/> class.
        /// </summary>
        /// <param name="appDomainSupport">Determines whether tests should be run in a separate app domain.</param>
        /// <param name="sourceInformationProvider">The source code information provider.</param>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <param name="shadowCopy">If set to <c>true</c>, runs tests in a shadow copied app domain, which allows
        /// tests to be discovered and run without locking assembly files on disk.</param>
        /// <param name="shadowCopyFolder">The path on disk to use for shadow copying; if <c>null</c>, a folder
        /// will be automatically (randomly) generated</param>
        /// <param name="diagnosticMessageSink">The message sink which received <see cref="IDiagnosticMessage"/> messages.</param>
        /// <param name="verifyTestAssemblyExists">Determines whether or not the existence of the test assembly is verified.</param>
        public Xunit2(AppDomainSupport appDomainSupport,
                      ISourceInformationProvider sourceInformationProvider,
                      string assemblyFileName,
                      string configFileName = null,
                      bool shadowCopy = true,
                      string shadowCopyFolder = null,
                      IMessageSink diagnosticMessageSink = null,
                      bool verifyTestAssemblyExists = true)
            : base(appDomainSupport, sourceInformationProvider, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink, verifyTestAssemblyExists)
        {
#if PLATFORM_DOTNET
            var an = Assembly.Load(new AssemblyName { Name = Path.GetFileNameWithoutExtension(assemblyFileName) }).GetName();
            var assemblyName = new AssemblyName { Name = an.Name, Version = an.Version };
#else
            var assemblyName = AssemblyName.GetAssemblyName(assemblyFileName);
#endif
            executor = Framework.GetExecutor(assemblyName);
        }
        public static IFrontController Create(
            string assemblyFileName,
            string?configFileName             = null,
            bool shadowCopy                   = true,
            AppDomainSupport appDomainSupport = AppDomainSupport.Required)
        {
            var project         = new XunitProject();
            var projectAssembly = new XunitProjectAssembly(project)
            {
                AssemblyFilename = assemblyFileName,
                ConfigFilename   = configFileName,
            };

            projectAssembly.Configuration.AppDomain  = appDomainSupport;
            projectAssembly.Configuration.ShadowCopy = shadowCopy;

            return(Xunit2.ForDiscoveryAndExecution(projectAssembly, diagnosticMessageSink: new _NullMessageSink()));
        }
示例#14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Xunit2"/> class.
        /// </summary>
        /// <param name="appDomainSupport">Determines whether tests should be run in a separate app domain.</param>
        /// <param name="sourceInformationProvider">The source code information provider.</param>
        /// <param name="assemblyFileName">The test assembly.</param>
        /// <param name="configFileName">The test assembly configuration file.</param>
        /// <param name="shadowCopy">If set to <c>true</c>, runs tests in a shadow copied app domain, which allows
        /// tests to be discovered and run without locking assembly files on disk.</param>
        /// <param name="shadowCopyFolder">The path on disk to use for shadow copying; if <c>null</c>, a folder
        /// will be automatically (randomly) generated</param>
        /// <param name="diagnosticMessageSink">The message sink which received <see cref="IDiagnosticMessage"/> messages.</param>
        /// <param name="verifyTestAssemblyExists">Determines whether or not the existence of the test assembly is verified.</param>
        public Xunit2(AppDomainSupport appDomainSupport,
                      ISourceInformationProvider sourceInformationProvider,
                      string assemblyFileName,
                      string configFileName              = null,
                      bool shadowCopy                    = true,
                      string shadowCopyFolder            = null,
                      IMessageSink diagnosticMessageSink = null,
                      bool verifyTestAssemblyExists      = true)
            : base(appDomainSupport, sourceInformationProvider, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink, verifyTestAssemblyExists)
        {
#if PLATFORM_DOTNET
            var an = Assembly.Load(new AssemblyName {
                Name = Path.GetFileNameWithoutExtension(assemblyFileName)
            }).GetName();
            var assemblyName = new AssemblyName {
                Name = an.Name, Version = an.Version
            };
#else
            var assemblyName = AssemblyName.GetAssemblyName(assemblyFileName);
#endif
            executor = Framework.GetExecutor(assemblyName);
        }
示例#15
0
        Xunit2Discoverer(AppDomainSupport appDomainSupport,
                         ISourceInformationProvider sourceInformationProvider,
                         IAssemblyInfo assemblyInfo,
                         string assemblyFileName,
                         string xunitExecutionAssemblyPath,
                         string configFileName,
                         bool shadowCopy,
                         string shadowCopyFolder,
                         IMessageSink diagnosticMessageSink,
                         bool verifyAssembliesOnDisk)
        {
            Guard.ArgumentNotNull("assemblyInfo", (object)assemblyInfo ?? assemblyFileName);
            if (verifyAssembliesOnDisk)
            {
                Guard.FileExists("xunitExecutionAssemblyPath", xunitExecutionAssemblyPath);
            }

#if PLATFORM_DOTNET
            CanUseAppDomains = false;
#else
            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#endif

            DiagnosticMessageSink = diagnosticMessageSink ?? new NullMessageSink();

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            appDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder);

            var testFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // If we didn't get an assemblyInfo object, we can leverage the reflection-based IAssemblyInfo wrapper
            if (assemblyInfo == null)
            {
                assemblyInfo = appDomain.CreateObject <IAssemblyInfo>(testFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName);
            }

            framework  = appDomain.CreateObject <ITestFramework>(testFrameworkAssemblyName, "Xunit.Sdk.TestFrameworkProxy", assemblyInfo, sourceInformationProvider, DiagnosticMessageSink);
            discoverer = Framework.GetDiscoverer(assemblyInfo);
        }
示例#16
0
        /// <summary>
        /// This constructor is used by factory methods and unit tests only.
        /// </summary>
        protected Xunit1(
            _IMessageSink diagnosticMessageSink,
            AppDomainSupport appDomainSupport,
            _ISourceInformationProvider sourceInformationProvider,
            string assemblyFileName,
            string?configFileName   = null,
            bool shadowCopy         = true,
            string?shadowCopyFolder = null)
        {
            Guard.ArgumentNotNull(nameof(sourceInformationProvider), sourceInformationProvider);
            Guard.ArgumentNotNullOrEmpty(nameof(assemblyFileName), assemblyFileName);

            this.diagnosticMessageSink     = diagnosticMessageSink;
            this.appDomainSupport          = appDomainSupport;
            this.sourceInformationProvider = sourceInformationProvider;
            this.assemblyFileName          = assemblyFileName;
            this.configFileName            = configFileName;
            this.shadowCopy       = shadowCopy;
            this.shadowCopyFolder = shadowCopyFolder;

            testAssemblyName     = Path.GetFileNameWithoutExtension(assemblyFileName);
            TestAssemblyUniqueID = $":v1:assembly:{assemblyFileName}:{configFileName ?? "(null)"}";
        }
示例#17
0
        static string GetExecutionAssemblyFileName(AppDomainSupport appDomainSupport, string basePath)
        {
            var supportedPlatformSuffixes = GetSupportedPlatformSuffixes(appDomainSupport);

            foreach (var suffix in supportedPlatformSuffixes)
            {
#if PLATFORM_DOTNET
                try
                {
                    var assemblyName = $"xunit.execution.{suffix}";
                    Assembly.Load(new AssemblyName { Name = assemblyName });
                    return assemblyName + ".dll";
                }
                catch { }
#else
                var fileName = Path.Combine(basePath, $"xunit.execution.{suffix}.dll");
                if (File.Exists(fileName))
                    return fileName;
#endif
            }

            throw new InvalidOperationException("Could not find any of the following assemblies: " + string.Join(", ", supportedPlatformSuffixes.Select(suffix => $"xunit.execution.{suffix}.dll").ToArray()));
        }
示例#18
0
 public TestableXunit2(string assemblyFileName, string configFileName = null, bool shadowCopy = true, AppDomainSupport appDomainSupport = AppDomainSupport.Required)
     : base(appDomainSupport, new NullSourceInformationProvider(), assemblyFileName, configFileName, shadowCopy)
 {
 }
示例#19
0
 public TestableXunitFrontController(string assemblyFileName, string configFileName = null, bool shadowCopy = true, AppDomainSupport appDomainSupport = AppDomainSupport.Required)
     : base(appDomainSupport, assemblyFileName, configFileName, shadowCopy)
 {
 }
示例#20
0
 TestableXunit1(AppDomainSupport appDomainSupport, string assemblyFileName, string configFileName, bool shadowCopy, string shadowCopyFolder, ISourceInformationProvider sourceInformationProvider)
     : base(appDomainSupport, sourceInformationProvider, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder)
 {
     SourceInformationProvider = sourceInformationProvider;
 }
示例#21
0
 public TestableXunit1(string assemblyFileName = null, string configFileName = null, bool shadowCopy = true, string shadowCopyFolder = null, AppDomainSupport appDomainSupport = AppDomainSupport.Required)
     : this(appDomainSupport, assemblyFileName ?? @"C:\Path\Assembly.dll", configFileName, shadowCopy, shadowCopyFolder, Substitute.For <ISourceInformationProvider>())
 {
     Executor_TestAssemblyFileName = assemblyFileName;
     Executor_ConfigFileName       = configFileName;
     Executor_ShadowCopy           = shadowCopy;
     Executor_ShadowCopyFolder     = shadowCopyFolder;
 }
示例#22
0
 TestableXunit1(AppDomainSupport appDomainSupport, string assemblyFileName, string configFileName, bool shadowCopy, string shadowCopyFolder, ISourceInformationProvider sourceInformationProvider)
     : base(appDomainSupport, sourceInformationProvider, assemblyFileName, configFileName, shadowCopy, shadowCopyFolder)
 {
     SourceInformationProvider = sourceInformationProvider;
 }
示例#23
0
        static string[] GetSupportedPlatformSuffixes(AppDomainSupport appDomainSupport)
        {
#if PLATFORM_DOTNET
            return new[] { "dotnet", "MonoAndroid", "MonoTouch", "iOS-Universal", "universal", "win8", "wp8" };
#else
            return appDomainSupport == AppDomainSupport.Required ? new[] { "desktop" } : new[] { "desktop", "dotnet" };
#endif
        }
示例#24
0
文件: Xunit2.cs 项目: jbhensley/xunit
        Xunit2(
            _IMessageSink diagnosticMessageSink,
            AppDomainSupport appDomainSupport,
            _ISourceInformationProvider sourceInformationProvider,
            _IAssemblyInfo?assemblyInfo,
            string?assemblyFileName,
            string xunitExecutionAssemblyPath,
            string?configFileName,
            bool shadowCopy,
            string?shadowCopyFolder,
            bool verifyAssembliesOnDisk)
        {
#if NETFRAMEWORK
            // Only safe to assume the execution reference is copied in a desktop project
            if (verifyAssembliesOnDisk)
            {
                Guard.FileExists(xunitExecutionAssemblyPath);
            }

            CanUseAppDomains = !IsDotNet(xunitExecutionAssemblyPath);
#else
            CanUseAppDomains = false;
#endif

            DiagnosticMessageSink = diagnosticMessageSink;

            var appDomainAssembly = assemblyFileName ?? xunitExecutionAssemblyPath;
            AppDomain = AppDomainManagerFactory.Create(appDomainSupport != AppDomainSupport.Denied && CanUseAppDomains, appDomainAssembly, configFileName, shadowCopy, shadowCopyFolder, diagnosticMessageSink);
            DisposalTracker.Add(AppDomain);

#if NETFRAMEWORK
            var runnerUtilityAssemblyLocation = Path.GetDirectoryName(typeof(AssemblyHelper).Assembly.GetLocalCodeBase());
            assemblyHelper = AppDomain.CreateObjectFrom <AssemblyHelper>(typeof(AssemblyHelper).Assembly.Location, typeof(AssemblyHelper).FullName !, runnerUtilityAssemblyLocation);
            DisposalTracker.Add(assemblyHelper);
#endif

            TestFrameworkAssemblyName = GetTestFrameworkAssemblyName(xunitExecutionAssemblyPath);

            // We need both a v2 and v3 assembly info, so manufacture the things we're missing
            IAssemblyInfo remoteAssemblyInfo;
            if (assemblyInfo != null)
            {
                remoteAssemblyInfo = new Xunit2AssemblyInfo(assemblyInfo);
            }
            else
            {
                remoteAssemblyInfo = Guard.NotNull(
                    "Could not create Xunit.Sdk.TestFrameworkProxy for v2 unit test",
                    AppDomain.CreateObject <IAssemblyInfo>(TestFrameworkAssemblyName, "Xunit.Sdk.ReflectionAssemblyInfo", assemblyFileName)
                    );
                assemblyInfo = new Xunit3AssemblyInfo(remoteAssemblyInfo);
            }

            this.assemblyInfo    = assemblyInfo;
            this.configFileName  = configFileName;
            TestAssemblyUniqueID = UniqueIDGenerator.ForAssembly(this.assemblyInfo.Name, this.assemblyInfo.AssemblyPath, configFileName);

            var v2SourceInformationProvider = Xunit2SourceInformationProviderAdapter.Adapt(sourceInformationProvider);
            var v2DiagnosticMessageSink     = new Xunit2MessageSink(DiagnosticMessageSink);
            remoteFramework = Guard.NotNull(
                "Could not create Xunit.Sdk.TestFrameworkProxy for v2 unit test",
                AppDomain.CreateObject <ITestFramework>(
                    TestFrameworkAssemblyName,
                    "Xunit.Sdk.TestFrameworkProxy",
                    remoteAssemblyInfo,
                    v2SourceInformationProvider,
                    v2DiagnosticMessageSink
                    )
                );
            DisposalTracker.Add(remoteFramework);

            remoteDiscoverer = Guard.NotNull("Could not get discoverer from test framework for v2 unit test", remoteFramework.GetDiscoverer(remoteAssemblyInfo));
            DisposalTracker.Add(remoteDiscoverer);

            // If we got an assembly file name, that means we can do execution as well as discovery.
            if (assemblyFileName != null)
            {
#if NETFRAMEWORK
                var assemblyName = AssemblyName.GetAssemblyName(assemblyFileName);
#else
                var an = Assembly.Load(new AssemblyName {
                    Name = Path.GetFileNameWithoutExtension(assemblyFileName)
                }).GetName();
                var assemblyName = new AssemblyName {
                    Name = an.Name, Version = an.Version
                };
#endif
                remoteExecutor = remoteFramework.GetExecutor(assemblyName);
                DisposalTracker.Add(remoteExecutor);
            }
        }
示例#25
0
        public static void ValidValues(string value, AppDomainSupport expected)
        {
            var commandLine = TestableCommandLine.Parse("assemblyName.dll", "-appdomains", value);

            Assert.Equal(expected, commandLine.AppDomains);
        }
示例#26
0
 public TestableXunit2(string assemblyFileName, string configFileName = null, bool shadowCopy = true, AppDomainSupport appDomainSupport = AppDomainSupport.Required)
     : base(appDomainSupport, new NullSourceInformationProvider(), assemblyFileName, configFileName, shadowCopy)
 {
 }
示例#27
0
        static string GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, IAssemblyInfo assemblyInfo)
        {
            Guard.ArgumentNotNull("assemblyInfo", assemblyInfo);
            Guard.ArgumentNotNullOrEmpty("assemblyInfo.AssemblyPath", assemblyInfo.AssemblyPath);

            return GetExecutionAssemblyFileName(appDomainSupport, Path.GetDirectoryName(assemblyInfo.AssemblyPath));
        }
示例#28
0
 public TestableXunit1(string assemblyFileName = null, string configFileName = null, bool shadowCopy = true, string shadowCopyFolder = null, AppDomainSupport appDomainSupport = AppDomainSupport.Required)
     : this(appDomainSupport, assemblyFileName ?? @"C:\Path\Assembly.dll", configFileName, shadowCopy, shadowCopyFolder, Substitute.For<ISourceInformationProvider>())
 {
     Executor_TestAssemblyFileName = assemblyFileName;
     Executor_ConfigFileName = configFileName;
     Executor_ShadowCopy = shadowCopy;
     Executor_ShadowCopyFolder = shadowCopyFolder;
 }
示例#29
0
        static string GetXunitExecutionAssemblyPath(AppDomainSupport appDomainSupport, string assemblyFileName, bool verifyTestAssemblyExists)
        {
            Guard.ArgumentNotNullOrEmpty("assemblyFileName", assemblyFileName);
            if (verifyTestAssemblyExists)
                Guard.FileExists("assemblyFileName", assemblyFileName);

            return GetExecutionAssemblyFileName(appDomainSupport, Path.GetDirectoryName(assemblyFileName));
        }
示例#30
0
        static string GetExecutionAssemblyFileName(AppDomainSupport appDomainSupport, string basePath)
        {
            var supportedPlatformSuffixes = GetSupportedPlatformSuffixes(appDomainSupport);

            foreach (var suffix in supportedPlatformSuffixes)
            {
#if PLATFORM_DOTNET
                try
                {
                    var assemblyName = $"xunit.execution.{suffix}";
                    Assembly.Load(new AssemblyName { Name = assemblyName });
                    return assemblyName + ".dll";
                }
                catch { }
#else
                var fileName = Path.Combine(basePath, $"xunit.execution.{suffix}.dll");
                if (File.Exists(fileName))
                    return fileName;
#endif
            }

            throw new InvalidOperationException("Could not find any of the following assemblies: " + string.Join(", ", supportedPlatformSuffixes.Select(suffix => $"xunit.execution.{suffix}.dll").ToArray()));
        }