public static void LogsMessageWithStatitics()
        {
            var assembly         = Mocks.TestAssembly(@"C:\Assembly\File.dll");
            var assemblyStarting = Substitute.For <ITestAssemblyStarting>();

            assemblyStarting.TestAssembly.Returns(assembly);
            var assemblyFinished = Substitute.For <ITestAssemblyFinished>();

            assemblyFinished.TestAssembly.Returns(assembly);
            assemblyFinished.TestsRun.Returns(2112);
            assemblyFinished.TestsFailed.Returns(42);
            assemblyFinished.TestsSkipped.Returns(6);
            assemblyFinished.ExecutionTime.Returns(123.4567M);

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(assemblyStarting);
            visitor.OnMessage(assemblyFinished);

            Assert.Collection(logger.Messages,
                              message => Assert.Equal(message, "MESSAGE[High]:   Starting:    File"),
                              message => Assert.Equal(message, "MESSAGE[High]:   Finished:    File")
                              );
        }
Exemple #2
0
        public void OutputStartMessageWhenInVerboseMode()
        {
            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, true, null);

            visitor.OnMessage(testStarting);

            Assert.Single(logger.Messages, "MESSAGE[Normal]:     START: This is my display name \\t\\r\\n");
        }
Exemple #3
0
        public void NoOutputWhenNotInVerboseMode()
        {
            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testStarting);

            Assert.Empty(logger.Messages);
        }
Exemple #4
0
        public void AddsPassToLogWhenInVerboseMode()
        {
            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, true, null);

            visitor.OnMessage(testPassed);

            Assert.Single(logger.Messages, "MESSAGE[Normal]:     PASS:  This is my display name \\t\\r\\n");
        }
Exemple #5
0
        public void LogsTestName()
        {
            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testPassed);

            Assert.Single(logger.Messages, "MESSAGE[Normal]:     This is my display name \\t\\r\\n");
        }
Exemple #6
0
        public static void LogsMessage(IMessageSinkMessage message, string messageType)
        {
            var logger = SpyLogger.Create();

            using (var visitor = new StandardOutputVisitor(logger, null, false, null))
            {
                visitor.OnMessage(message);

                Assert.Collection(logger.Messages,
                                  msg => Assert.Equal(String.Format("ERROR: [{0}] ExceptionType : This is my message \\t\\r\\n", messageType), msg),
                                  msg => Assert.Equal("ERROR: Line 1\r\nLine 2\r\nLine 3", msg));
            }
        }
Exemple #7
0
        public static void LogsTestNameAsWarning()
        {
            var testSkipped = Substitute.For <ITestSkipped>();

            testSkipped.TestDisplayName.Returns("This is my display name \t\r\n");
            testSkipped.Reason.Returns("This is my skip reason \t\r\n");

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testSkipped);

            Assert.Single(logger.Messages, "WARNING: This is my display name \\t\\r\\n: This is my skip reason \\t\\r\\n");
        }
Exemple #8
0
        public static void IncludesSourceLineNumberFromTopOfStack(IMessageSinkMessage message, string messageType)
        {
            ((IFailureInformation)message).StackTraces.Returns(new[] { @"   at FixtureAcceptanceTests.Constructors.TestClassMustHaveSinglePublicConstructor() in d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs:line 16" });

            var logger = SpyLogger.Create(includeSourceInformation: true);

            using (var visitor = new StandardOutputVisitor(logger, null, false, null))
            {
                visitor.OnMessage(message);

                Assert.Collection(logger.Messages,
                                  msg => Assert.Equal(String.Format(@"ERROR: [FILE d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs][LINE 16] [{0}] ExceptionType : This is my message \t\r\n", messageType), msg),
                                  msg => Assert.Equal(@"ERROR: [FILE d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs][LINE 16]    at FixtureAcceptanceTests.Constructors.TestClassMustHaveSinglePublicConstructor() in d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs:line 16", msg));
            }
        }
Exemple #9
0
        public static void IncludesSourceLineNumberOfFirstStackFrameWithSourceInformation(IMessageSinkMessage message, string messageType)
        {
            ((IFailureInformation)message).StackTraces.Returns(new[] { @"   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)" + Environment.NewLine
                                                                       + @"   at FixtureAcceptanceTests.ClassFixture.TestClassWithExtraArgumentToConstructorResultsInFailedTest() in d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs:line 76" });

            var logger = SpyLogger.Create(includeSourceInformation: true);

            using (var visitor = new StandardOutputVisitor(logger, null, false, null))
            {
                visitor.OnMessage(message);

                Assert.Collection(logger.Messages,
                                  msg => Assert.Equal(String.Format(@"ERROR: [FILE d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs][LINE 76] [{0}] ExceptionType : This is my message \t\r\n", messageType), msg),
                                  msg => Assert.Equal(String.Format(@"ERROR: [FILE d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs][LINE 76]    at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source){0}   at FixtureAcceptanceTests.ClassFixture.TestClassWithExtraArgumentToConstructorResultsInFailedTest() in d:\Dev\xunit\xunit\test\test.xunit.execution\Acceptance\FixtureAcceptanceTests.cs:line 76", Environment.NewLine), msg));
            }
        }
Exemple #10
0
        public void NullStackTraceDoesNotLogStackTrace()
        {
            var testFailed = Substitute.For <ITestFailed>();

            testFailed.TestDisplayName.Returns("1");
            testFailed.Message.Returns("2");
            testFailed.StackTrace.Returns((string)null);

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testFailed);

            Assert.Collection(logger.Messages,
                              msg => Assert.Equal("ERROR: 1: 2", msg));
        }
Exemple #11
0
        public void LogsTestNameWithExceptionAndStackTrace()
        {
            var testFailed = Substitute.For <ITestFailed>();

            testFailed.TestDisplayName.Returns("This is my display name \t\r\n");
            testFailed.Message.Returns("This is my message \t\r\n");
            testFailed.StackTrace.Returns("Line 1\r\nLine 2\r\nLine 3");

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testFailed);

            Assert.Collection(logger.Messages,
                              msg => Assert.Equal("ERROR: This is my display name \\t\\r\\n: This is my message \\t\\r\\n", msg),
                              msg => Assert.Equal("ERROR: Line 1\r\nLine 2\r\nLine 3", msg));
        }
Exemple #12
0
        public void LogsMessage()
        {
            var errorMessage = Substitute.For <IErrorMessage>();

            errorMessage.ExceptionType.Returns("ExceptionType");
            errorMessage.Message.Returns("This is my message \t\r\n");
            errorMessage.StackTrace.Returns("Line 1\r\nLine 2\r\nLine 3");

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(errorMessage);

            Assert.Collection(logger.Messages,
                              msg => Assert.Equal("ERROR: ExceptionType: This is my message \\t\\r\\n", msg),
                              msg => Assert.Equal("ERROR: Line 1\r\nLine 2\r\nLine 3", msg));
        }
Exemple #13
0
        public static void NullStackTraceDoesNotLogStackTrace()
        {
            var testFailed = Substitute.For <ITestFailed>();

            testFailed.TestDisplayName.Returns("1");
            testFailed.Messages.Returns(new[] { "2" });
            testFailed.StackTraces.Returns(new[] { (string)null });
            testFailed.ExceptionTypes.Returns(new[] { "ExceptionType" });
            testFailed.ExceptionParentIndices.Returns(new[] { -1 });

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testFailed);

            Assert.Collection(logger.Messages,
                              msg => Assert.Equal("ERROR: 1: ExceptionType : 2", msg));
        }
        public static void LogsTestNameWithExceptionAndStackTrace()
        {
            var testFailed = Substitute.For <ITestFailed>();
            var test       = Mocks.Test(null, "This is my display name \t\r\n");

            testFailed.Test.Returns(test);
            testFailed.Messages.Returns(new[] { "This is my message \t\r\n" });
            testFailed.StackTraces.Returns(new[] { "Line 1\r\nLine 2\r\nLine 3" });
            testFailed.ExceptionTypes.Returns(new[] { "ExceptionType" });
            testFailed.ExceptionParentIndices.Returns(new[] { -1 });

            var logger  = SpyLogger.Create();
            var visitor = new StandardOutputVisitor(logger, null, false, null);

            visitor.OnMessage(testFailed);

            Assert.Collection(logger.Messages,
                              msg => Assert.Equal("ERROR: This is my display name \\t\\r\\n: ExceptionType : This is my message \\t\\r\\n", msg),
                              msg => Assert.Equal("ERROR: Line 1\r\nLine 2\r\nLine 3", msg));
        }