public void CLogger_ExpectedMessages_Message()
        {
            using (var output = new OutputCaptureScope())
            {
                // 1. Logger without timestamps
                var logger = new ConsoleLogger(includeTimestamp: false);

                logger.LogInfo("message1");
                output.AssertExpectedLastMessage("message1");

                logger.LogInfo("message2", null);
                output.AssertExpectedLastMessage("message2");

                logger.LogInfo("message3 {0}", "xxx");
                output.AssertExpectedLastMessage("message3 xxx");

                // 2. Logger with timestamps
                logger = new ConsoleLogger(includeTimestamp: true);

                logger.LogInfo("message4");
                output.AssertLastMessageEndsWith("message4");

                logger.LogInfo("message5{0}{1}", null, null);
                output.AssertLastMessageEndsWith("message5");

                logger.LogInfo("message6 {0}{1}", "xxx", "yyy", "zzz");
                output.AssertLastMessageEndsWith("message6 xxxyyy");
            }
        }
        public void CLogger_Verbosity()
        {
            var logger = new ConsoleLogger(includeTimestamp: false);

            logger.Verbosity.Should().Be(LoggerVerbosity.Debug, "Default verbosity should be Debug");

            using (var output = new OutputCaptureScope())
            {
                logger.Verbosity = LoggerVerbosity.Info;
                logger.LogInfo("info1");
                output.AssertExpectedLastMessage("info1");
                logger.LogInfo("info2");
                output.AssertExpectedLastMessage("info2");
                logger.LogDebug("debug1");
                output.AssertExpectedLastMessage("info2"); // the debug message should not have been logged

                logger.Verbosity = LoggerVerbosity.Debug;
                logger.LogDebug("debug");
                output.AssertExpectedLastMessage("debug");
                logger.LogInfo("info3");
                output.AssertExpectedLastMessage("info3");

                logger.Verbosity = LoggerVerbosity.Info;
                logger.LogInfo("info4");
                output.AssertExpectedLastMessage("info4");
                logger.LogDebug("debug2");
                output.AssertExpectedLastMessage("info4");
            }
        }
        public void CLogger_ExpectedMessages_Error()
        {
            using (var output = new OutputCaptureScope())
            {
                // 1. Logger without timestamps
                var logger = new ConsoleLogger(includeTimestamp: false);

                logger.LogError("simple error1");
                output.AssertExpectedLastError("simple error1");

                logger.LogError("simple error2", null);
                output.AssertExpectedLastError("simple error2");

                logger.LogError("simple error3 {0}", "xxx");
                output.AssertExpectedLastError("simple error3 xxx");

                // 2. Logger with timestamps
                logger = new ConsoleLogger(includeTimestamp: true);

                logger.LogError("simple error4");
                output.AssertLastErrorEndsWith("simple error4");

                logger.LogError("simple error5{0}{1}", null, null);
                output.AssertLastErrorEndsWith("simple error5");

                logger.LogError("simple error6 {0}{1}", "xxx", "yyy", "zzz");
                output.AssertLastErrorEndsWith("simple error6 xxxyyy");
            }
        }
        public void CLogger_ExpectedMessages_Warning()
        {
            // NOTE: we expect all warnings to be prefixed with a localized
            // "WARNING" prefix, so we're using "AssertLastMessageEndsWith"
            // even for warnings that do not have timestamps.

            using (var output = new OutputCaptureScope())
            {
                // 1. Logger without timestamps
                var logger = new ConsoleLogger(includeTimestamp: false);

                logger.LogWarning("warn1");
                output.AssertLastMessageEndsWith("warn1");

                logger.LogWarning("warn2", null);
                output.AssertLastMessageEndsWith("warn2");

                logger.LogWarning("warn3 {0}", "xxx");
                output.AssertLastMessageEndsWith("warn3 xxx");

                // 2. Logger with timestamps
                logger = new ConsoleLogger(includeTimestamp: true);

                logger.LogWarning("warn4");
                output.AssertLastMessageEndsWith("warn4");

                logger.LogWarning("warn5{0}{1}", null, null);
                output.AssertLastMessageEndsWith("warn5");

                logger.LogWarning("warn6 {0}{1}", "xxx", "yyy", "zzz");
                output.AssertLastMessageEndsWith("warn6 xxxyyy");
            }
        }
        public void CLogger_FormattedStrings()
        {
            using (var output = new OutputCaptureScope())
            {
                // 1. Logger without timestamps
                var logger = new ConsoleLogger(includeTimestamp: false);

                logger.LogInfo("{ }");
                output.AssertExpectedLastMessage("{ }");

                logger.LogInfo("}{");
                output.AssertExpectedLastMessage("}{");

                logger.LogInfo("a{1}2", null);
                output.AssertExpectedLastMessage("a{1}2");

                logger.LogInfo("{0}", "123");
                output.AssertExpectedLastMessage("123");

                logger.LogInfo("a{0}{{{1}}}", "11", "22");
                output.AssertExpectedLastMessage("a11{22}");

                // 2. Logger with timestamps
                logger = new ConsoleLogger(includeTimestamp: true);

                logger.LogInfo("{ }");
                output.AssertLastMessageEndsWith("{ }");

                logger.LogInfo("}{");
                output.AssertLastMessageEndsWith("}{");

                logger.LogInfo("a{1}2", null);
                output.AssertLastMessageEndsWith("a{1}2");

                logger.LogInfo("{0}", "123");
                output.AssertLastMessageEndsWith("123");

                logger.LogInfo("a{0}{{{1}}}", "11", "22");
                output.AssertLastMessageEndsWith("a11{22}");
            }
        }