public static async void UsesCustomTestOrderer() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionUnderTest)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); Assert.IsType <CustomTestCaseOrderer>(runner.TestCaseOrderer); }
public static async void DisposesFixtures() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionUnderTest)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); var fixtureUnderTest = runner.CollectionFixtureMappings.Values.OfType <FixtureUnderTest>().Single(); Assert.True(fixtureUnderTest.Disposed); }
public static async void UnresolvedConstructorParameterOnCollectionFixture_ReturnsError() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionWithCollectionFixtureWithDependency)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); var ex = Assert.IsType <TestClassException>(runner.RunTestClassAsync_AggregatorResult); Assert.Equal("Collection fixture type 'XunitTestCollectionRunnerTests+CollectionFixtureWithCollectionFixtureDependency' had one or more unresolved constructor arguments: DependentCollectionFixture collectionFixture", ex.Message); }
public static async void MultiplePublicConstructorsOnCollectionFixture_ReturnsError() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionsWithMultiCtorCollectionFixture)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); var ex = Assert.IsType <TestClassException>(runner.RunTestClassAsync_AggregatorResult); Assert.Equal("Collection fixture type 'XunitTestCollectionRunnerTests+CollectionFixtureWithMultipleConstructors' may only define a single public constructor.", ex.Message); }
public static async void CanLogSinkMessageFromCollectionFixture() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionWithCollectionFixtureWithMessageSinkDependency)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); var diagnosticMessage = Assert.Single(runner.DiagnosticMessages.Cast <IDiagnosticMessage>()); Assert.Equal("CollectionFixtureWithMessageSinkDependency constructor message", diagnosticMessage.Message); }
public static async void SettingUnknownTestCaseOrderLogsDiagnosticMessage() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionWithUnknownTestCaseOrderer)), "TestCollectionDisplayName"); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); Assert.IsType <MockTestCaseOrderer>(runner.TestCaseOrderer); var diagnosticMessage = Assert.Single(runner.DiagnosticMessages.Cast <IDiagnosticMessage>()); Assert.Equal("Could not find type 'UnknownType' in UnknownAssembly for collection-level test case orderer on test collection 'TestCollectionDisplayName'", diagnosticMessage.Message); }
public static async void CreatesFixtures() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionUnderTest)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); Assert.Collection(runner.CollectionFixtureMappings.OrderBy(mapping => mapping.Key.Name), mapping => Assert.IsType <FixtureUnderTest>(mapping.Value), mapping => Assert.IsType <object>(mapping.Value) ); }
public static async void SettingTestCaseOrdererWithThrowingConstructorLogsDiagnosticMessage() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionWithCtorThrowingTestCaseOrderer)), "TestCollectionDisplayName"); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); Assert.IsType <MockTestCaseOrderer>(runner.TestCaseOrderer); var diagnosticMessage = Assert.Single(runner.DiagnosticMessages.Cast <IDiagnosticMessage>()); Assert.StartsWith("Collection-level test case orderer 'XunitTestCollectionRunnerTests+TestCaseOrderer+MyCtorThrowingTestCaseOrderer' for test collection 'TestCollectionDisplayName' threw 'System.DivideByZeroException' during construction:", diagnosticMessage.Message); }
public static async void CanInjectMessageSinkIntoCollectionFixture() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionWithCollectionFixtureWithMessageSinkDependency)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("CreatesFixtures", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); await runner.RunAsync(); Assert.Null(runner.RunTestClassAsync_AggregatorResult); var classFixture = runner.CollectionFixtureMappings.Values.OfType <CollectionFixtureWithMessageSinkDependency>().Single(); Assert.NotNull(classFixture.MessageSink); Assert.Same(runner.DiagnosticMessageSink, classFixture.MessageSink); }
public static async void DisposeAndAsyncLifetimeShouldBeCalledInTheRightOrder() { var collection = new TestCollection(Mocks.TestAssembly(), Reflector.Wrap(typeof(CollectionForFixtureAsyncLifetimeAndDisposableUnderTest)), null); var testCase = Mocks.XunitTestCase <XunitTestCollectionRunnerTests>("DisposeAndAsyncLifetimeShouldBeCalledInTheRightOrder", collection); var runner = TestableXunitTestCollectionRunner.Create(testCase); var runnerSessionTask = runner.RunAsync(); await Task.Delay(500); var fixtureUnderTest = runner.CollectionFixtureMappings.Values.OfType <FixtureAsyncLifetimeAndDisposableUnderTest>().Single(); Assert.True(fixtureUnderTest.DisposeAsyncCalled); Assert.False(fixtureUnderTest.Disposed); fixtureUnderTest.DisposeAsyncSignaler.SetResult(true); await runnerSessionTask; Assert.True(fixtureUnderTest.Disposed); }