public static async void DisposesArguments() { ClassUnderTest.DataWasDisposed = false; var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassUnderTest>("TestWithDisposableData", messageBus); await runner.RunAsync(); Assert.True(ClassUnderTest.DataWasDisposed); }
public async void ThrowingToString() { var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassWithThrowingToString>("Test", messageBus, "Display Name"); var summary = await runner.RunAsync(); var passed = messageBus.Messages.OfType <ITestPassed>().Single(); Assert.Equal("Display Name(c: TargetInvocationException was thrown formatting an object of type \"XunitTheoryTestCaseRunnerTests+ClassWithThrowingToString\")", passed.Test.DisplayName); }
public async void ThrowingEnumerator() { var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassWithThrowingEnumerator>("Test", messageBus, "Display Name"); var summary = await runner.RunAsync(); var passed = messageBus.Messages.OfType <ITestPassed>().Single(); Assert.Equal("Display Name(c: [ClassWithThrowingEnumerator { }])", passed.Test.DisplayName); }
public static async void EnumeratesDataAtRuntimeAndExecutesOneTestForEachDataRow() { var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassUnderTest>("TestWithData", messageBus, "Display Name"); var summary = await runner.RunAsync(); Assert.NotEqual(0m, summary.Time); Assert.Equal(2, summary.Total); Assert.Equal(1, summary.Failed); var passed = messageBus.Messages.OfType <ITestPassed>().Single(); Assert.Equal($"Display Name(x: 42, y: {21.12}, z: \"Hello\")", passed.Test.DisplayName); var failed = messageBus.Messages.OfType <ITestFailed>().Single(); Assert.Equal("Display Name(x: 0, y: 0, z: \"World!\")", failed.Test.DisplayName); }
public static async void DiscovererWhichThrowsReturnsASingleFailedTest() { var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassUnderTest>("TestWithThrowingData", messageBus, "Display Name"); var summary = await runner.RunAsync(); Assert.Equal(0m, summary.Time); Assert.Equal(1, summary.Total); Assert.Equal(1, summary.Failed); var failed = messageBus.Messages.OfType <ITestFailed>().Single(); Assert.Equal("Display Name", failed.Test.DisplayName); Assert.Equal("System.DivideByZeroException", failed.ExceptionTypes.Single()); Assert.Equal("Attempted to divide by zero.", failed.Messages.Single()); Assert.Contains("ClassUnderTest.get_ThrowingData", failed.StackTraces.Single()); }
public static async void OnlySkipsDataRowsWithSkipReason() { var messageBus = new SpyMessageBus(); var runner = TestableXunitTheoryTestCaseRunner.Create <ClassUnderTest>("TestWithSomeDataSkipped", messageBus, "Display Name"); var summary = await runner.RunAsync(); Assert.NotEqual(0m, summary.Time); Assert.Equal(4, summary.Total); Assert.Equal(2, summary.Skipped); Assert.Equal(1, summary.Failed); var passed = messageBus.Messages.OfType <ITestPassed>().Single(); Assert.Equal($"Display Name(x: 1, y: {2.1}, z: \"not skipped\")", passed.Test.DisplayName); var failed = messageBus.Messages.OfType <ITestFailed>().Single(); Assert.Equal("Display Name(x: 0, y: 0, z: \"also not skipped\")", failed.Test.DisplayName); Assert.Contains(messageBus.Messages.OfType <ITestSkipped>(), skipped => skipped.Test.DisplayName == $"Display Name(x: 42, y: {21.12}, z: \"Hello\")"); Assert.Contains(messageBus.Messages.OfType <ITestSkipped>(), skipped => skipped.Test.DisplayName == "Display Name(x: 0, y: 0, z: \"World!\")"); }