예제 #1
0
        public void JobLoggerCanAggregateLoggersExceptions()
        {
            JobLogger jl = JobLogger.Instance;

            jl.Reset();

            StubLogger consoleLogger1 = new StubConsoleLogger();
            StubLogger consoleLogger2 = new StubConsoleLogger();
            StubLogger exceptionLogger1 = new StubExceptionThrowingLogger();
            StubLogger exceptionLogger2 = new StubExceptionThrowingLogger();
            StubLogger exceptionLogger3 = new StubExceptionThrowingLogger();

            List<ILogger> loggers = new List<ILogger>
            {
                exceptionLogger1,
                consoleLogger1,
                exceptionLogger2,
                consoleLogger2,
                exceptionLogger3
            };

            jl.SetLoggers(loggers);
            jl.AcceptMessages<ErrorMessage>();

            jl.LogMessage(new ErrorMessage("Error message."));
        }
예제 #2
0
        public void JobLoggerCanContinueIfLoggersThrowExceptions()
        {
            int numberOfException = 0;
            string msg_text = "Error message.";

            JobLogger jl = JobLogger.Instance;

            jl.Reset();

            StubLogger consoleLogger1 = new StubConsoleLogger();
            StubLogger consoleLogger2 = new StubConsoleLogger();
            StubLogger exceptionLogger1 = new StubExceptionThrowingLogger();
            StubLogger exceptionLogger2 = new StubExceptionThrowingLogger();
            StubLogger exceptionLogger3 = new StubExceptionThrowingLogger();

            List<ILogger> loggers = new List<ILogger>
            {
                exceptionLogger1,
                consoleLogger1,
                exceptionLogger2,
                consoleLogger2,
                exceptionLogger3
            };

            jl.SetLoggers(loggers);
            jl.AcceptMessages<ErrorMessage>();

            try
            {
                jl.LogMessage(new ErrorMessage(msg_text));
            }
            catch (AggregateException agg)
            {
                numberOfException = agg.InnerExceptions.Count();
            }

            Assert.AreEqual(3, numberOfException);

            Assert.AreEqual(1, consoleLogger1.Output.Count);
            Assert.AreEqual(1, consoleLogger2.Output.Count);

            CollectionAssert.AreEqual(new List<string> { msg_text }, consoleLogger1.Output);
            CollectionAssert.AreEqual(new List<string> { msg_text }, consoleLogger2.Output);
        }