Exemple #1
0
        public void TestCasesUseInformationFromSourceInformationProvider()
        {
            var xml = @"
<assembly>
    <class name='Type2'>
        <method name='Type2.Method1' type='Type2' method='Method1'/>
        <method name='Type2.Method2' type='Type2' method='Method2'/>
    </class>
</assembly>";

            using (var xunit1 = new TestableXunit1())
            {
                xunit1.Executor
                .WhenForAnyArgs(x => x.EnumerateTests(null))
                .Do(callInfo => callInfo.Arg <ICallbackEventHandler>().RaiseCallbackEvent(xml));
                xunit1.SourceInformationProvider
                .GetSourceInformation(null)
                .ReturnsForAnyArgs(callInfo => new SourceInformation {
                    FileName = "File for " + callInfo.Arg <ITestCase>().DisplayName
                });
                var sink = new TestDiscoverySink();

                xunit1.Find(true, sink);
                sink.Finished.WaitOne();

                Assert.Collection(sink.TestCases,
                                  testCase => Assert.Equal("File for Type2.Method1", testCase.SourceInformation.FileName),
                                  testCase => Assert.Equal("File for Type2.Method2", testCase.SourceInformation.FileName)
                                  );
            }
        }
Exemple #2
0
        public void FindByTypesReturnsOnlyMethodsInTheGivenType()
        {
            var xml = @"
<assembly>
    <class name='Type1'>
        <method name='Method1 Display Name' type='Type1' method='Method1'/>
    </class>
    <class name='Type2'>
        <method name='Type2.Method1' type='Type2' method='Method1'/>
        <method name='Type2.Method2' type='Type2' method='Method2'/>
    </class>
</assembly>";

            using (var xunit1 = new TestableXunit1())
            {
                xunit1.Executor
                .WhenForAnyArgs(x => x.EnumerateTests(null))
                .Do(callInfo => callInfo.Arg <ICallbackEventHandler>().RaiseCallbackEvent(xml));
                var sink = new TestDiscoverySink();

                xunit1.Find("Type2", false, sink);
                sink.Finished.WaitOne();

                Assert.Collection(sink.TestCases,
                                  testCase => Assert.Equal("Type2.Method1", testCase.DisplayName),
                                  testCase => Assert.Equal("Type2.Method2", testCase.DisplayName)
                                  );
            }
        }
Exemple #3
0
        public void FindByAssemblyReturnsAllTestMethodsFromExecutorXml()
        {
            var xml = @"
<assembly>
    <class name='Type1'>
        <method name='Method1 Display Name' type='Type1' method='Method1'/>
    </class>
    <class name='SpecialType'>
        <method name='SpecialType.SkippedMethod' type='SpecialType' method='SkippedMethod' skip='I am not run'/>
        <method name='SpecialType.MethodWithTraits' type='SpecialType' method='MethodWithTraits'>
            <traits>
                <trait name='Trait1' value='Value1'/>
                <trait name='Trait2' value='Value2'/>
            </traits>
        </method>
    </class>
</assembly>";

            using (var xunit1 = new TestableXunit1())
            {
                xunit1.Executor
                .WhenForAnyArgs(x => x.EnumerateTests(null))
                .Do(callInfo => callInfo.Arg <ICallbackEventHandler>().RaiseCallbackEvent(xml));
                var sink = new TestDiscoverySink();

                xunit1.Find(false, sink);
                sink.Finished.WaitOne();

                Assert.Collection(sink.TestCases,
                                  testCase =>
                {
                    Assert.Equal("Type1", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("Method1", testCase.TestMethod.Method.Name);
                    Assert.Equal("Method1 Display Name", testCase.DisplayName);
                    Assert.Null(testCase.SkipReason);
                    Assert.Empty(testCase.Traits);
                },
                                  testCase =>
                {
                    Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("SkippedMethod", testCase.TestMethod.Method.Name);
                    Assert.Equal("SpecialType.SkippedMethod", testCase.DisplayName);
                    Assert.Equal("I am not run", testCase.SkipReason);
                },
                                  testCase =>
                {
                    Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("MethodWithTraits", testCase.TestMethod.Method.Name);
                    Assert.Equal("SpecialType.MethodWithTraits", testCase.DisplayName);
                    Assert.Collection(testCase.Traits.Keys,
                                      key =>
                    {
                        Assert.Equal("Trait1", key);
                        Assert.Collection(testCase.Traits[key],
                                          value => Assert.Equal("Value1", value)
                                          );
                    },
                                      key =>
                    {
                        Assert.Equal("Trait2", key);
                        Assert.Collection(testCase.Traits[key],
                                          value => Assert.Equal("Value2", value)
                                          );
                    }
                                      );
                }
                                  );
            }
        }
Exemple #4
0
        public void FindByAssemblyReturnsAllTestMethodsFromExecutorXml()
        {
            var xml = @"
<assembly>
    <class name='Type1'>
        <method name='Method1 Display Name' type='Type1' method='Method1'/>
    </class>
    <class name='SpecialType'>
        <method name='SpecialType.SkippedMethod' type='SpecialType' method='SkippedMethod' skip='I am not run'/>
        <method name='SpecialType.MethodWithTraits' type='SpecialType' method='MethodWithTraits'>
            <traits>
                <trait name='Trait1' value='Value1'/>
                <trait name='Trait2' value='Value2'/>
            </traits>
        </method>
    </class>
</assembly>";
            var xunit1 = new TestableXunit1();
            xunit1.Executor
                  .WhenForAnyArgs(x => x.EnumerateTests(null))
                  .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml));
            var sink = new TestDiscoveryVisitor();

            xunit1.Find(false, sink);
            sink.Finished.WaitOne();

            Assert.Collection(sink.TestCases,
                testCase =>
                {
                    Assert.Equal("Type1", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("Method1", testCase.TestMethod.Method.Name);
                    Assert.Equal("Method1 Display Name", testCase.DisplayName);
                    Assert.Null(testCase.SkipReason);
                    Assert.Empty(testCase.Traits);
                },
                testCase =>
                {
                    Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("SkippedMethod", testCase.TestMethod.Method.Name);
                    Assert.Equal("SpecialType.SkippedMethod", testCase.DisplayName);
                    Assert.Equal("I am not run", testCase.SkipReason);
                },
                testCase =>
                {
                    Assert.Equal("SpecialType", testCase.TestMethod.TestClass.Class.Name);
                    Assert.Equal("MethodWithTraits", testCase.TestMethod.Method.Name);
                    Assert.Equal("SpecialType.MethodWithTraits", testCase.DisplayName);
                    Assert.Collection(testCase.Traits.Keys,
                        key =>
                        {
                            Assert.Equal("Trait1", key);
                            Assert.Collection(testCase.Traits[key],
                                value => Assert.Equal("Value1", value)
                            );
                        },
                        key =>
                        {
                            Assert.Equal("Trait2", key);
                            Assert.Collection(testCase.Traits[key],
                                value => Assert.Equal("Value2", value)
                            );
                        }
                    );
                }
            );
        }
Exemple #5
0
        public void TestCasesUseInformationFromSourceInformationProvider()
        {
            var xml = @"
<assembly>
    <class name='Type2'>
        <method name='Type2.Method1' type='Type2' method='Method1'/>
        <method name='Type2.Method2' type='Type2' method='Method2'/>
    </class>
</assembly>";
            var xunit1 = new TestableXunit1();
            xunit1.Executor
                  .WhenForAnyArgs(x => x.EnumerateTests(null))
                  .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml));
            xunit1.SourceInformationProvider
                  .GetSourceInformation(null)
                  .ReturnsForAnyArgs(callInfo => new SourceInformation { FileName = "File for " + callInfo.Arg<ITestCase>().DisplayName });
            var sink = new TestDiscoveryVisitor();

            xunit1.Find(true, sink);
            sink.Finished.WaitOne();

            Assert.Collection(sink.TestCases,
                testCase => Assert.Equal("File for Type2.Method1", testCase.SourceInformation.FileName),
                testCase => Assert.Equal("File for Type2.Method2", testCase.SourceInformation.FileName)
            );
        }
Exemple #6
0
        public void FindByTypesReturnsOnlyMethodsInTheGivenType()
        {
            var xml = @"
<assembly>
    <class name='Type1'>
        <method name='Method1 Display Name' type='Type1' method='Method1'/>
    </class>
    <class name='Type2'>
        <method name='Type2.Method1' type='Type2' method='Method1'/>
        <method name='Type2.Method2' type='Type2' method='Method2'/>
    </class>
</assembly>";
            var xunit1 = new TestableXunit1();
            xunit1.Executor
                  .WhenForAnyArgs(x => x.EnumerateTests(null))
                  .Do(callInfo => callInfo.Arg<ICallbackEventHandler>().RaiseCallbackEvent(xml));
            var sink = new TestDiscoveryVisitor();

            xunit1.Find("Type2", false, sink);
            sink.Finished.WaitOne();

            Assert.Collection(sink.TestCases,
                testCase => Assert.Equal("Type2.Method1", testCase.DisplayName),
                testCase => Assert.Equal("Type2.Method2", testCase.DisplayName)
            );
        }