public void RaiseMessageShouldInvokeRegisteredEventHandlerIfTestRunMessageEventArgsIsPassed() { EventWaitHandle waitHandle = new AutoResetEvent(false); bool testMessageReceived = false; TestRunMessageEventArgs eventArgs = null; var message = "This is the test message"; // Register for the test message event. loggerEvents.TestRunMessage += (sender, e) => { testMessageReceived = true; eventArgs = e; waitHandle.Set(); }; loggerEvents.EnableEvents(); // Send the test mesage event. loggerEvents.RaiseMessage(new TestRunMessageEventArgs(TestMessageLevel.Informational, message)); var waitSuccess = waitHandle.WaitOne(500); Assert.IsTrue(waitSuccess, "Event must be raised within timeout."); Assert.IsTrue(testMessageReceived); Assert.IsNotNull(eventArgs); Assert.AreEqual(message, eventArgs.Message); Assert.AreEqual(TestMessageLevel.Informational, eventArgs.Level); }
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 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)); // 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()); }
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 AttachmentInformationShouldBeWrittenToConsoleIfAttachmentsArePresent() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); this.consoleLogger.Initialize(loggerEvents, parameters); var attachmentSet = new AttachmentSet(new Uri("test://uri"), "myattachmentset"); var uriDataAttachment = new UriDataAttachment(new Uri("file://server/filename.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment); var uriDataAttachment1 = new UriDataAttachment(new Uri("file://server/filename1.ext"), "description"); attachmentSet.Attachments.Add(uriDataAttachment1); var attachmentSetList = new List <AttachmentSet> { attachmentSet }; loggerEvents.CompleteTestRun(null, false, false, null, new Collection <AttachmentSet>(attachmentSetList), new TimeSpan(1, 0, 0, 0)); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment1.Uri.LocalPath), 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()); }
private void InitializeAndVerify(int count) { // Initialize var attachmentSetList = new List <AttachmentSet>(); for (int i = 0; i < count; i++) { attachmentSetList.Add(this.GetAttachmentSet()); } // Initialize Blame Logger var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); this.blameLogger.Initialize(loggerEvents, (string)null); var testCaseList = new List <BlameTestObject> { new BlameTestObject(new TestCase("ABC.UnitTestMethod1", new Uri("test://uri"), "C://test/filepath")), new BlameTestObject(new TestCase("ABC.UnitTestMethod2", new Uri("test://uri"), "C://test/filepath")) }; // Setup and Raise event this.mockBlameReaderWriter.Setup(x => x.ReadTestSequence(It.IsAny <string>())).Returns(testCaseList); loggerEvents.CompleteTestRun(null, false, true, null, new Collection <AttachmentSet>(attachmentSetList), new TimeSpan(1, 0, 0, 0)); // Verify Call this.mockBlameReaderWriter.Verify(x => x.ReadTestSequence(It.Is <string>(str => str.EndsWith(".xml"))), Times.Exactly(count)); }
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 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 PrintTimeHandlerShouldPrintElapsedTimeOnConsole() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); this.consoleLogger.Initialize(loggerEvents, parameters); foreach (var testResult in this.GetTestResultObject(TestOutcome.Passed)) { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(1, 0, 0, 0)); loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(0, 1, 0, 0)); loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(0, 0, 1, 0)); loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(0, 0, 0, 1)); // Verify PrintTimeSpan with different formats this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Days), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Hours), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Minutes), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ExecutionTimeFormatString, 1, CommandLineResources.Seconds), OutputLevel.Information), Times.Once()); }
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()); }
private void SetupForTestMessageHandler(out InternalTestLoggerEvents loggerEvents) { loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); this.consoleLogger.Initialize(loggerEvents, parameters); }
public void TestResultHandlerShouldThowExceptionIfEventArgsIsNull() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); Assert.ThrowsException <ArgumentNullException>(() => { loggerEvents.RaiseTestResult(default(TestResultEventArgs)); }); }
public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAbortedWithoutRunningAnyTest() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); this.consoleLogger.Initialize(loggerEvents, parameters); loggerEvents.CompleteTestRun(null, false, true, null, null, new TimeSpan(1, 0, 0, 0)); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), Times.Once()); }
public void TestRunCompleteHandlerShouldNotReadFileIfTestRunNotAborted() { // Initialize Blame Logger var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); this.blameLogger.Initialize(loggerEvents, (string)null); // Setup and Raise event this.mockBlameReaderWriter.Setup(x => x.ReadTestSequence(It.IsAny <string>())); loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan(1, 0, 0, 0)); // Verify Call this.mockBlameReaderWriter.Verify(x => x.ReadTestSequence(It.IsAny <string>()), Times.Never); }
public void TestRunCompleteHandlerShouldWriteToConsoleIfTestsAborted() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); this.consoleLogger.Initialize(loggerEvents, parameters); foreach (var testResult in this.GetTestResultObject(TestOutcome.Failed)) { loggerEvents.RaiseTestResult(new TestResultEventArgs(testResult)); } loggerEvents.CompleteTestRun(null, false, true, null, null, new TimeSpan(1, 0, 0, 0)); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestRunSummaryForCanceledOrAbortedRun, 0, 1, 0), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(CommandLineResources.TestRunAborted, OutputLevel.Error), 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)); } 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 TestRunCompleteHandlerShouldReturnIfUriAttachmentIsNull() { // Initialize var attachmentSet = new AttachmentSet(new Uri("test://uri"), "Blame"); var attachmentSetList = new List <AttachmentSet> { attachmentSet }; // Initialize Blame Logger var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); this.blameLogger.Initialize(loggerEvents, (string)null); // Setup and Raise event loggerEvents.CompleteTestRun(null, false, true, null, new Collection <AttachmentSet>(attachmentSetList), new TimeSpan(1, 0, 0, 0)); // Verify Call this.mockBlameReaderWriter.Verify(x => x.ReadTestSequence(It.IsAny <string>()), Times.Never); }
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()); }
public void TestResultHandlerShouldWriteToConsoleShouldShowPassedTestsForNormalVebosity() { var loggerEvents = new InternalTestLoggerEvents(TestSessionMessageLogger.Instance); loggerEvents.EnableEvents(); var parameters = new Dictionary <string, string>(); parameters.Add("verbosity", "normal"); 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.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.FailedTestIndicator, "TestName"), OutputLevel.Information), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.SkippedTestIndicator, "TestName"), OutputLevel.Warning), Times.Once()); this.mockOutput.Verify(o => o.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.NotRunTestIndicator, "TestName"), OutputLevel.Information), Times.Exactly(2)); this.mockProgressIndicator.Verify(pi => pi.Pause(), Times.Exactly(5)); this.mockProgressIndicator.Verify(pi => pi.Start(), Times.Exactly(5)); }
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()); }