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 !));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
            }
                              );
        }
Exemplo n.º 4
0
        public static void AssemblyWithNoTypes_ReturnsNoTestCases()
        {
            var framework = TestableXunitTestFrameworkDiscoverer.Create();

            framework.Find();

            Assert.Empty(framework.TestCases);
        }
Exemplo n.º 5
0
        public static void RequestsOnlyPublicTypesFromAssembly()
        {
            var framework = TestableXunitTestFrameworkDiscoverer.Create(collectionFactory: Substitute.For <IXunitTestCollectionFactory>());

            framework.Find();

            framework.Assembly.Received(1).GetTypes(includePrivateTypes: false);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        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>());
        }
Exemplo n.º 11
0
        public static async ValueTask DoesNotDiscoverNonFactDecoratedTestMethod()
        {
            var testClass  = Mocks.TestClass <ClassWithNoTests>();
            var discoverer = TestableXunitTestFrameworkDiscoverer.Create();

            await discoverer.FindTestsForType(testClass);

            Assert.Empty(discoverer.FindTestsForType_TestCases);
        }
Exemplo n.º 12
0
        public void ClassWithNoTests_ReturnsNoTestCases()
        {
            var framework = TestableXunitTestFrameworkDiscoverer.Create();
            var type      = Reflector.Wrap(typeof(ClassWithNoTests));

            framework.FindImpl(type);

            Assert.False(framework.Visitor.Finished.WaitOne(0));
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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)");
        }
Exemplo n.º 17
0
        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");
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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)
                              );
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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");
        }
Exemplo n.º 23
0
        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)
                              );
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 26
0
        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)");
        }
Exemplo n.º 28
0
        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)");
        }
Exemplo n.º 29
0
        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>());
        }
Exemplo n.º 30
0
        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);
        }