예제 #1
0
            public async ValueTask TheoryAcceptanceTest()
            {
                var code = @"
module FSharpTests

open Xunit

[<Theory>]
[<InlineData(42)>]
[<InlineData(2112)>]
let TestMethod(x : int) =
	Assert.Equal(2112, x)
";

                using var assembly = await FSharpAcceptanceTestV2Assembly.Create(code.Replace("\t", "    "));

                var controller = TestableXunit2.Create(assembly.FileName, null, true);
                var settings   = new FrontControllerFindAndRunSettings(_TestFrameworkOptions.ForDiscovery(), _TestFrameworkOptions.ForExecution());

                using var sink = SpyMessageSink <_TestAssemblyFinished> .Create();

                controller.FindAndRun(sink, settings);
                sink.Finished.WaitOne();

                Assert.Empty(sink.Messages.OfType <_TestSkipped>());
                var passedTest     = Assert.Single(sink.Messages.OfType <_TestPassed>());
                var passedMetadata = sink.Messages.OfType <_TestStarting>().Single(ts => ts.TestUniqueID == passedTest.TestUniqueID);

                Assert.Equal("FSharpTests.TestMethod(x: 2112)", passedMetadata.TestDisplayName);
                var failedTest     = Assert.Single(sink.Messages.OfType <_TestFailed>());
                var failedMetadata = sink.Messages.OfType <_TestStarting>().Single(ts => ts.TestUniqueID == failedTest.TestUniqueID);

                Assert.Equal("FSharpTests.TestMethod(x: 42)", failedMetadata.TestDisplayName);
            }
예제 #2
0
            public async ValueTask AsyncAcceptanceTest()
            {
                var code = @"
module FSharpTests

open Xunit

[<Fact>]
let AsyncFailing() =
	async {
		do! Async.Sleep(10)
		Assert.True(false)
	}
";

                using var assembly = await FSharpAcceptanceTestV2Assembly.Create(code.Replace("\t", "    "));

                var controller = TestableXunit2.Create(assembly.FileName, null, true);

                using var sink = SpyMessageSink <_TestAssemblyFinished> .Create();

                var settings = new FrontControllerFindAndRunSettings(_TestFrameworkOptions.ForDiscovery(), _TestFrameworkOptions.ForExecution());

                controller.FindAndRun(sink, settings);
                sink.Finished.WaitOne();

                var failures        = sink.Messages.OfType <_TestFailed>();
                var failure         = Assert.Single(failures);
                var failureStarting = sink.Messages.OfType <_TestStarting>().Single(s => s.TestUniqueID == failure.TestUniqueID);

                Assert.Equal("FSharpTests.AsyncFailing", failureStarting.TestDisplayName);
            }
예제 #3
0
            public async ValueTask TheoryAcceptanceTest()
            {
                var code = @"
module FSharpTests

open Xunit

[<Theory>]
[<InlineData>]
[<InlineData(42)>]
[<InlineData(42, 21.12)>]
let TestMethod (x:int) =
	Assert.True(true)
";

                using var assembly = await FSharpAcceptanceTestV2Assembly.Create(code.Replace("\t", "    "));

                var controller = TestableXunit2.Create(assembly.FileName, null, true);
                var sink       = new TestDiscoverySink();
                var settings   = new FrontControllerFindSettings(_TestFrameworkOptions.ForDiscovery());

                controller.Find(sink, settings);
                sink.Finished.WaitOne();

                Assert.Collection(
                    sink.TestCases.OrderBy(tc => tc.TestCaseDisplayName),
                    testCase => Assert.Equal("FSharpTests.TestMethod(x: ???)", testCase.TestCaseDisplayName),
                    testCase => Assert.Equal("FSharpTests.TestMethod(x: 42)", testCase.TestCaseDisplayName),
                    testCase => Assert.Equal("FSharpTests.TestMethod(x: 42, ???: 21.12)", testCase.TestCaseDisplayName)
                    );
            }
예제 #4
0
파일: Xunit2Tests.cs 프로젝트: xirsoi/xunit
        public void SupportsAsyncReturningMethods()
        {
            string code = @"
module FSharpTests

open Xunit

[<Fact>]
let AsyncFailing() =
    async {
        do! Async.Sleep(10)
        Assert.True(false)
    }
";

            using (var assembly = FSharpAcceptanceTestV2Assembly.Create(code))
                using (var controller = new TestableXunit2(assembly.FileName, null, true))
                {
                    var sink = new SpyMessageSink <ITestAssemblyFinished>();

                    controller.RunAll(sink, discoveryOptions: TestFrameworkOptions.ForDiscovery(), executionOptions: TestFrameworkOptions.ForExecution());
                    sink.Finished.WaitOne();

                    var failures = sink.Messages.OfType <ITestFailed>();
                    var failure  = Assert.Single(failures);
                    Assert.Equal("FSharpTests.AsyncFailing", failure.TestCase.DisplayName);
                }
        }
예제 #5
0
파일: Xunit2Tests.cs 프로젝트: xirsoi/xunit
        public void TheoryWithInlineData()
        {
            string code = @"
module FSharpTests

open Xunit

[<Theory>]
[<InlineData>]
[<InlineData(42)>]
[<InlineData(42, 21.12)>]
let TestMethod (x:int) =
    Assert.True(true)
";

            using (var assembly = FSharpAcceptanceTestV2Assembly.Create(code))
                using (var controller = new TestableXunit2(assembly.FileName, null, true))
                {
                    var sink = new TestDiscoverySink();

                    controller.Find(includeSourceInformation: false, messageSink: sink, discoveryOptions: TestFrameworkOptions.ForDiscovery());
                    sink.Finished.WaitOne();

                    Assert.Collection(sink.TestCases.OrderBy(tc => tc.DisplayName),
                                      testCase => Assert.Equal("FSharpTests.TestMethod(x: ???)", testCase.DisplayName),
                                      testCase => Assert.Equal("FSharpTests.TestMethod(x: 42)", testCase.DisplayName),
                                      testCase => Assert.Equal("FSharpTests.TestMethod(x: 42, ???: 21.12)", testCase.DisplayName)
                                      );
                }
        }
예제 #6
0
            public async ValueTask FactAcceptanceTest()
            {
                var code = @"
module FSharpTests

open Xunit

[<Fact>]
[<Trait(""Name!"", ""Value!"")>]
let Trait() =
	Assert.True(true)

[<Fact(Skip = ""Skipping"")>]
let Skipped() =
	Assert.True(false)

[<Fact(DisplayName=""Custom Test Name"")>]
let CustomName() =
	Assert.True(true)
";

                using var assembly = await FSharpAcceptanceTestV2Assembly.Create(code.Replace("\t", "    "));

                var controller = TestableXunit2.Create(assembly.FileName, null, true);
                var sink       = new TestDiscoverySink();
                var settings   = new FrontControllerFindSettings(_TestFrameworkOptions.ForDiscovery());

                controller.Find(sink, settings);

                sink.Finished.WaitOne();

                Assert.Collection(
                    sink.TestCases.OrderBy(tc => tc.TestCaseDisplayName),
                    testCase => Assert.Equal("Custom Test Name", testCase.TestCaseDisplayName),
                    testCase =>
                {
                    Assert.Equal("FSharpTests.Skipped", testCase.TestCaseDisplayName);
                    Assert.Equal("Skipping", testCase.SkipReason);
                },
                    testCase =>
                {
                    Assert.Equal("FSharpTests.Trait", testCase.TestCaseDisplayName);
                    Assert.Collection(testCase.Traits,
                                      kvp =>
                    {
                        Assert.Equal("Name!", kvp.Key);
                        Assert.Equal("Value!", kvp.Value.Single());
                    }
                                      );
                }
                    );
            }
예제 #7
0
파일: Xunit2Tests.cs 프로젝트: xirsoi/xunit
        public void FactAcceptanceTest()
        {
            string code = @"
module FSharpTests

open Xunit

[<Fact>]
[<Trait(""Name!"", ""Value!"")>]
let Trait() =
    Assert.True(true)

[<Fact(Skip = ""Skipping"")>]
let Skipped() =
    Assert.True(false)

[<Fact(DisplayName=""Custom Test Name"")>]
let CustomName() =
    Assert.True(true)
";

            using (var assembly = FSharpAcceptanceTestV2Assembly.Create(code))
                using (var controller = new TestableXunit2(assembly.FileName, null, true))
                {
                    var sink = new TestDiscoverySink();

                    controller.Find(includeSourceInformation: false, messageSink: sink, discoveryOptions: TestFrameworkOptions.ForDiscovery());
                    sink.Finished.WaitOne();

                    Assert.Collection(sink.TestCases.OrderBy(tc => tc.DisplayName),
                                      testCase => Assert.Equal("Custom Test Name", testCase.DisplayName),
                                      testCase =>
                    {
                        Assert.Equal("FSharpTests.Skipped", testCase.DisplayName);
                        Assert.Equal("Skipping", testCase.SkipReason);
                    },
                                      testCase =>
                    {
                        Assert.Equal("FSharpTests.Trait", testCase.DisplayName);
                        Assert.Collection(testCase.Traits,
                                          kvp =>
                        {
                            Assert.Equal("Name!", kvp.Key);
                            Assert.Equal("Value!", kvp.Value.Single());
                        }
                                          );
                    }
                                      );
                }
        }
예제 #8
0
            public async ValueTask TheoryAcceptanceTest()
            {
                var code = @"
module FSharpTests

open Xunit

[<Theory>]
[<InlineData(42)>]
[<InlineData(2112)>]
let TestMethod(x : int) =
	Assert.Equal(2112, x)
";

                using var assembly = await FSharpAcceptanceTestV2Assembly.Create(code.Replace("\t", "    "));

                var controller   = TestableXunit2.Create(assembly.FileName, null, true);
                var findSettings = new FrontControllerFindSettings(_TestFrameworkOptions.ForDiscovery());

                using var discoverySink = SpyMessageSink <_DiscoveryComplete> .Create();

                controller.Find(discoverySink, findSettings);
                discoverySink.Finished.WaitOne();

                using var executionSink = SpyMessageSink <_TestAssemblyFinished> .Create();

                var serializedTestCases = discoverySink.Messages.OfType <_TestCaseDiscovered>().Select(tcdm => tcdm.Serialization !).ToArray();

                Assert.All(serializedTestCases, serializedTestCase => Assert.NotNull(serializedTestCase));
                var runSettings = new FrontControllerRunSettings(_TestFrameworkOptions.ForExecution(), serializedTestCases);

                controller.Run(executionSink, runSettings);
                executionSink.Finished.WaitOne();

                Assert.Empty(executionSink.Messages.OfType <_TestSkipped>());
                var passedTest     = Assert.Single(executionSink.Messages.OfType <_TestPassed>());
                var passedMetadata = executionSink.Messages.OfType <_TestStarting>().Single(ts => ts.TestUniqueID == passedTest.TestUniqueID);

                Assert.Equal("FSharpTests.TestMethod(x: 2112)", passedMetadata.TestDisplayName);
                var failedTest     = Assert.Single(executionSink.Messages.OfType <_TestFailed>());
                var failedMetadata = executionSink.Messages.OfType <_TestStarting>().Single(ts => ts.TestUniqueID == failedTest.TestUniqueID);

                Assert.Equal("FSharpTests.TestMethod(x: 42)", failedMetadata.TestDisplayName);
            }