RunClass() 공개 메소드

public RunClass ( string type, Predicate callback ) : XmlNode
type string
callback Predicate
리턴 System.Xml.XmlNode
        /// <summary>
        /// Run all the unit tests in the class
        /// </summary>
        /// <param name="assemblyPath">The assembly that contains the unit test.</param>
        /// <param name="className">The full name of the class that contains the unit test.</param>
		override public void RunTests(string assemblyPath, string assemblyName, string className)
        {
            System.Xml.XmlNode returnValue = null;

            using (ExecutorWrapper wrapper = new ExecutorWrapper(assemblyPath, null, true))
            {
				returnValue = wrapper.RunClass(className, node => true);
            }

            ParseResults(returnValue);
        }
예제 #2
0
        public void Should_be_able_to_run_the_simple_example()
        {
            using (MockAssembly assembly = new MockAssembly())
            {

                XmlNode lastNode = null;
                XmlNode returnValue = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper("Coulda.Examples.dll", null, false))
                    returnValue = wrapper.RunClass("Coulda.Examples.SimpleExample", node => { lastNode = node; return true; });

                XmlNode resultNode = ResultXmlUtility.GetResult(lastNode);
                ResultXmlUtility.AssertAttribute(resultNode, "name", "My example test should be able to assert");
                ResultXmlUtility.AssertAttribute(resultNode, "type", "Coulda.Examples.SimpleExample");
                ResultXmlUtility.AssertAttribute(resultNode, "method", "A_simple_example");
                ResultXmlUtility.AssertAttribute(resultNode, "result", "Pass");
            }
        }
예제 #3
0
        public void Should_be_able_to_have_a_failing_test()
        {
            using (MockAssembly assembly = new MockAssembly())
            {

                XmlNode lastNode = null;
                XmlNode returnValue = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper("Coulda.Examples.dll", null, false))
                    returnValue = wrapper.RunClass("Coulda.Examples.FailingExample", node => { lastNode = node; return true; });

                XmlNode resultNode = ResultXmlUtility.GetResult(lastNode);
                ResultXmlUtility.AssertAttribute(resultNode, "name", "A test with an assertion should be able to fail");
                ResultXmlUtility.AssertAttribute(resultNode, "type", "Coulda.Examples.FailingExample");
                ResultXmlUtility.AssertAttribute(resultNode, "method", "A_failing_example");
                ResultXmlUtility.AssertAttribute(resultNode, "result", "Fail");
            }
        }
예제 #4
0
        public void CanCancelBetweenTestMethodRuns()
        {
            string code = @"
                    using Xunit;

                    public class TestClass
                    {
                        [Fact]
                        public void TestMethod1()
                        {
                        }

                        [Fact]
                        public void TestMethod2()
                        {
                        }
                    }";

            using (MockAssembly assembly = new MockAssembly())
            {
                assembly.Compile(code);

                XmlNode lastNode = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false))
                    wrapper.RunClass("TestClass", node => { lastNode = node; return false; });

                Assert.Equal(0, lastNode.ChildNodes.Count);   // Cancels from the start of the first test
            }
        }
예제 #5
0
        public void InvalidClassName()
        {
            string code = @"
                    using Xunit;

                    public class TestClass
                    {
                    }";

            using (MockAssembly assembly = new MockAssembly())
            {
                assembly.Compile(code);

                using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false))
                    Assert.Throws<ArgumentException>(() => wrapper.RunClass("TestClassIsNotMe", null));
            }
        }
예제 #6
0
        public void ClassWhichHasNoTests()
        {
            string code = @"
                    using Xunit;

                    public class PlainOldDotNetClass
                    {
                    }";

            using (MockAssembly assembly = new MockAssembly())
            {
                assembly.Compile(code);

                XmlNode lastNode = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false))
                    wrapper.RunClass("PlainOldDotNetClass", node => { lastNode = node; return true; });

                Assert.Equal("class", lastNode.Name);
                Assert.Equal(0, lastNode.ChildNodes.Count);   // Empty class node
            }
        }
예제 #7
0
        public void AcceptanceTest()
        {
            string code = @"
                    using Xunit;

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

            using (MockAssembly assembly = new MockAssembly())
            {
                assembly.Compile(code);

                XmlNode lastNode = null;
                XmlNode returnValue = null;

                using (ExecutorWrapper wrapper = new ExecutorWrapper(assembly.FileName, null, false))
                    returnValue = wrapper.RunClass("TestClass", node => { lastNode = node; return true; });

                XmlNode resultNode = ResultXmlUtility.GetResult(lastNode);
                Assert.Equal("Pass", resultNode.Attributes["result"].Value);
                Assert.Equal(returnValue, lastNode);
            }
        }