Пример #1
0
        public XmlNode ExecuteWithCustomAssemblyName(string code, string assemblyName)
        {
            using (MockAssembly mockAssembly = new MockAssembly(assemblyName))
            {
                string fullAssemblyName = Path.GetFullPath(assemblyName);
                string assemblyPath = Path.GetDirectoryName(fullAssemblyName);
                string xunitCopyFilename = Path.Combine(assemblyPath, "xunit.dll");
                File.Copy(mockAssembly.XunitDllFilename, xunitCopyFilename, true);

                try
                {
                    mockAssembly.Compile(code, null);
                    return mockAssembly.Run(null);
                }
                finally
                {
                    try
                    {
                        if (xunitCopyFilename != null && File.Exists(xunitCopyFilename))
                            File.Delete(xunitCopyFilename);
                    }
                    catch { } // Throws on Mono because of a lack of shadow copying
                }
            }
        }
Пример #2
0
        public XmlNode ExecuteWithCustomAssemblyName(string code, string assemblyName)
        {
            using (MockAssembly mockAssembly = new MockAssembly(assemblyName))
            {
                string fullAssemblyName  = Path.GetFullPath(assemblyName);
                string assemblyPath      = Path.GetDirectoryName(fullAssemblyName);
                string xunitCopyFilename = Path.Combine(assemblyPath, "xunit.dll");
                File.Copy(mockAssembly.XunitDllFilename, xunitCopyFilename, true);

                try
                {
                    mockAssembly.Compile(code, null);
                    return(mockAssembly.Run(null));
                }
                finally
                {
                    try
                    {
                        if (xunitCopyFilename != null && File.Exists(xunitCopyFilename))
                        {
                            File.Delete(xunitCopyFilename);
                        }
                    }
                    catch { }                     // Throws on Mono because of a lack of shadow copying
                }
            }
        }
Пример #3
0
 public XmlNode Execute(string code, string configFile, params string[] references)
 {
     using (MockAssembly mockAssembly = new MockAssembly())
     {
         mockAssembly.Compile(code, references);
         return mockAssembly.Run(configFile);
     }
 }
Пример #4
0
 public XmlNode Execute(string code, string configFile, params string[] references)
 {
     using (MockAssembly mockAssembly = new MockAssembly())
     {
         mockAssembly.Compile(code, references);
         return(mockAssembly.Run(configFile));
     }
 }
 public void AssemblyFilenameInXmlMatchesOriginallyPassedNameToExecutor()
 {
     using (MockAssembly mockAssembly = new MockAssembly())
     {
         mockAssembly.Compile("");
         XmlNode assemblyNode = mockAssembly.Run(null);
         ResultXmlUtility.AssertAttribute(assemblyNode, "name", mockAssembly.FileName);
     }
 }
    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");
    }
Пример #7
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);
        }
Пример #8
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);
        }