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());
        }
Example #2
0
        public void TestMessageHandlerShouldWriteToConsoleIfTestRunEventsAreRaised()
        {
            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>();

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

            loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Informational, "Informational123"));
            loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Error, "Error123"));
            loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Warning, "Warning123"));

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

            this.mockOutput.Verify(o => o.WriteLine("Informational123", OutputLevel.Information), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine("Warning123", OutputLevel.Warning), Times.Once());
            this.mockOutput.Verify(o => o.WriteLine("Error123", OutputLevel.Error), Times.Once());
        }
        public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull()
        {
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

            loggerEvents.EnableEvents();

            Assert.ThrowsException <ArgumentNullException>(() =>
            {
                loggerEvents.RaiseTestRunMessage(default(TestRunMessageEventArgs));
            });
        }
Example #4
0
        public void InQuietModeTestWarningMessageShouldNotShow()
        {
            // Setup
            var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance);

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

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

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

            // Verify
            this.mockOutput.Verify(o => o.WriteLine(message, OutputLevel.Warning), Times.Never());
        }
Example #5
0
 public void RaiseTestRunMessageShouldNotThrowExceptionIfNoEventHandlersAreRegistered()
 {
     // Send the test mesage event.
     loggerEvents.RaiseTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Informational, "This is a string."));
 }