예제 #1
0
        public void debugging_by_object()
        {
            var l1 = new RecordingLogListener { IsInfoEnabled = true };
            var l2 = new RecordingLogListener { IsInfoEnabled = false, IsDebugEnabled = true };
            var l3 = new RecordingLogListener { IsInfoEnabled = true };

            l1.ListensForTypes[typeof(Trace1)] = true;
            l2.ListensForTypes[typeof(Trace1)] = true;
            l3.ListensForTypes[typeof(Trace2)] = true;

            var logger = new Logger(SystemTime.Default(), new ILogListener[] { l1, l2, l3 });

            var msg1 = new Trace1();
            var msg2 = new Trace1();

            logger.DebugMessage(msg1);
            logger.DebugMessage(() => msg2);

            l1.DebugMessages.Any().ShouldBeFalse(); // debugging is not enabled
            l2.DebugMessages.ShouldHaveTheSameElementsAs(msg1, msg2);
            l3.DebugMessages.Any().ShouldBeFalse(); // does not listen to Trace1
        }
예제 #2
0
        public void debugging_by_message_puts_a_time_stamp_on_it_2()
        {
            var l1 = new RecordingLogListener { IsInfoEnabled = true };
            var l2 = new RecordingLogListener { IsInfoEnabled = false, IsDebugEnabled = true };
            var l3 = new RecordingLogListener { IsInfoEnabled = true };

            l1.ListensForTypes[typeof(StringMessage)] = true;
            l2.ListensForTypes[typeof(StringMessage)] = true;
            l3.ListensForTypes[typeof(StringMessage)] = true;

            var systemTime = SystemTime.AtLocalTime(DateTime.Today.AddHours(8));
            var logger = new Logger(systemTime, new ILogListener[] { l1, l2, l3 });

            var message = new StringMessage("something");
            logger.DebugMessage(message);

            message.Time.ShouldEqual(systemTime.UtcNow());
        }