コード例 #1
0
        public void LogInfoTest()
        {
            var source  = "source";
            var message = "message";

            var writer = new Mock <IOutputWriter>();

            var logger = new ConsoleLoggingService(writer.Object);

            logger.LogInfo(source, message);

            var expectedLog1 = "Info from " + source + ": " + message;

            writer.Verify(w => w.WriteLine(It.Is <string>(s => s == expectedLog1)), Times.Once);
        }
コード例 #2
0
        public void LogInfoWithExceptionTest()
        {
            var source    = "source";
            var message   = "message";
            var exception = new Exception("exception");

            var writer = new Mock <IOutputWriter>();

            var logger = new ConsoleLoggingService(writer.Object);

            logger.LogInfo(source, message, exception);

            var expectedLog1 = "Info from " + source + ": " + message;
            var expectedLog2 = "Exception logged: " + exception.Message;

            writer.Verify(w => w.WriteLine(It.Is <string>(s => s == expectedLog1)), Times.Once);
            writer.Verify(w => w.WriteLine(It.Is <string>(s => s == expectedLog2)), Times.Once);
        }