Пример #1
0
        public void GetMessageMustNotLogExceptionWhenExceptionIsNull()
        {
            DateTime now = DateTime.UtcNow;
            StubConsoleLoggerFormatter formatter = new StubConsoleLoggerFormatter(now);
            string message = formatter.GetMessage(nameof(ConsoleLoggerFormatterTests), LogLevel.Information, "Test", null);

            Assert.Matches($@"(?s)^{now:O} Information {nameof(ConsoleLoggerFormatterTests)} \[.*\] Test$", message);
        }
Пример #2
0
        public void GetMessageMustLogExceptionWhenExceptionIsNotNull()
        {
            DateTime now = DateTime.UtcNow;
            StubConsoleLoggerFormatter formatter = new StubConsoleLoggerFormatter(now);
            string message = formatter.GetMessage(nameof(ConsoleLoggerFormatterTests), LogLevel.Information, "Test", new Exception("Test"));

            Assert.Matches($@"(?s)^{now:O} Information {nameof(ConsoleLoggerFormatterTests)} \[.*\] Test{Environment.NewLine}System.Exception: Test.*$", message);
        }
Пример #3
0
        public void GetThreadIdMustReturnThreadNameWhenThreadNameIsNotEmpty()
        {
            bool   result = false;
            Thread thread = new Thread(() =>
            {
                try
                {
                    string threadId = new StubConsoleLoggerFormatter().InvokeGetThreadId();
                    result          = threadId == "Test";
                }
                catch
                {
                    result = false;
                }
            })
            {
                IsBackground = true, Name = "Test"
            };

            thread.Start();
            thread.Join();
            Assert.True(result);
        }