Esempio n. 1
0
        public void ExecuteForClassInitializeThrowingExceptionShouldReturnUnitTestResultWithFailedOutcome()
        {
            // Arrange.
            var tai = new TestAssemblyInfo(typeof(DummyTestClass).Assembly);

            var constructorInfo     = typeof(DummyTestClass).GetConstructors().Single();
            var classAttribute      = new UTF.TestClassAttribute();
            var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext");

            var tci = new TestClassInfo(
                type: typeof(DummyTestClass),
                constructor: constructorInfo,
                testContextProperty: testContextProperty,
                classAttribute: classAttribute,
                parent: tai)
            {
                ClassInitializeMethod = typeof(TestMethodRunnerTests).GetMethod(
                    "InitMethodThrowingException",
                    BindingFlags.Static | BindingFlags.NonPublic)
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, tci, this.testMethodOptions, () => { throw new Exception("DummyException"); });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            // Act.
            var results = testMethodRunner.Execute();

            // Assert.
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
            StringAssert.Contains(results[0].ErrorMessage, "System.ArgumentException: Value does not fall within the expected range.");
        }
Esempio n. 2
0
        bool ShouldRunAssembly(TestAssemblyInfo assemblyInfo)
        {
            if (assemblyInfo == null)
            {
                return(false);
            }

            if (AssemblyFilters == null || AssemblyFilters.Count == 0)
            {
                return(true);
            }

            bool include;

            if (AssemblyFilters.TryGetValue(assemblyInfo.FullPath, out include))
            {
                return(ReportFilteredAssembly(assemblyInfo, include));
            }

            string fileName = Path.GetFileName(assemblyInfo.FullPath);

            if (AssemblyFilters.TryGetValue(fileName, out include))
            {
                return(ReportFilteredAssembly(assemblyInfo, include));
            }

            fileName = Path.GetFileNameWithoutExtension(assemblyInfo.FullPath);
            if (AssemblyFilters.TryGetValue(fileName, out include))
            {
                return(ReportFilteredAssembly(assemblyInfo, include));
            }

            return(runAssemblyByDefault);
        }
Esempio n. 3
0
        bool ReportFilteredAssembly(TestAssemblyInfo assemblyInfo, bool include)
        {
            if (LogExcludedTests)
            {
                const string included = "Included";
                const string excluded = "Excluded";

                OnInfo($"[FILTER] {(include ? included : excluded)} assembly: {assemblyInfo.FullPath}");
            }
            return(include);
        }
Esempio n. 4
0
        public TestMethodRunnerTests()
        {
            var constructorInfo = typeof(DummyTestClass).GetConstructors().Single();

            this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod"));
            var classAttribute = new UTF.TestClassAttribute();

            this.testMethodAttribute = new UTF.TestMethodAttribute();
            var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext");

            var testAssemblyInfo = new TestAssemblyInfo(typeof(DummyTestClass).Assembly);

            this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false);
            this.testContextImplementation = new TestContextImplementation(this.testMethod, new StringWriter(), new Dictionary <string, object>());
            this.testClassInfo             = new TestClassInfo(
                type: typeof(DummyTestClass),
                constructor: constructorInfo,
                testContextProperty: testContextProperty,
                classAttribute: classAttribute,
                parent: testAssemblyInfo);

            this.globaltestMethodOptions = new TestMethodOptions()
            {
                Timeout           = 3600 * 1000,
                Executor          = this.testMethodAttribute,
                TestContext       = this.testContextImplementation,
                ExpectedException = null
            };
            var globalTestMethodInfo = new TestMethodInfo(
                this.methodInfo,
                this.testClassInfo,
                this.globaltestMethodOptions);
            var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, null);

            this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false);

            this.testMethodOptions = new TestMethodOptions()
            {
                Timeout           = 200,
                Executor          = this.testMethodAttribute,
                TestContext       = this.testContextImplementation,
                ExpectedException = null
            };

            this.mockReflectHelper = new Mock <ReflectHelper>();

            // Reset test hooks
            DummyTestClass.TestConstructorMethodBody = () => { };
            DummyTestClass.TestContextSetterBody     = value => { };
            DummyTestClass.TestInitializeMethodBody  = value => { };
            DummyTestClass.TestMethodBody            = instance => { };
            DummyTestClass.TestCleanupMethodBody     = value => { };
        }
Esempio n. 5
0
        public TestClassInfoTests()
        {
            this.testClassType        = typeof(DummyTestClass);
            this.testClassConstructor = this.testClassType.GetConstructors().First();
            this.testContextProperty  = this.testClassType.GetProperties().First();
            this.testClassAttribute   = (UTF.TestClassAttribute) this.testClassType.GetCustomAttributes().First();
            this.testAssemblyInfo     = new TestAssemblyInfo();

            this.testClassInfo = new TestClassInfo(
                this.testClassType,
                this.testClassConstructor,
                this.testContextProperty,
                this.testClassAttribute,
                this.testAssemblyInfo);

            this.testContext = new Mock <UTFExtension.TestContext>().Object;
        }
Esempio n. 6
0
        public void CanNotifyAssembly()
        {
            const string path = "path/to/assembly.dll";

            var sink    = Substitute.For <IExecutionListener>();
            var cache   = new ElementCache(Array.Empty <ISpecificationElement>());
            var tracker = new RunTracker(Array.Empty <ISpecificationElement>());

            var listener = new ExecutionAdapterRunListener(sink, cache, tracker);

            var assembly = new TestAssemblyInfo(path);

            listener.OnAssemblyStart(assembly);
            listener.OnAssemblyEnd(assembly);

            sink.Received().OnAssemblyStart(path);
            sink.Received().OnAssemblyEnd(path);
        }
Esempio n. 7
0
        private void AppendDomainInfo(TestAssemblyInfo info)
        {
            AppendBoldText(string.Format("\r\n  {0}\r\n", info.DomainName));

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("    ApplicationBase: {0}\r\n", info.ApplicationBase);

            if (info.PrivateBinPath != null)
            {
                string prefix = "    PrivateBinPath: ";
                foreach (string s in info.PrivateBinPath.Split(new char[] { ';' }))
                {
                    sb.AppendFormat("{0}{1}\r\n", prefix, s);
                    prefix = "                    ";
                }
            }

            sb.AppendFormat("    Configuration File: {0}\r\n", info.ConfigurationFile);

            TextBox.AppendText(sb.ToString());
        }
Esempio n. 8
0
        private void AppendAssemblyInfo(TestAssemblyInfo info)
        {
            AppendBoldText(
                string.Format("    {0}\r\n", Path.GetFileNameWithoutExtension(info.Name)));

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("      Path: {0}\r\n", info.Name);
            sb.AppendFormat("      Image Runtime Version: {0}\r\n", info.ImageRuntimeVersion.ToString());

            if (info.TestFrameworks != null)
            {
                string prefix = "      Uses: ";
                foreach (AssemblyName framework in info.TestFrameworks)
                {
                    sb.AppendFormat("{0}{1}\r\n", prefix, framework.FullName);
                    prefix = "            ";
                }
            }

            TextBox.AppendText(sb.ToString());
        }
Esempio n. 9
0
        public TestMethodRunnerTests()
        {
            var constructorInfo = typeof(DummyTestClass).GetConstructors().Single();

            this.methodInfo = typeof(DummyTestClass).GetMethods().Single(m => m.Name.Equals("DummyTestMethod"));
            var classAttribute = new UTF.TestClassAttribute();

            this.testMethodAttribute = new UTF.TestMethodAttribute();
            var testContextProperty = typeof(DummyTestClass).GetProperty("TestContext");

            var testAssemblyInfo = new TestAssemblyInfo();

            this.testMethod = new TestMethod("dummyTestName", "dummyClassName", "dummyAssemblyName", false);
            this.testContextImplementation = new TestContextImplementation(this.testMethod, null, new Dictionary <string, object>());
            this.testClassInfo             = new TestClassInfo(
                type: typeof(DummyTestClass),
                constructor: constructorInfo,
                testContextProperty: testContextProperty,
                classAttribute: classAttribute,
                parent: testAssemblyInfo);
            var globalTestMethodInfo = new TestMethodInfo(
                this.methodInfo,
                timeout: 3600 * 1000,
                executor: this.testMethodAttribute,
                expectedException: null,
                parent: this.testClassInfo,
                testContext: this.testContextImplementation);

            this.globalTestMethodRunner = new TestMethodRunner(globalTestMethodInfo, this.testMethod, this.testContextImplementation, false);

            // Reset test hooks
            DummyTestClass.TestConstructorMethodBody = () => { };
            DummyTestClass.TestContextSetterBody     = value => { };
            DummyTestClass.TestInitializeMethodBody  = value => { };
            DummyTestClass.TestMethodBody            = instance => { };
            DummyTestClass.TestCleanupMethodBody     = value => { };
        }
Esempio n. 10
0
    public bool IsExcluded(TestAssemblyInfo assembly, Action <string>?reportFilteredAssembly = null)
    {
        if (FilterType != XUnitFilterType.Assembly)
        {
            throw new InvalidOperationException("Filter is not targeting assemblies.");
        }

        Func <bool, bool> log = (result) => ReportFilteredAssembly(assembly, result, reportFilteredAssembly);

        if (string.Equals(AssemblyName, assembly.FullPath, StringComparison.Ordinal))
        {
            return(log(Exclude));
        }

        string fileName = Path.GetFileName(assembly.FullPath);

        if (string.Equals(fileName, AssemblyName, StringComparison.Ordinal))
        {
            return(log(Exclude));
        }

        // No path of the name matched the filter, therefore return the opposite of the Exclude value
        return(log(!Exclude));
    }
Esempio n. 11
0
 private void AppendProcessInfo(TestAssemblyInfo info)
 {
     AppendProcessInfo(info.ProcessId, info.ModuleName, info.RunnerRuntimeFramework);
 }
Esempio n. 12
0
 public TestAssemblyInfoTests()
 {
     this.testAssemblyInfo = new TestAssemblyInfo(typeof(TestAssemblyInfoTests).Assembly);
     this.dummyMethodInfo  = typeof(TestAssemblyInfoTests).GetMethods().First();
     this.testContext      = new Mock <UTFExtension.TestContext>().Object;
 }
Esempio n. 13
0
            internal void IsExcludedAsAssembly(XUnitFiltersCollection collection, TestAssemblyInfo assemblyInfo, bool excluded)
            {
                var wasExcluded = collection.IsExcluded(assemblyInfo);

                Assert.Equal(excluded, wasExcluded);
            }
Esempio n. 14
0
 public bool IsExcluded(TestAssemblyInfo assembly, Action <string>?log = null) =>
 IsExcludedInternal(AssemblyFilters, f => f.IsExcluded(assembly, log));