Example #1
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)
                );
        }
Example #2
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);
        }
Example #3
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
                              );
        }
        public static async void FailingTest()
        {
            var messages = new List<string>();
            var attribute1 = new RecordingBeforeAfter(messages, 1);
            var attribute2 = new RecordingBeforeAfter(messages, 2);
            var invoker = TestableXunitTestInvoker.Create(
                beforeAfterAttributes: new List<BeforeAfterTestAttribute> { attribute1, attribute2 },
                lambda: () => { messages.Add("Test method invocation"); Assert.True(false); }
            );

            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)
            );
        }
        public static async void FailingBefore_Second()
        {
            var messages = new List<string>();
            var attribute1 = new RecordingBeforeAfter(messages, 1);
            var attribute2 = new RecordingBeforeAfter(messages, 2) { ThrowInBefore = 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),
                // No cleanup for #2, since it threw
                msg => Assert.Equal("After #1", msg)
            );
        }
        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
            );
        }