Exemple #1
0
        public void ValueFromUserSpecifiedConfigFile()
        {
            string code =
                @"
                    using System;
                    using System.Configuration;
                    using Xunit;

                    public class MockTestClass
                    {
                        [Fact]
                        public void CheckConfigurationFileEntry()
                        {
                            Assert.Equal(ConfigurationSettings.AppSettings[""ConfigurationValue""], ""42"");
                        }
                    }
                ";

            XmlNode assemblyNode;

            using (MockAssembly mockAssembly = new MockAssembly(assemblyFileName))
            {
                mockAssembly.Compile(code, null);
                assemblyNode = mockAssembly.Run(configFile);
            }

            ResultXmlUtility.AssertResult(assemblyNode, "Pass", "MockTestClass.CheckConfigurationFileEntry");
            Assert.Equal(Path.GetFullPath(configFile), assemblyNode.Attributes["configFile"].Value);
        }
Exemple #2
0
        public void ConfigurationExceptionShouldBeThrown()
        {
            string code =
                @"
                    using System;
                    using System.Configuration;
                    using Xunit;

                    public class MockTestClass
                    {
                        [Fact]
                        public void TestMethod()
                        {
                        }
                    }
                ";

            XmlNode assemblyNode;

            using (MockAssembly mockAssembly = new MockAssembly(assemblyFileName))
            {
                mockAssembly.Compile(code, null);
                assemblyNode = mockAssembly.Run(configFile);
            }

            var resultNode  = ResultXmlUtility.GetResult(assemblyNode);
            var failureNode = resultNode.SelectSingleNode("failure");

            Assert.NotNull(failureNode);
            Assert.Equal("System.Configuration.ConfigurationErrorsException", failureNode.Attributes["exception-type"].Value);
        }
 public void AssemblyFilenameInXmlMatchesOriginallyPassedNameToExecutor()
 {
     using (MockAssembly mockAssembly = new MockAssembly())
     {
         mockAssembly.Compile("");
         XmlNode assemblyNode = mockAssembly.Run(null);
         ResultXmlUtility.AssertAttribute(assemblyNode, "name", mockAssembly.FileName);
     }
 }
Exemple #4
0
    public void TestsFromAbstractBaseClassesShouldBeExecuted()
    {
        string code = @"
            using Xunit;

            public class TestClass
            {
                [Fact]
                public void TestMethod() {}
            }
        ";

        XmlNode xmlFromExecutorWrapper;
        XmlNode xmlFromMate;

        using (MockAssembly mockAssembly = new MockAssembly())
        {
            mockAssembly.Compile(code);
            xmlFromExecutorWrapper = mockAssembly.Run();
            xmlFromMate            = mockAssembly.RunWithMate();
        }

        // Make sure that we have these (and only these) attributes
        AssertExactAttributeList(
            xmlFromExecutorWrapper,
            "name", "configFile", "total", "passed", "failed", "skipped", "environment",
            "time", "run-date", "run-time", "test-framework"
            );
        AssertExactAttributeList(
            xmlFromMate,
            "name", "configFile", "total", "passed", "failed", "skipped", "environment",
            "time", "run-date", "run-time", "test-framework"
            );

        // Only compare values on assembly node, because we know that MATE
        // uses the actual XML from Executor for classes & tests. We can't
        // do equivalence for "time", "run-date", "run-time" because of variance.
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "name");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "configFile");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "total");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "passed");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "failed");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "skipped");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "environment");
        AssertAttributeEqual(xmlFromExecutorWrapper, xmlFromMate, "test-framework");
    }