Exemplo n.º 1
0
        public async ValueTask TestMethodCleanupFailure()
        {
            var methodStarting = new _TestMethodStarting
            {
                AssemblyUniqueID       = assemblyID,
                TestClassUniqueID      = classID,
                TestCollectionUniqueID = collectionID,
                TestMethod             = "MyMethod",
                TestMethodUniqueID     = methodID,
            };
            var methodCleanupFailure = new _TestMethodCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID,
                TestClassUniqueID      = classID,
                TestMethodUniqueID     = methodID
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(methodStarting);
            sink.OnMessage(methodCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Method Cleanup Failure (MyMethod)");
        }
Exemplo n.º 2
0
        public async ValueTask TestCollectionCleanupFailure()
        {
            var collectionStarting = new _TestCollectionStarting
            {
                AssemblyUniqueID          = assemblyID,
                TestCollectionDisplayName = "FooBar",
                TestCollectionUniqueID    = collectionID
            };
            var collectionCleanupFailure = new _TestCollectionCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(collectionStarting);
            sink.OnMessage(collectionCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Collection Cleanup Failure (FooBar)");
        }
Exemplo n.º 3
0
        public async ValueTask TestAssemblyCleanupFailure()
        {
            var collectionStarting = new _TestAssemblyStarting
            {
                AssemblyUniqueID = assemblyID,
                AssemblyPath     = "assembly-file-path"
            };
            var collectionCleanupFailure = new _TestAssemblyCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(collectionStarting);
            sink.OnMessage(collectionCleanupFailure);

            AssertFailure(listener, sink.TestRunState, "Test Assembly Cleanup Failure (assembly-file-path)");
        }
Exemplo n.º 4
0
        public static async void Skip_MovesToSuccess()
        {
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };
            sink.OnMessage(TestData.TestClassStarting());
            sink.OnMessage(TestData.TestMethodStarting());
            sink.OnMessage(TestData.TestStarting());

            sink.OnMessage(TestData.TestSkipped());

            Assert.Equal(TestRunState.Success, sink.TestRunState);
        }
Exemplo n.º 5
0
        public static async void Success_StaysInCurrentState(TestRunState initialState)
        {
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = initialState
                        };
            sink.OnMessage(TestData.TestClassStarting());
            sink.OnMessage(TestData.TestMethodStarting());
            sink.OnMessage(TestData.TestStarting());

            sink.OnMessage(TestData.TestPassed());

            Assert.Equal(initialState, sink.TestRunState);
        }
Exemplo n.º 6
0
        public static async void FailureSetsStateToFailed(TestRunState initialState)
        {
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = initialState
                        };
            sink.OnMessage(TestData.TestClassStarting());
            sink.OnMessage(TestData.TestMethodStarting());
            sink.OnMessage(TestData.TestStarting());

            sink.OnMessage(TestData.TestFailed());

            Assert.Equal(TestRunState.Failure, sink.TestRunState);
        }
Exemplo n.º 7
0
        public static async void ConvertsTestFailed()
        {
            (string?[] ExceptionTypes, string[] Messages, string?[] StackTraces, int[] ExceptionParentIndices, FailureCause _)errorMetadata;

            try
            {
                throw new Exception();
            }
            catch (Exception e)
            {
                errorMetadata = ExceptionUtility.ExtractMetadata(e);
            }

            TestResult?testResult = null;
            var        listener   = Substitute.For <ITestListener>();

            listener
            .WhenAny(l => l.TestFinished(null))
            .Do <TestResult>(result => testResult = result);
            await using var sink = new ResultSink(listener, 42);
            sink.OnMessage(TestData.TestClassStarting(testClass: typeof(object).FullName !));
            sink.OnMessage(TestData.TestMethodStarting(testMethod: nameof(object.GetHashCode)));
            sink.OnMessage(TestData.TestStarting(testDisplayName: "Display Name"));
            var message = TestData.TestFailed(
                exceptionParentIndices: errorMetadata.ExceptionParentIndices,
                exceptionTypes: errorMetadata.ExceptionTypes,
                executionTime: 123.45m,
                messages: errorMetadata.Messages,
                stackTraces: errorMetadata.StackTraces
                );

            sink.OnMessage(message);

            Assert.NotNull(testResult);
            Assert.Same(typeof(object), testResult.FixtureType);
            Assert.Equal(nameof(object.GetHashCode), testResult.Method.Name);
            Assert.Equal("Display Name", testResult.Name);
            Assert.Equal(TestState.Failed, testResult.State);
            Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds);
            Assert.Equal(42, testResult.TotalTests);
            Assert.Equal($"{errorMetadata.ExceptionTypes[0]} : {errorMetadata.Messages[0]}", testResult.Message);
            Assert.Equal(errorMetadata.StackTraces[0], testResult.StackTrace);
        }
Exemplo n.º 8
0
    public static async void SignalsFinishedEventUponReceiptOfITestAssemblyFinished()
    {
        var listener = Substitute.For <ITestListener>();

        await using var sink = new ResultSink(listener, 42);
        var message = TestData.TestAssemblyFinished();

        sink.OnMessage(message);

        Assert.True(sink.Finished.WaitOne(0));
    }
Exemplo n.º 9
0
        public static async void ConvertsTestPassed()
        {
            TestResult?testResult = null;
            var        listener   = Substitute.For <ITestListener>();

            listener
            .WhenAny(l => l.TestFinished(null))
            .Do <TestResult>(result => testResult = result);
            await using var sink = new ResultSink(listener, 42);
            sink.OnMessage(TestData.TestClassStarting(testClass: typeof(object).FullName !));
            sink.OnMessage(TestData.TestMethodStarting(testMethod: nameof(object.GetHashCode)));
            sink.OnMessage(TestData.TestStarting(testDisplayName: "Display Name"));

            sink.OnMessage(TestData.TestPassed(executionTime: 123.45m));

            Assert.NotNull(testResult);
            Assert.Same(typeof(object), testResult.FixtureType);
            Assert.Equal(nameof(object.GetHashCode), testResult.Method.Name);
            Assert.Equal("Display Name", testResult.Name);
            Assert.Equal(TestState.Passed, testResult.State);
            Assert.Equal(123.45, testResult.TimeSpan.TotalMilliseconds);
            Assert.Equal(42, testResult.TotalTests);
        }
Exemplo n.º 10
0
        public async ValueTask ErrorMessage()
        {
            var errorMessage = new _ErrorMessage
            {
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var listener = Substitute.For <ITestListener>();

            await using var sink = new ResultSink(listener, 42)
                        {
                            TestRunState = TestRunState.NoTests
                        };

            sink.OnMessage(errorMessage);

            AssertFailure(listener, sink.TestRunState, "Fatal Error");
        }