コード例 #1
0
ファイル: Xunit1Executor.cs プロジェクト: seesharper/xunit-1
 /// <summary>
 /// Initializes a new instance of the <see cref="Xunit1Executor" /> class.
 /// </summary>
 /// <param name="testAssemblyFileName">The filename of the test assembly.</param>
 /// <param name="configFileName">The filename of the configuration file.</param>
 /// <param name="shadowCopy">Set to <c>true</c> to enable shadow copying the assemblies.</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 Xunit1Executor(string testAssemblyFileName, string configFileName = null, bool shadowCopy = true, string shadowCopyFolder = null)
 {
     appDomain                = new RemoteAppDomainManager(testAssemblyFileName, configFileName, shadowCopy, shadowCopyFolder);
     xunitAssemblyPath        = GetXunitAssemblyPath(testAssemblyFileName);
     xunitAssemblyName        = AssemblyName.GetAssemblyName(xunitAssemblyPath);
     executor                 = CreateObject("Xunit.Sdk.Executor", testAssemblyFileName);
     TestFrameworkDisplayName = String.Format(CultureInfo.InvariantCulture, "xUnit.net {0}", AssemblyName.GetAssemblyName(xunitAssemblyPath).Version);
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExecutorWrapper"/> class.
        /// </summary>
        /// <param name="assemblyFilename">The assembly filename.</param>
        /// <param name="configFilename">The config filename. If null, the default config filename will be used.</param>
        /// <param name="shadowCopy">Set to true to enable shadow copying; false, otherwise.</param>
        public ExecutorWrapper(string assemblyFilename, string configFilename, bool shadowCopy)
        {
            assemblyFilename = Path.GetFullPath(assemblyFilename);
            if (!File.Exists(assemblyFilename))
            {
                throw new ArgumentException("Could not find file: " + assemblyFilename);
            }

            if (configFilename == null)
            {
                configFilename = GetDefaultConfigFile(assemblyFilename);
            }

            if (configFilename != null)
            {
                configFilename = Path.GetFullPath(configFilename);
            }

            AssemblyFilename = assemblyFilename;
            ConfigFilename   = configFilename;

            appDomain = CreateAppDomain(assemblyFilename, configFilename, shadowCopy);

            try
            {
                string xunitAssemblyFilename = Path.Combine(Path.GetDirectoryName(assemblyFilename), "xunit.dll");

                if (!File.Exists(xunitAssemblyFilename))
                {
                    throw new ArgumentException("Could not find file: " + xunitAssemblyFilename);
                }

                xunitAssemblyName = AssemblyName.GetAssemblyName(xunitAssemblyFilename);
                executor          = CreateObject("Xunit.Sdk.Executor", AssemblyFilename);

                Version xunitVersion = new Version(XunitVersion);

                if (xunitVersion.Major == 1 && xunitVersion.Minor < 6)
                {
                    if (typeICallbackEventHandler == null)
                    {
                        throw new InvalidOperationException("Attempted to run assembly linked to xUnit.net older than 1.6. This requires the full server version of .NET, which does not appear to be installed.");
                    }

                    MakeIntCallbackHandler     = () => (IntCallbackHandler)intCallbackHandlerCtor.Invoke(new object[0]);
                    MakeXmlNodeCallbackHandler = (callback, lastNodeName) => (XmlNodeCallbackHandler)xmlNodeCallbackHandlerCtor.Invoke(new object[] { callback, lastNodeName });
                }
                else
                {
                    MakeIntCallbackHandler     = () => new IntCallbackHandlerWithIMessageSink();
                    MakeXmlNodeCallbackHandler = (callback, lastNodeName) => new XmlNodeCallbackHandlerWithIMessageSink(callback, lastNodeName);
                }
            }
            catch (TargetInvocationException ex)
            {
                Dispose();
                RethrowWithNoStackTraceLoss(ex.InnerException);
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }
        }