public static void GuardClauses() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); Assert.Throws <ArgumentNullException>("discoveryMessageSink", () => framework.Find(discoveryMessageSink: null !, discoveryOptions: _TestFrameworkOptions.ForDiscovery())); Assert.Throws <ArgumentNullException>("discoveryOptions", () => framework.Find(discoveryMessageSink: Substitute.For <_IMessageSink>(), discoveryOptions: null !)); }
public static void GuardClauses() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); Assert.Throws <ArgumentNullException>("discoveryMessageSink", () => framework.Find(includeSourceInformation: false, discoveryMessageSink: null, discoveryOptions: TestFrameworkOptions.ForDiscovery())); Assert.Throws <ArgumentNullException>("discoveryOptions", () => framework.Find(includeSourceInformation: false, discoveryMessageSink: Substitute.For <IMessageSink>(), discoveryOptions: null)); }
public static void CallsSourceProviderWhenTypesAreFoundInAssembly() { var sourceProvider = Substitute.For <ISourceInformationProvider>(); sourceProvider .GetSourceInformation(null) .ReturnsForAnyArgs(new Xunit.SourceInformation { FileName = "Source File", LineNumber = 42 }); var framework = TestableXunitTestFrameworkDiscoverer.Create(sourceProvider: sourceProvider); var typeInfo = Reflector.Wrap(typeof(ClassWithSingleTest)); framework.Assembly.GetType("abc").Returns(typeInfo); framework.Find("abc", includeSourceInformation: true); Assert.Collection(framework.TestCases, testCase => { Assert.Equal("XunitTestFrameworkDiscovererTests+ClassWithSingleTest.TestMethod", testCase.DisplayName); Assert.Equal("Source File", testCase.SourceInformation.FileName); Assert.Equal(42, testCase.SourceInformation.LineNumber); } ); }
public static void AssemblyWithNoTypes_ReturnsNoTestCases() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); framework.Find(); Assert.Empty(framework.TestCases); }
public static void RequestsOnlyPublicTypesFromAssembly() { var framework = TestableXunitTestFrameworkDiscoverer.Create(collectionFactory: Substitute.For <IXunitTestCollectionFactory>()); framework.Find(); framework.Assembly.Received(1).GetTypes(includePrivateTypes: false); }
public static void NonParallel() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(disableTestParallelization: true); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[collection-per-class, non-parallel\]", discoverer.TestFrameworkDisplayName); }
public static void ValidCustomFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType <CustomTestCollectionFactory>(discoverer.TestCollectionFactory); }
public static void ClassWithNoTests_ReturnsNoTestCases() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = new TestClass(Mocks.TestCollection(), Reflector.Wrap(typeof(ClassWithNoTests))); framework.FindTestsForClass(testClass); Assert.False(framework.Sink.Finished.WaitOne(0)); }
public static void CustomCollectionFactory() { var behaviorAttribute = Mocks.CollectionBehaviorAttribute <CustomTestCollectionFactory>(); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.Matches(@"xUnit.net v3 \d+\.\d+\.\d+(-pre\.\d+(-dev)?(\+[0-9a-f]+)?)? \[my-custom-test-collection-factory, parallel\]", discoverer.TestFrameworkDisplayName); }
public static void DoesNotCallSourceProviderWhenNotAskedFor() { var sourceProvider = Substitute.For <ISourceInformationProvider>(); var framework = TestableXunitTestFrameworkDiscoverer.Create(sourceProvider: sourceProvider); framework.Find("abc"); sourceProvider.Received(0).GetSourceInformation(Arg.Any <ITestCase>()); }
public static async ValueTask DoesNotDiscoverNonFactDecoratedTestMethod() { var testClass = Mocks.TestClass <ClassWithNoTests>(); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(); await discoverer.FindTestsForType(testClass); Assert.Empty(discoverer.FindTestsForType_TestCases); }
public void ClassWithNoTests_ReturnsNoTestCases() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(ClassWithNoTests)); framework.FindImpl(type); Assert.False(framework.Visitor.Finished.WaitOne(0)); }
public static void AssemblyWithMultiLevelHierarchyWithFactOverridenInNonImmediateDerivedClass_ReturnsOneTestCase() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = Mocks.TestClass(typeof(Child)); framework.FindTestsForClass(testClass); Assert.Equal(1, framework.Sink.TestCases.Count); Assert.Equal("XunitTestFrameworkDiscovererTests+FindImpl+Child.FactOverridenInNonImmediateDerivedClass", framework.Sink.TestCases[0].DisplayName); }
public void GuardClauses() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var typeName = typeof(Object).FullName; var sink = Substitute.For <IMessageSink>(); Assert.Throws <ArgumentNullException>("typeName", () => framework.Find(typeName: null, includeSourceInformation: false, messageSink: sink)); Assert.Throws <ArgumentException>("typeName", () => framework.Find(typeName: "", includeSourceInformation: false, messageSink: sink)); Assert.Throws <ArgumentNullException>("messageSink", () => framework.Find(typeName, includeSourceInformation: false, messageSink: null)); }
public static async ValueTask RequestsPublicAndPrivateMethodsFromType() { var typeInfo = Mocks.TypeInfo(); var testClass = Mocks.TestClass(typeInfo); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(); await discoverer.FindTestsForType(testClass); typeInfo.Received(1).GetMethods(includePrivateMethods: true); }
public static void AssemblyWithTheoryWithPropertyData_ReturnsOneTestCasePerDataRecord() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = Mocks.TestClass(typeof(TheoryWithPropertyData)); framework.FindTestsForClass(testClass); Assert.Equal(2, framework.Sink.TestCases.Count); Assert.Single(framework.Sink.TestCases, testCase => testCase.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithPropertyData.TheoryMethod(value: 42)"); Assert.Single(framework.Sink.TestCases, testCase => testCase.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithPropertyData.TheoryMethod(value: 2112)"); }
public static void AssemblyWithMixOfFactsAndNonTests_ReturnsTestCasesOnlyForFacts() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = new TestClass(Mocks.TestCollection(), Reflector.Wrap(typeof(ClassWithMixOfFactsAndNonFacts))); framework.FindTestsForClass(testClass); Assert.Equal(2, framework.Sink.TestCases.Count); Assert.Single(framework.Sink.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+ClassWithMixOfFactsAndNonFacts.TestMethod1"); Assert.Single(framework.Sink.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+ClassWithMixOfFactsAndNonFacts.TestMethod2"); }
public static async void AssemblyWithMultiLevelHierarchyWithFactOverridenInNonImmediateDerivedClass_ReturnsOneTestCase() { var testClass = Mocks.TestClass <Child>(); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(); await discoverer.FindTestsForType(testClass); var testCase = Assert.Single(discoverer.FindTestsForType_TestCases); Assert.Equal($"{typeof(Child).FullName}.{nameof(GrandParent.FactOverridenInNonImmediateDerivedClass)}", testCase.TestCaseDisplayName); }
public static void AssemblyWithFact_ReturnsOneTestCaseOfTypeXunitTestCase() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = new TestClass(Mocks.TestCollection(), Reflector.Wrap(typeof(ClassWithOneFact))); framework.FindTestsForClass(testClass); Assert.Collection(framework.Sink.TestCases, testCase => Assert.IsType <XunitTestCase>(testCase) ); }
public static void AssemblyAttributeOverride( CollectionBehavior behavior, Type expectedFactoryType) { var behaviorAttribute = Mocks.CollectionBehaviorAttribute(behavior); var assembly = Mocks.AssemblyInfo(attributes: new[] { behaviorAttribute }); var discoverer = TestableXunitTestFrameworkDiscoverer.Create(assembly); Assert.IsType(expectedFactoryType, discoverer.TestCollectionFactory); }
public static void DefaultTestCollection() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(ClassWithNoCollection)); var testClass = framework.CreateTestClass(type); Assert.NotNull(testClass.TestCollection); Assert.Equal("Test collection for XunitTestFrameworkDiscovererTests+CreateTestClass+ClassWithNoCollection", testClass.TestCollection.DisplayName); Assert.Null(testClass.TestCollection.CollectionDefinition); }
public void AssemblyWithMixOfFactsAndNonTests_ReturnsTestCasesOnlyForFacts() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(ClassWithMixOfFactsAndNonFacts)); framework.FindImpl(type); Assert.Equal(2, framework.Visitor.TestCases.Count); Assert.Single(framework.Visitor.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+ClassWithMixOfFactsAndNonFacts.TestMethod1"); Assert.Single(framework.Visitor.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+ClassWithMixOfFactsAndNonFacts.TestMethod2"); }
public void AssemblyWithFact_ReturnsOneTestCaseOfTypeXunitTestCase() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(ClassWithOneFact)); framework.FindImpl(type); Assert.Collection(framework.Visitor.TestCases, testCase => Assert.IsType <XunitTestCase>(testCase) ); }
public void AssemblyWithTheoryWithPropertyData_ReturnsOneTestCasePerDataRecord() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(TheoryWithPropertyData)); framework.FindImpl(type); Assert.Equal(2, framework.Visitor.TestCases.Count); Assert.Single(framework.Visitor.TestCases, testCase => testCase.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithPropertyData.TheoryMethod(value: 42)"); Assert.Single(framework.Visitor.TestCases, testCase => testCase.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithPropertyData.TheoryMethod(value: 2112)"); }
public static void SendsDiscoveryStartingMessage() { var typeInfo = Reflector.Wrap(typeof(ClassWithSingleTest)); var mockAssembly = Mocks.AssemblyInfo(types: new[] { typeInfo }); var framework = TestableXunitTestFrameworkDiscoverer.Create(mockAssembly); framework.Find("abc"); framework.Sink.Finished.WaitOne(); Assert.True(framework.Sink.StartSeen); }
public static void UndeclaredTestCollection() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(ClassWithUndeclaredCollection)); var testClass = framework.CreateTestClass(type); Assert.NotNull(testClass.TestCollection); Assert.Equal("This a collection without declaration", testClass.TestCollection.DisplayName); Assert.Null(testClass.TestCollection.CollectionDefinition); }
public static void AssemblyWithTheoryWithInlineData_ReturnsOneTestCasePerDataRecord() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var testClass = Mocks.TestClass <TheoryWithInlineData>(); framework.FindTestsForClass(testClass); Assert.Equal(2, framework.Sink.TestCases.Count); Assert.Single(framework.Sink.TestCases, t => t.TestCaseDisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithInlineData.TheoryMethod(value: \"Hello world\")"); Assert.Single(framework.Sink.TestCases, t => t.TestCaseDisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithInlineData.TheoryMethod(value: 42)"); }
public static void AssemblyWithTheoryWithInlineData_ReturnsOneTestCasePerDataRecord() { var framework = TestableXunitTestFrameworkDiscoverer.Create(); var type = Reflector.Wrap(typeof(TheoryWithInlineData)); framework.FindTestsForClass(type); Assert.Equal(2, framework.Visitor.TestCases.Count); Assert.Single(framework.Visitor.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithInlineData.TheoryMethod(value: \"Hello world\")"); Assert.Single(framework.Visitor.TestCases, t => t.DisplayName == "XunitTestFrameworkDiscovererTests+FindImpl+TheoryWithInlineData.TheoryMethod(value: 42)"); }
public static void DoesNotCallSourceProviderWhenNotAskedFor() { var sourceProvider = Substitute.For <ISourceInformationProvider>(); var typeInfo = Reflector.Wrap(typeof(ClassWithSingleTest)); var mockAssembly = Mocks.AssemblyInfo(types: new[] { typeInfo }); var framework = TestableXunitTestFrameworkDiscoverer.Create(mockAssembly, sourceProvider); framework.Find(); framework.Sink.Finished.WaitOne(); sourceProvider.Received(0).GetSourceInformation(Arg.Any <ITestCase>()); }
public static void DefinedTestCollection() { var type = Reflector.Wrap(typeof(ClassWithDefinedCollection)); var framework = TestableXunitTestFrameworkDiscoverer.Create(type.Assembly); var testClass = framework.CreateTestClass(type); Assert.NotNull(testClass.TestCollection); Assert.Equal("This a defined collection", testClass.TestCollection.DisplayName); Assert.NotNull(testClass.TestCollection.CollectionDefinition); Assert.Equal("XunitTestFrameworkDiscovererTests+CreateTestClass+DeclaredCollection", testClass.TestCollection.CollectionDefinition.Name); }