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 CompleteTestRunShouldInvokeRegisteredEventHandler() { bool testRunCompleteReceived = false; TestRunCompleteEventArgs eventArgs = null; EventWaitHandle waitHandle = new AutoResetEvent(false); // Register for the test run complete event. loggerEvents.TestRunComplete += (sender, e) => { testRunCompleteReceived = true; eventArgs = e; waitHandle.Set(); }; loggerEvents.EnableEvents(); // Send the test run complete event. loggerEvents.CompleteTestRun(null, false, false, null, null, new TimeSpan()); var waitSuccess = waitHandle.WaitOne(500); Assert.IsTrue(waitSuccess, "Event must be raised within timeout."); Assert.IsTrue(testRunCompleteReceived); Assert.IsNotNull(eventArgs); }
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()); }
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 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 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); }