Пример #1
0
    static Xunit2MessageAdapterTests()
    {
        try
        {
            throw new DivideByZeroException();
        }
        catch (Exception ex)
        {
            ThrownException = ex;
        }

        Traits = new Dictionary <string, List <string> >
        {
            { "key1", new List <string> {
                  "value1a", "value1b"
              } },
            { "key2", new List <string> {
                  "value2"
              } },
            { "key3", new List <string>() }
        };

        TestAssembly         = Xunit2Mocks.TestAssembly("testAssembly.dll", "xunit.runner.json");
        TestAssemblyUniqueID = UniqueIDGenerator.ForAssembly(
            TestAssembly.Assembly.Name,
            TestAssembly.Assembly.AssemblyPath,
            TestAssembly.ConfigFileName
            );

        TestCollectionDefinition = Xunit2Mocks.TypeInfo();
        TestCollection           = Xunit2Mocks.TestCollection(TestAssembly, TestCollectionDefinition, "test-collection-display-name");
        TestCollectionUniqueID   = UniqueIDGenerator.ForTestCollection(
            TestAssemblyUniqueID,
            TestCollection.DisplayName,
            TestCollectionDefinition.Name
            );

        TestClassType     = Xunit2Mocks.TypeInfo();
        TestClass         = Xunit2Mocks.TestClass(TestCollection, TestClassType);
        TestClassUniqueID = UniqueIDGenerator.ForTestClass(
            TestCollectionUniqueID,
            TestClass.Class.Name
            );

        TestMethod         = Xunit2Mocks.TestMethod(TestClass, "MyTestMethod");
        TestMethodUniqueID = UniqueIDGenerator.ForTestMethod(
            TestClassUniqueID,
            TestMethod.Method.Name
            );

        TestCase         = Xunit2Mocks.TestCase(TestMethod, "test-case-display-name", "skip-reason", "source-file", 2112, Traits, "test-case-id");
        TestCaseUniqueID = TestCase.UniqueID;

        Test         = Xunit2Mocks.Test(TestCase, "test-display-name");
        TestUniqueID = UniqueIDGenerator.ForTest(TestCaseUniqueID, 0);
    }
Пример #2
0
        public void SuccessCases(
            string assemblyName,
            string?assemblyPath,
            string?configFilePath,
            string expected)
        {
            var actual = UniqueIDGenerator.ForAssembly(assemblyName, assemblyPath, configFilePath);

            Assert.Equal <object>(expected, actual);
        }
Пример #3
0
        public void UniqueIDUsesOnlyShortAssemblyNameForDiscoveryVsExecutionConsistency()
        {
            var longName  = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
            var shortName = "mscorlib";

            var longID  = UniqueIDGenerator.ForAssembly(longName, null, null);
            var shortID = UniqueIDGenerator.ForAssembly(shortName, null, null);

            Assert.NotEmpty(longID);
            Assert.Equal(shortID, longID);
        }
Пример #4
0
        void SendDiscoveryStartingMessage(_IMessageSink messageSink)
        {
            // There is no v2 equivalent to this, so we manufacture it ourselves
            var discoveryStarting = new _DiscoveryStarting
            {
                AssemblyName     = assemblyInfo.Name,
                AssemblyPath     = assemblyInfo.AssemblyPath,
                AssemblyUniqueID = UniqueIDGenerator.ForAssembly(assemblyInfo.Name, assemblyInfo.AssemblyPath, configFileName),
                ConfigFilePath   = configFileName
            };

            messageSink.OnMessage(discoveryStarting);
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestAssembly"/> class.
        /// </summary>
        /// <param name="assembly">The test assembly.</param>
        /// <param name="configFileName">The optional configuration filename</param>
        /// <param name="version">The version number of the assembly (defaults to "0.0.0.0")</param>
        /// <param name="uniqueID">The unique ID for the test assembly (only used to override default behavior in testing scenarios)</param>
        public TestAssembly(
            _IAssemblyInfo assembly,
            string?configFileName = null,
            Version?version       = null,
            string?uniqueID       = null)
        {
            Assembly       = Guard.ArgumentNotNull(assembly);
            ConfigFileName = configFileName;

            this.uniqueID = uniqueID ?? UniqueIDGenerator.ForAssembly(assembly.Name, assembly.AssemblyPath, configFileName);
            Version       =
                version
                ?? (assembly as _IReflectionAssemblyInfo)?.Assembly?.GetName()?.Version
                ?? new Version(0, 0, 0, 0);
        }
Пример #6
0
        /// <summary>
        /// Used for de-serialization.
        /// </summary>
        protected TestAssembly(
            SerializationInfo info,
            StreamingContext context)
        {
            Version        = Guard.NotNull("Could not retrieve Version from serialization", info.GetValue <Version>("Version"));
            ConfigFileName = info.GetValue <string>("ConfigFileName");

            var assemblyPath = Guard.NotNull("Could not retrieve AssemblyPath from serialization", info.GetValue <string>("AssemblyPath"));
            var assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
            var assembly     = System.Reflection.Assembly.Load(new AssemblyName {
                Name = assemblyName, Version = Version
            });

            Assembly = Reflector.Wrap(assembly);

            uniqueID = UniqueIDGenerator.ForAssembly(assemblyName, assemblyPath, ConfigFileName);
        }
Пример #7
0
        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);
            }
        }