示例#1
0
        public static async void FailedAfter()
        {
            var messageBus = new SpyMessageBus();
            var attribute  = new SpyBeforeAfterTest {
                ThrowInAfter = true
            };
            var invoker = TestableXunitTestInvoker.Create(messageBus, "Display Name", new List <BeforeAfterTestAttribute> {
                attribute
            }, lambda: () => Assert.True(false));

            await invoker.RunAsync();

            var aggEx = Assert.IsType <AggregateException>(invoker.Aggregator.ToException());

            Assert.Collection(
                aggEx.InnerExceptions,
                ex => Assert.IsType <TrueException>(ex),
                ex => Assert.IsType <SpyBeforeAfterTest.AfterException>(ex)
                );
            Assert.Collection(
                messageBus.Messages,
                msg => Assert.IsType <_TestClassConstructionStarting>(msg),
                msg => Assert.IsType <_TestClassConstructionFinished>(msg),
                msg => Assert.IsType <_BeforeTestStarting>(msg),
                msg => Assert.IsType <_BeforeTestFinished>(msg),
                msg => Assert.IsType <_AfterTestStarting>(msg),
                msg => Assert.IsType <_AfterTestFinished>(msg)
                );
        }
示例#2
0
        public static async void FailingAfter_Second()
        {
            var messages   = new List <string>();
            var attribute1 = new RecordingBeforeAfter(messages, 1);
            var attribute2 = new RecordingBeforeAfter(messages, 2)
            {
                ThrowInAfter = true
            };
            var invoker = TestableXunitTestInvoker.Create(
                beforeAfterAttributes: new List <BeforeAfterTestAttribute> {
                attribute1, attribute2
            },
                lambda: () => messages.Add("Test method invocation")
                );

            await invoker.RunAsync();

            Assert.Collection(
                messages,
                msg => Assert.Equal("Before #1", msg),
                msg => Assert.Equal("Before #2", msg),
                msg => Assert.Equal("Test method invocation", msg),
                msg => Assert.Equal("After #2", msg),
                msg => Assert.Equal("After #1", msg)
                );
        }
示例#3
0
        public static async void Success()
        {
            var messageBus = new SpyMessageBus();
            var attribute  = new SpyBeforeAfterTest();
            var invoker    = TestableXunitTestInvoker.Create(messageBus, "Display Name", new List <BeforeAfterTestAttribute> {
                attribute
            });

            await invoker.RunAsync();

            Assert.Null(invoker.Aggregator.ToException());
            Assert.Collection(messageBus.Messages,
                              msg => Assert.IsAssignableFrom <ITestClassConstructionStarting>(msg),   // From TestInvoker
                              msg => Assert.IsAssignableFrom <ITestClassConstructionFinished>(msg),   // From TestInvoker
                              msg =>
            {
                var beforeStarting = Assert.IsAssignableFrom <IBeforeTestStarting>(msg);
                Assert.Same(invoker.TestCase.TestMethod.TestClass.TestCollection, beforeStarting.TestCollection);
                Assert.Same(invoker.TestCase, beforeStarting.TestCase);
                Assert.Equal("Display Name", beforeStarting.Test.DisplayName);
                Assert.Equal("SpyBeforeAfterTest", beforeStarting.AttributeName);
            },
                              msg =>
            {
                var beforeFinished = Assert.IsAssignableFrom <IBeforeTestFinished>(msg);
                Assert.Same(invoker.TestCase.TestMethod.TestClass.TestCollection, beforeFinished.TestCollection);
                Assert.Same(invoker.TestCase, beforeFinished.TestCase);
                Assert.Equal("Display Name", beforeFinished.Test.DisplayName);
                Assert.Equal("SpyBeforeAfterTest", beforeFinished.AttributeName);
            },
                              // Test method is invoked here; no directly observable message (tested below)
                              msg =>
            {
                var afterStarting = Assert.IsAssignableFrom <IAfterTestStarting>(msg);
                Assert.Same(invoker.TestCase.TestMethod.TestClass.TestCollection, afterStarting.TestCollection);
                Assert.Same(invoker.TestCase, afterStarting.TestCase);
                Assert.Equal("Display Name", afterStarting.Test.DisplayName);
                Assert.Equal("SpyBeforeAfterTest", afterStarting.AttributeName);
            },
                              msg =>
            {
                var afterFinished = Assert.IsAssignableFrom <IAfterTestFinished>(msg);
                Assert.Same(invoker.TestCase.TestMethod.TestClass.TestCollection, afterFinished.TestCollection);
                Assert.Same(invoker.TestCase, afterFinished.TestCase);
                Assert.Equal("Display Name", afterFinished.Test.DisplayName);
                Assert.Equal("SpyBeforeAfterTest", afterFinished.AttributeName);
            }
                              );
        }
示例#4
0
        public static async void FailedBefore()
        {
            var messageBus = new SpyMessageBus();
            var attribute  = new SpyBeforeAfterTest {
                ThrowInBefore = true
            };
            var invoker = TestableXunitTestInvoker.Create(messageBus, "Display Name", new List <BeforeAfterTestAttribute> {
                attribute
            }, lambda: () => Assert.True(false));

            await invoker.RunAsync();

            Assert.IsType <SpyBeforeAfterTest.BeforeException>(invoker.Aggregator.ToException());
            Assert.Collection(messageBus.Messages,
                              msg => Assert.IsAssignableFrom <ITestClassConstructionStarting>(msg),
                              msg => Assert.IsAssignableFrom <ITestClassConstructionFinished>(msg),
                              msg => Assert.IsAssignableFrom <IBeforeTestStarting>(msg),
                              msg => Assert.IsAssignableFrom <IBeforeTestFinished>(msg)
                              );
        }
示例#5
0
        public static async void FailingBefore_First()
        {
            var messages   = new List <string>();
            var attribute1 = new RecordingBeforeAfter(messages, 1)
            {
                ThrowInBefore = true
            };
            var attribute2 = new RecordingBeforeAfter(messages, 2);
            var invoker    = TestableXunitTestInvoker.Create(
                beforeAfterAttributes: new List <BeforeAfterTestAttribute> {
                attribute1, attribute2
            },
                lambda: () => messages.Add("Test method invocation")
                );

            await invoker.RunAsync();

            var msg = Assert.Single(messages);

            Assert.Equal("Before #1", msg);
        }
示例#6
0
        public static async void FailingBefore_First()
        {
            var messages   = new List <string>();
            var attribute1 = new RecordingBeforeAfter(messages, 1)
            {
                ThrowInBefore = true
            };
            var attribute2 = new RecordingBeforeAfter(messages, 2);
            var invoker    = TestableXunitTestInvoker.Create(
                beforeAfterAttributes: new List <BeforeAfterTestAttribute> {
                attribute1, attribute2
            },
                lambda: () => messages.Add("Test method invocation")
                );

            await invoker.RunAsync();

            Assert.Collection(messages,
                              msg => Assert.Equal("Before #1", msg)
                              // No cleanup for anything, so we had nothing run successfully
                              );
        }
示例#7
0
        public static async void Success()
        {
            var messageBus = new SpyMessageBus();
            var attribute  = new SpyBeforeAfterTest();
            var invoker    = TestableXunitTestInvoker.Create(messageBus, "Display Name", new List <BeforeAfterTestAttribute> {
                attribute
            });

            await invoker.RunAsync();

            Assert.Null(invoker.Aggregator.ToException());
            Assert.Collection(
                messageBus.Messages,
                msg => Assert.IsType <_TestClassConstructionStarting>(msg),                 // From TestInvoker
                msg => Assert.IsType <_TestClassConstructionFinished>(msg),                 // From TestInvoker
                msg =>
            {
                var beforeStarting = Assert.IsType <_BeforeTestStarting>(msg);
                Assert.Equal("assembly-id", beforeStarting.AssemblyUniqueID);
                Assert.Equal("SpyBeforeAfterTest", beforeStarting.AttributeName);
                Assert.Equal("case-id", beforeStarting.TestCaseUniqueID);
                Assert.Equal("class-id", beforeStarting.TestClassUniqueID);
                Assert.Equal("collection-id", beforeStarting.TestCollectionUniqueID);
                Assert.Equal("method-id", beforeStarting.TestMethodUniqueID);
                Assert.Equal("test-id", beforeStarting.TestUniqueID);
            },
                msg =>
            {
                var beforeFinished = Assert.IsType <_BeforeTestFinished>(msg);
                Assert.Equal("assembly-id", beforeFinished.AssemblyUniqueID);
                Assert.Equal("SpyBeforeAfterTest", beforeFinished.AttributeName);
                Assert.Equal("case-id", beforeFinished.TestCaseUniqueID);
                Assert.Equal("class-id", beforeFinished.TestClassUniqueID);
                Assert.Equal("collection-id", beforeFinished.TestCollectionUniqueID);
                Assert.Equal("method-id", beforeFinished.TestMethodUniqueID);
                Assert.Equal("test-id", beforeFinished.TestUniqueID);
            },
                // Test method is invoked here; no directly observable message (tested below)
                msg =>
            {
                var afterStarting = Assert.IsType <_AfterTestStarting>(msg);
                Assert.Equal("assembly-id", afterStarting.AssemblyUniqueID);
                Assert.Equal("SpyBeforeAfterTest", afterStarting.AttributeName);
                Assert.Equal("case-id", afterStarting.TestCaseUniqueID);
                Assert.Equal("class-id", afterStarting.TestClassUniqueID);
                Assert.Equal("collection-id", afterStarting.TestCollectionUniqueID);
                Assert.Equal("method-id", afterStarting.TestMethodUniqueID);
                Assert.Equal("test-id", afterStarting.TestUniqueID);
            },
                msg =>
            {
                var afterFinished = Assert.IsType <_AfterTestFinished>(msg);
                Assert.Equal("assembly-id", afterFinished.AssemblyUniqueID);
                Assert.Equal("SpyBeforeAfterTest", afterFinished.AttributeName);
                Assert.Equal("case-id", afterFinished.TestCaseUniqueID);
                Assert.Equal("class-id", afterFinished.TestClassUniqueID);
                Assert.Equal("collection-id", afterFinished.TestCollectionUniqueID);
                Assert.Equal("method-id", afterFinished.TestMethodUniqueID);
                Assert.Equal("test-id", afterFinished.TestUniqueID);
            }
                );
        }