コード例 #1
0
        public void TraceSourceLogger_Verbose_Does_Not_Log_If_Some_Logging_Levels_Are_Not_Enabled()
        {
            // Arrange
            Helpers.InvokeInNewAppDomain(
                () =>
            {
                TraceSourceLogger target = TraceSourceLogger.Instance;

                // Act
                target.WriteError(1, "Letter 1 is {0}.", 'a');
                target.WriteWarning(2, "Letter 2 is {0}.", 'b');
                target.WriteInformation(3, "Letter 3 is {0}.", 'c');
                target.WriteVerbose(4, "Letter 4 is {0}.", 'd');

                // Assert
                var data = TestTraceListener.LogData;

                Assert.AreEqual(2, data.Count, "An incorrect number of messages were logged.");

                int count = data
                            .Where((p) => p.Item1 == TraceEventType.Error)
                            .Where((p) => p.Item2 == 1)
                            .Where((p) => p.Item3 == "Letter 1 is {0}.")
                            .Where((p) => p.Item4 != null)
                            .Where((p) => p.Item4.Length == 1)
                            .Where((p) => (char)p.Item4[0] == 'a')
                            .Count();

                Assert.AreEqual(1, count, "The error message was not logged correctly.");

                count = data
                        .Where((p) => p.Item1 == TraceEventType.Warning)
                        .Where((p) => p.Item2 == 2)
                        .Where((p) => p.Item3 == "Letter 2 is {0}.")
                        .Where((p) => p.Item4 != null)
                        .Where((p) => p.Item4.Length == 1)
                        .Where((p) => (char)p.Item4[0] == 'b')
                        .Count();

                Assert.AreEqual(1, count, "The warning message was not logged correctly.");
            },
                configurationFile: "TraceSourceLoggerTests.SomeDisabled.config");
        }
コード例 #2
0
        public void TraceSourceLogger_Verbose_Does_Not_Log_If_All_Logging_Levels_Are_Not_Disabled()
        {
            // Arrange
            Helpers.InvokeInNewAppDomain(
                () =>
            {
                TraceSourceLogger target = TraceSourceLogger.Instance;

                // Act
                target.WriteError(1, "Letter 1 is {0}.", 'a');
                target.WriteWarning(2, "Letter 2 is {0}.", 'b');
                target.WriteInformation(3, "Letter 3 is {0}.", 'c');
                target.WriteVerbose(4, "Letter 4 is {0}.", 'd');

                // Assert
                var data = TestTraceListener.LogData;

                Assert.AreEqual(0, data.Count, "An incorrect number of messages were logged.");
            },
                configurationFile: "TraceSourceLoggerTests.AllDisabled.config");
        }