public void ReportMessageToConsole_Does_Nothing_If_Logging_Event_Handled() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); string testTitle = "Test title"; string testMessage = "Test message"; MessengerReporter reporter = new MessengerReporter(); MessengerListener.SubscribeListener(reporter); //Check for event MessengerEventArgs arg = new MessengerEventArgs(testTitle, testMessage); reporter.ThrowMessengerEvent(arg); string expected = string.Format(testTitle + Environment.NewLine + testMessage + Environment.NewLine); Assert.AreEqual(expected, sw.ToString()); // Clear Console output StringBuilder sb = sw.GetStringBuilder(); sb.Remove(0, sb.Length); // Check that event does not trigger again arg.Handled = true; reporter.ThrowMessengerEvent(arg); expected = string.Empty; Assert.AreEqual(expected, sw.ToString()); } }
public void TestInitialize() { moqFactory = new Fakes.FakeFactory(true); moqFactory.Client.Setup(x => x.IsConnected).Returns(true); Listener = new MessengerListener(moqFactory.Client.Object); }
public void SubscribeListener_Subsribes_Listener() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); string testTitle = "Test title"; string testMessage = "Test message"; MessengerReporter reporter = new MessengerReporter(); MessengerListener.SubscribeListener(reporter); //Check for event MessengerEventArgs arg = new MessengerEventArgs(testTitle, testMessage); reporter.ThrowMessengerEvent(arg); string expected = string.Format(testTitle + Environment.NewLine + testMessage + Environment.NewLine); Assert.AreEqual(expected, sw.ToString()); } }