public void MultipleAssemblies()
        {
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;

            var clockTime = TimeSpan.FromSeconds(12.3456);
            var @short    = new ExecutionSummary {
                Total = 2112, Errors = 6, Failed = 42, Skipped = 8, Time = 1.2345M
            };
            var nothing = new ExecutionSummary {
                Total = 0
            };
            var longerName = new ExecutionSummary {
                Total = 10240, Errors = 7, Failed = 96, Skipped = 4, Time = 3.4567M
            };
            var message = new TestExecutionSummary(clockTime, new List <KeyValuePair <string, ExecutionSummary> > {
                new KeyValuePair <string, ExecutionSummary>("short", @short),
                new KeyValuePair <string, ExecutionSummary>("nothing", nothing),
                new KeyValuePair <string, ExecutionSummary>("longerName", longerName),
            });
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Imp] => === TEST EXECUTION SUMMARY ===", msg),
                              msg => Assert.Equal("[Imp] =>    short       Total:  2112, Errors:  6, Failed:  42, Skipped:  8, Time: 1.235s", msg),
                              msg => Assert.Equal("[Imp] =>    nothing     Total:     0", msg),
                              msg => Assert.Equal("[Imp] =>    longerName  Total: 10240, Errors:  7, Failed:  96, Skipped:  4, Time: 3.457s", msg),
                              msg => Assert.Equal("[Imp] =>                       -----          --          ---           --        ------", msg),
                              msg => Assert.Equal("[Imp] =>          GRAND TOTAL: 12352          13          138           12        4.691s (12.346s)", msg)
                              );
        }
        public void MultipleAssemblies()
        {
            var clockTime = TimeSpan.FromSeconds(12.3456);
            var @short    = new ExecutionSummary {
                Total = 2112, Errors = 6, Failed = 42, Skipped = 8, Time = 1.2345M
            };
            var nothing = new ExecutionSummary {
                Total = 0
            };
            var longerName = new ExecutionSummary {
                Total = 10240, Errors = 7, Failed = 96, Skipped = 4, Time = 3.4567M
            };
            var assemblyShortStarting   = TestData.TestAssemblyStarting(assemblyUniqueID: "asm-short", assemblyName: "short");
            var assemblyNothingStarting = TestData.TestAssemblyStarting(assemblyUniqueID: "asm-nothing", assemblyName: "nothing");
            var assemblyLongerStarting  = TestData.TestAssemblyStarting(assemblyUniqueID: "asm-longer", assemblyName: "longerName");
            var summaryMessage          = TestData.TestExecutionSummaries(clockTime, ("asm-short", @short), ("asm-nothing", nothing), ("asm-longer", longerName));
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(assemblyShortStarting);
            handler.OnMessage(assemblyNothingStarting);
            handler.OnMessage(assemblyLongerStarting);
            handler.OnMessage(summaryMessage);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Imp] => === TEST EXECUTION SUMMARY ===", msg),
                              msg => Assert.Equal("[Imp] =>    longerName  Total: 10240, Errors:  7, Failed:  96, Skipped:  4, Time: 3.457s", msg),
                              msg => Assert.Equal("[Imp] =>    nothing     Total:     0", msg),
                              msg => Assert.Equal("[Imp] =>    short       Total:  2112, Errors:  6, Failed:  42, Skipped:  8, Time: 1.235s", msg),
                              msg => Assert.Equal("[Imp] =>                       -----          --          ---           --        ------", msg),
                              msg => Assert.Equal("[Imp] =>          GRAND TOTAL: 12352          13          138           12        4.691s (12.346s)", msg)
                              );
        }
        public void TestClassCleanupFailure()
        {
            var classStarting = new _TestClassStarting
            {
                AssemblyUniqueID       = assemblyID,
                TestClass              = "MyType",
                TestClassUniqueID      = classID,
                TestCollectionUniqueID = collectionID
            };
            var classCleanupFailure = new _TestClassCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCollectionUniqueID = collectionID,
                TestClassUniqueID      = classID
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(classStarting);
            handler.OnMessage(classCleanupFailure);

            AssertFailureMessages(handler.Messages, "Test Class Cleanup Failure (MyType)");
        }
        public void TestCleanupFailure()
        {
            var testStarting = new _TestStarting
            {
                AssemblyUniqueID       = assemblyID,
                TestCaseUniqueID       = testCaseID,
                TestClassUniqueID      = classID,
                TestDisplayName        = "MyTest",
                TestCollectionUniqueID = collectionID,
                TestMethodUniqueID     = methodID,
                TestUniqueID           = testID
            };
            var testCleanupFailure = new _TestCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages               = messages,
                StackTraces            = stackTraces,
                TestCaseUniqueID       = testCaseID,
                TestCollectionUniqueID = collectionID,
                TestClassUniqueID      = classID,
                TestMethodUniqueID     = methodID,
                TestUniqueID           = testID
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(testStarting);
            handler.OnMessage(testCleanupFailure);

            AssertFailureMessages(handler.Messages, "Test Cleanup Failure (MyTest)");
        }
        public void DoesNotLogOutputByDefault()
        {
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(startingMessage);
            handler.OnMessage(passedMessage);

            Assert.Empty(handler.Messages);
        }
        public void DoesNotLogOutputByDefault()
        {
            var message = Mocks.TestPassed("This is my display name \t\r\n", output: "This is\t" + Environment.NewLine + "output");
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Empty(handler.Messages);
        }
        public static void LogsMessage(bool diagnosticMessages, int toRun, int discovered, string expectedResult)
        {
            var message = Mocks.TestAssemblyDiscoveryFinished(diagnosticMessages, toRun, discovered);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            var msg = Assert.Single(handler.Messages);

            Assert.Equal(expectedResult, msg);
        }
        public static void LogsMessage()
        {
            var message = Mocks.TestAssemblyExecutionFinished();
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            var msg = Assert.Single(handler.Messages);

            Assert.Equal("[Imp] =>   Finished:    testAssembly", msg);
        }
        public static void LogsMessage(bool diagnosticMessages, string expectedResult)
        {
            var message = Mocks.TestAssemblyExecutionStarting(diagnosticMessages: diagnosticMessages);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            var msg = Assert.Single(handler.Messages);

            Assert.Equal <object>(expectedResult, msg);
        }
        public static void LogsTestNameAsWarning()
        {
            var message = Mocks.TestSkipped("This is my display name \t\r\n", "This is my skip reason \t\r\n");
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Wrn] =>     This is my display name \\t\\r\\n [SKIP]", msg),
                              msg => Assert.Equal("[Imp] =>       This is my skip reason \\t\\r\\n", msg)
                              );
        }
        public static void LogsMessage(
            bool diagnosticMessages,
            string expectedResult)
        {
            var message = TestData.TestAssemblyExecutionStarting(diagnosticMessages: diagnosticMessages, parallelizeTestCollections: true, maxParallelThreads: 42);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            var msg = Assert.Single(handler.Messages);

            Assert.Equal(expectedResult, msg);
        }
        public static void LogsTestNameAsWarning(string skipNewline)
        {
            var startingMessage = TestData.TestStarting(testDisplayName: "This is my display name \t\r\n");
            var skipMessage     = TestData.TestSkipped(reason: $"This is my skip reason \t{skipNewline}across multiple lines");
            var handler         = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(startingMessage);
            handler.OnMessage(skipMessage);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Wrn] =>     This is my display name \\t\\r\\n [SKIP]", msg),
                              msg => Assert.Equal($"[Imp] =>       This is my skip reason \t{Environment.NewLine}      across multiple lines", msg)
                              );
        }
        public void ErrorMessage()
        {
            var errorMessage = new _ErrorMessage
            {
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(errorMessage);

            AssertFailureMessages(handler.Messages, "FATAL ERROR");
        }
        public static void LogsMessage(
            bool diagnosticMessages,
            AppDomainOption appDomain,
            bool shadowCopy,
            string expectedResult)
        {
            var message = TestData.TestAssemblyDiscoveryStarting(diagnosticMessages: diagnosticMessages, appDomain: appDomain, shadowCopy: shadowCopy);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            var msg = Assert.Single(handler.Messages);

            Assert.Equal(expectedResult, msg);
        }
        public void LogsMessage(IMessageSinkMessage message, string messageType)
        {
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Err @ SomeFolder\\SomeClass.cs:18] =>     [" + messageType + "] ExceptionType", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       ExceptionType : This is my message \t", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       Message Line 2", msg),
                              msg => Assert.Equal("[--- @ SomeFolder\\SomeClass.cs:18] =>       Stack Trace:", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 1", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         SomeFolder\\SomeClass.cs(18,0): at SomeClass.SomeMethod()", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 3", msg)
                              );
        }
        public void LogsOutputWhenDiagnosticsAreEnabled()
        {
            var message = Mocks.TestPassed("This is my display name \t\r\n", output: "This is\t" + Environment.NewLine + "output");
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(Mocks.TestAssemblyExecutionStarting(diagnosticMessages: true, assemblyFilename: message.TestAssembly.Assembly.AssemblyPath));
            handler.Messages.Clear();  // Ignore any output from the "assembly execution starting" message

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Imp] =>     This is my display name \\t\\r\\n [PASS]", msg),
                              msg => Assert.Equal("[---] =>       Output:", msg),
                              msg => Assert.Equal("[Imp] =>         This is\t", msg),
                              msg => Assert.Equal("[Imp] =>         output", msg)
                              );
        }
        public void SingleAssembly()
        {
            var clockTime = TimeSpan.FromSeconds(12.3456);
            var summary   = new ExecutionSummary {
                Total = 2112, Errors = 6, Failed = 42, Skipped = 8, Time = 1.2345M
            };
            var assemblyStartingMessage = TestData.TestAssemblyStarting(assemblyUniqueID: "asm-id", assemblyName: "assembly");
            var summaryMessage          = TestData.TestExecutionSummaries(clockTime, "asm-id", summary);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(assemblyStartingMessage);
            handler.OnMessage(summaryMessage);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Imp] => === TEST EXECUTION SUMMARY ===", msg),
                              msg => Assert.Equal("[Imp] =>    assembly  Total: 2112, Errors: 6, Failed: 42, Skipped: 8, Time: 1.235s", msg)
                              );
        }
        public void SingleAssembly()
        {
            var clockTime = TimeSpan.FromSeconds(12.3456);
            var assembly  = new ExecutionSummary {
                Total = 2112, Errors = 6, Failed = 42, Skipped = 8, Time = 1.2345M
            };
            var message = new TestExecutionSummary(clockTime, new List <KeyValuePair <string, ExecutionSummary> > {
                new KeyValuePair <string, ExecutionSummary>("assembly", assembly)
            });
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Imp] => === TEST EXECUTION SUMMARY ===", msg),
                              msg => Assert.Equal("[Imp] =>    assembly  Total: 2112, Errors: 6, Failed: 42, Skipped: 8, Time: 1.235s", msg)
                              );
        }
        public void LogsOutputWhenDiagnosticsAreEnabled()
        {
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(TestData.TestAssemblyExecutionStarting(diagnosticMessages: true));
            handler.OnMessage(TestData.TestAssemblyStarting());
            handler.Messages.Clear();              // Reset any output from previous messages

            handler.OnMessage(startingMessage);
            handler.OnMessage(passedMessage);

            Assert.Collection(
                handler.Messages,
                msg => Assert.Equal("[Imp] =>     This is my display name \\t\\r\\n [PASS]", msg),
                msg => Assert.Equal("[---] =>       Output:", msg),
                msg => Assert.Equal("[Imp] =>         This is\t", msg),
                msg => Assert.Equal("[Imp] =>         output", msg)
                );
        }
        public void LogsTestNameWithExceptionAndStackTraceAndOutput()
        {
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(startingMessage);
            handler.OnMessage(failedMessage);

            Assert.Collection(
                handler.Messages,
                msg => Assert.Equal("[Err @ SomeFolder\\SomeClass.cs:18] =>     This is my display name \\t\\r\\n [FAIL]", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       ExceptionType : This is my message \t", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       Message Line 2", msg),
                msg => Assert.Equal("[--- @ SomeFolder\\SomeClass.cs:18] =>       Stack Trace:", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 1", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         SomeFolder\\SomeClass.cs(18,0): at SomeClass.SomeMethod()", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 3", msg),
                msg => Assert.Equal("[--- @ SomeFolder\\SomeClass.cs:18] =>       Output:", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         This is\t", msg),
                msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         output", msg)
                );
        }
        public void LogsTestNameWithExceptionAndStackTraceAndOutput()
        {
            var message = Mocks.TestFailed("This is my display name \t\r\n", 1.2345M, output: "This is\t" + Environment.NewLine + "output");

            SetupFailureInformation(message);
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(message);

            Assert.Collection(handler.Messages,
                              msg => Assert.Equal("[Err @ SomeFolder\\SomeClass.cs:18] =>     This is my display name \\t\\r\\n [FAIL]", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       ExceptionType : This is my message \t", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>       Message Line 2", msg),
                              msg => Assert.Equal("[--- @ SomeFolder\\SomeClass.cs:18] =>       Stack Trace:", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 1", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         SomeFolder\\SomeClass.cs(18,0): at SomeClass.SomeMethod()", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         Line 3", msg),
                              msg => Assert.Equal("[--- @ SomeFolder\\SomeClass.cs:18] =>       Output:", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         This is\t", msg),
                              msg => Assert.Equal("[Imp @ SomeFolder\\SomeClass.cs:18] =>         output", msg)
                              );
        }
        public void TestAssemblyCleanupFailure()
        {
            var assemblyStarting = new _TestAssemblyStarting
            {
                AssemblyUniqueID = assemblyID,
                AssemblyPath     = @"C:\Foo\bar.dll"
            };
            var assemblyCleanupFailure = new _TestAssemblyCleanupFailure
            {
                AssemblyUniqueID       = assemblyID,
                ExceptionParentIndices = exceptionParentIndices,
                ExceptionTypes         = exceptionTypes,
                Messages    = messages,
                StackTraces = stackTraces
            };
            var handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(assemblyStarting);
            handler.OnMessage(assemblyCleanupFailure);

            AssertFailureMessages(handler.Messages, @"Test Assembly Cleanup Failure (C:\Foo\bar.dll)");
        }
        public void 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 handler = TestableDefaultRunnerReporterMessageHandler.Create();

            handler.OnMessage(collectionStarting);
            handler.OnMessage(collectionCleanupFailure);

            AssertFailureMessages(handler.Messages, "Test Collection Cleanup Failure (FooBar)");
        }