public void TestResultHandlerShouldNotShowDbgTrcMsg()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>();

            parameters.Add("verbosity", "normal");
            this.consoleLogger.Initialize(loggerEvents, parameters);

            var               testcase          = new TestCase("TestName", new Uri("some://uri"), "TestSource");
            string            message           = "Dummy message";
            TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.DebugTraceCategory, message);
            var               testresult        = new ObjectModel.TestResult(testcase)
            {
                Outcome = TestOutcome.Passed
            };

            testresult.Messages.Add(testResultMessage);

            loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult));
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.DbgTrcMessagesBanner, OutputLevel.Information), Times.Never());
            this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Never());
        }
        public void GetTestMessagesShouldWriteMessageAndStackTraceToConsole()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>();

            parameters.Add("verbosity", "normal");
            this.consoleLogger.Initialize(loggerEvents, parameters);

            var testresults = this.GetTestResultObject(TestOutcome.Failed);

            testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, "StandardOutCategory"));
            testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.StandardErrorCategory, "StandardErrorCategory"));
            testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.AdditionalInfoCategory, "AdditionalInfoCategory"));
            testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.AdditionalInfoCategory, "AnotherAdditionalInfoCategory"));

            foreach (var testResult in testresults)
            {
                loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
            }
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" StandardOutCategory", OutputLevel.Information), Times.Once());

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdErrMessagesBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" StandardErrorCategory", OutputLevel.Information), Times.Once());

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.AddnlInfoMessagesBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" AdditionalInfoCategory AnotherAdditionalInfoCategory", OutputLevel.Information), Times.Once());
        }
        public void DisplayFullInformationShouldWriteErrorMessageAndStackTraceToConsole()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>();

            parameters.Add("verbosity", "normal");
            this.consoleLogger.Initialize(loggerEvents, parameters);

            var testresults = this.GetTestResultObject(TestOutcome.Failed);

            testresults[0].ErrorMessage    = "ErrorMessage";
            testresults[0].ErrorStackTrace = "ErrorStackTrace";
            foreach (var testResult in testresults)
            {
                loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
            }
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}", " ErrorMessage"), OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}", "ErrorStackTrace"), OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.ErrorMessageBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StacktraceBanner, OutputLevel.Information), Times.Once());
        }
        public void TestResultHandlerShouldNotShowAdditionalInfoBannerIfAdditionalInfoIsEmpty()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>
            {
                { "verbosity", "normal" }
            };

            this.consoleLogger.Initialize(loggerEvents, parameters);

            var testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");

            TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.AdditionalInfoCategory, null);

            var testresult = new ObjectModel.TestResult(testcase)
            {
                Outcome = TestOutcome.Failed
            };

            testresult.Messages.Add(testResultMessage);

            loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult));
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.AddnlInfoMessagesBanner, OutputLevel.Information), Times.Never());
        }
        public void InNormalModeTestWarningAndErrorMessagesShouldShow()
        {
            // Setup
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>
            {
                { "verbosity", "normal" }
            };

            this.consoleLogger.Initialize(loggerEvents, parameters);
            string message      = "Adapter Warning";
            string errorMessage = "Adapter Error";

            // Act. Raise an event on mock object
            loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Warning, message));
            loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Error, errorMessage));
            loggerEvents.RaiseTestRunComplete(new TestRunCompleteEventArgs(new Mock <ITestRunStatistics>().Object, false, false, null, new Collection <AttachmentSet>(), TimeSpan.FromSeconds(1)));
            loggerEvents.WaitForEventCompletion();

            // Verify
            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunFailed, OutputLevel.Error), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(message, OutputLevel.Warning), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(errorMessage, OutputLevel.Error), Times.Once());
        }
        public void DetailedVerbosityShowStdOutMessagesForPassedTests()
        {
            // Setup
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>
            {
                { "verbosity", "detailed" }
            };

            this.consoleLogger.Initialize(loggerEvents, parameters);
            var    testcase = new TestCase("TestName", new Uri("some://uri"), "TestSource");
            string message  = "Dummy message";

            TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.StandardOutCategory, message);
            var testresult = new ObjectModel.TestResult(testcase)
            {
                Outcome = TestOutcome.Passed
            };

            testresult.Messages.Add(testResultMessage);

            // Act. Raise an event on mock object
            loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult));
            loggerEvents.WaitForEventCompletion();

            // Verify
            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
        }
        public void TestResultHandlerShouldWriteToNoTestResultForQuietVerbosity()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>();

            parameters.Add("verbosity", "Quiet");
            this.consoleLogger.Initialize(loggerEvents, parameters);

            foreach (var testResult in this.GetTestResultsObject())
            {
                loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
            }
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.PassedTestIndicator, "TestName"), OutputLevel.Information), Times.Never);
            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, "TestName"), OutputLevel.Information), Times.Never);
            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, "TestName"), OutputLevel.Warning), Times.Never);
            this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, "TestName"), OutputLevel.Information), Times.Never);
        }
        public void DisplayFullInformationShouldWriteStdMessageWithNewLine()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>();

            parameters.Add("verbosity", "detailed");
            this.consoleLogger.Initialize(loggerEvents, parameters);

            var testresults = this.GetTestResultObject(TestOutcome.Passed);

            testresults[0].Messages.Add(new TestResultMessage(TestResultMessage.StandardOutCategory, "Hello"));

            foreach (var testResult in testresults)
            {
                loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult));
            }
            loggerEvents.WaitForEventCompletion();

            this.mockOutput.Verify(o => o.WriteLine("Passed   TestName", OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" Hello", OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(String.Empty, OutputLevel.Information), Times.Once());
        }
        public void TestResultHandlerShouldShowStdOutMessagesBannerIfStdOutIsNotEmpty()
        {
            var count = 0;

            this.mockOutput.Setup(o => o.WriteLine(It.IsAny <string>(), It.IsAny <OutputLevel>())).Callback <string, OutputLevel>(
                (s, o) => { count++; });

            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();
            var parameters = new Dictionary <string, string>
            {
                { "verbosity", "normal" }
            };

            this.consoleLogger.Initialize(loggerEvents, parameters);

            string            message           = "Dummy message";
            var               testcase          = new TestCase("TestName", new Uri("some://uri"), "TestSource");
            TestResultMessage testResultMessage = new TestResultMessage(TestResultMessage.StandardOutCategory, message);
            var               testresult        = new ObjectModel.TestResult(testcase)
            {
                Outcome = TestOutcome.Failed
            };

            testresult.Messages.Add(testResultMessage);

            loggerEvents.RaiseTestResult(new TestResultEventArgs(testresult));
            loggerEvents.WaitForEventCompletion();

            // Added this for synchronization
            SpinWait.SpinUntil(() => count == 2, 300);

            this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.StdOutMessagesBanner, OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine(" " + message, OutputLevel.Information), Times.Once());
        }