public void ConfirmLoggingTest() { var myLogger = new ConsoleLogger(); // Create mock TextWriters which confirm the output var stringOutput = new Mock<TextWriter>(); stringOutput.Setup(w => w.WriteLine(It.IsRegex("\\([^)]+\\) \\.NET Client API \\[(\\w+)\\]: FooBar"))); var nullOutput = new Mock<TextWriter>(); nullOutput .Setup(w => w.WriteLine(It.IsAny<string>())) .Callback<string>(str => Assert.Fail("Unexpected WriteLine(): " + str)); // Test non-error methods: Console.SetOut(stringOutput.Object); Console.SetError(nullOutput.Object); myLogger.Info("FooBar"); myLogger.Debug("FooBar"); myLogger.Warning("FooBar"); stringOutput.Verify(); nullOutput.Verify(); // Test error-methods: Console.SetOut(nullOutput.Object); Console.SetError(stringOutput.Object); myLogger.Error("FooBar"); stringOutput.Verify(); nullOutput.Verify(); }
public void SimpleLogTest() { var myLogger = new ConsoleLogger(); myLogger.Debug("FooBar"); myLogger.Warning("FooBar"); myLogger.Error("FooBar"); myLogger.Error(new Exception(), "FooBar"); myLogger.Info("FooBar"); myLogger.Info("FooBar", "Bar"); Assert.AreEqual(myLogger.IsDebugEnabled, myLogger.IsDebugEnabled); // We don't care about the actual value. }