예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestFrameworkExecutor{TTestCase}"/> class.
 /// </summary>
 /// <param name="assemblyInfo">The test assembly.</param>
 /// <param name="sourceInformationProvider">The source line number information provider.</param>
 /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
 protected TestFrameworkExecutor(
     _IReflectionAssemblyInfo assemblyInfo,
     _ISourceInformationProvider sourceInformationProvider,
     _IMessageSink diagnosticMessageSink)
 {
     this.assemblyInfo = Guard.ArgumentNotNull(nameof(assemblyInfo), assemblyInfo);
     this.sourceInformationProvider = Guard.ArgumentNotNull(nameof(sourceInformationProvider), sourceInformationProvider);
     this.diagnosticMessageSink     = Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="XunitTestFrameworkExecutor"/> class.
 /// </summary>
 /// <param name="assemblyInfo">The test assembly.</param>
 /// <param name="configFileName">The test configuration file.</param>
 /// <param name="sourceInformationProvider">The source line number information provider.</param>
 /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
 public XunitTestFrameworkExecutor(
     _IReflectionAssemblyInfo assemblyInfo,
     string?configFileName,
     _ISourceInformationProvider sourceInformationProvider,
     _IMessageSink diagnosticMessageSink)
     : base(assemblyInfo, sourceInformationProvider, diagnosticMessageSink)
 {
     testAssembly = new TestAssembly(AssemblyInfo, configFileName, assemblyInfo.Assembly.GetName().Version);
     discoverer   = new Lazy <XunitTestFrameworkDiscoverer>(() => new XunitTestFrameworkDiscoverer(AssemblyInfo, configFileName, SourceInformationProvider, DiagnosticMessageSink));
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkDiscoverer"/> class.
        /// </summary>
        /// <param name="assemblyInfo">The test assembly.</param>
        /// <param name="configFileName">The configuration filename.</param>
        /// <param name="sourceProvider">The source information provider.</param>
        /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
        protected TestFrameworkDiscoverer(
            _IAssemblyInfo assemblyInfo,
            string?configFileName,
            _ISourceInformationProvider sourceProvider,
            _IMessageSink diagnosticMessageSink)
        {
            this.assemblyInfo          = Guard.ArgumentNotNull(nameof(assemblyInfo), assemblyInfo);
            this.configFileName        = configFileName;
            this.diagnosticMessageSink = Guard.ArgumentNotNull(nameof(diagnosticMessageSink), diagnosticMessageSink);
            this.sourceProvider        = Guard.ArgumentNotNull(nameof(sourceProvider), sourceProvider);

            targetFramework = new Lazy <string>(() => AssemblyInfo.GetTargetFramework());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class.
        /// </summary>
        /// <param name="assemblyInfo">The test assembly.</param>
        /// <param name="configFileName">The test configuration file.</param>
        /// <param name="sourceProvider">The source information provider.</param>
        /// <param name="diagnosticMessageSink">The message sink which receives <see cref="_DiagnosticMessage"/> messages.</param>
        /// <param name="collectionFactory">The test collection factory used to look up test collections.</param>
        public XunitTestFrameworkDiscoverer(
            _IAssemblyInfo assemblyInfo,
            string?configFileName,
            _ISourceInformationProvider sourceProvider,
            _IMessageSink diagnosticMessageSink,
            IXunitTestCollectionFactory?collectionFactory = null)
            : base(assemblyInfo, configFileName, sourceProvider, diagnosticMessageSink)
        {
            var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault();
            var disableParallelization      = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization");

            var testAssembly = new TestAssembly(assemblyInfo, configFileName);

            TestAssemblyUniqueID = testAssembly.UniqueID;

            TestCollectionFactory =
                collectionFactory
                ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly)
                ?? new CollectionPerClassTestCollectionFactory(testAssembly, diagnosticMessageSink);

            TestFrameworkDisplayName = $"{DisplayName} [{TestCollectionFactory.DisplayName}, {(disableParallelization ? "non-parallel" : "parallel")}]";
        }
예제 #5
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)"}";
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Xunit2SourceInformationProvider"/> class.
        /// </summary>
        /// <param name="v3Provider"></param>
        public Xunit2SourceInformationProvider(_ISourceInformationProvider v3Provider)
        {
            disposalTracker.Add(v3Provider);

            this.v3Provider = Guard.ArgumentNotNull(nameof(v3Provider), v3Provider);
        }
 /// <summary>
 /// Create a <see cref="ISourceInformationProvider"/> adapter around a <see cref="_ISourceInformationProvider"/>
 /// instance.
 /// </summary>
 public static ISourceInformationProvider Adapt(_ISourceInformationProvider v3Provider) =>
 new Xunit2SourceInformationProvider(v3Provider);
예제 #8
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);
            }
        }