Ejemplo n.º 1
0
        public void MultipleClose()
        {
            IDefaultActivityLogger logger = DefaultActivityLogger.Create();

            // Binds the TestHelper.Logger logger to this one.
            logger.Output.RegisterMuxClient(TestHelper.Logger.Output.ExternalInput);

            var log1 = new StringImpl();

            logger.Register(log1);

            Assert.That(logger.RegisteredSinks.Count, Is.EqualTo(1));

            using (logger.OpenGroup(LogLevel.Trace, () => "End First", "First"))
            {
                logger.CloseGroup("Pouf");
                using (logger.OpenGroup(LogLevel.Warn, "A group at level 0!"))
                {
                    logger.CloseGroup("Close it.");
                    logger.CloseGroup("Close it again.");
                }
            }

            Assert.That(log1.Writer.ToString(), Is.Not.StringContaining("End First"), "Close forgets other closes...");
            Assert.That(log1.Writer.ToString(), Is.Not.StringContaining("Close it again"), "Close forgets other closes...");
        }
Ejemplo n.º 2
0
        public void ExplicitCloseWins()
        {
            IDefaultActivityLogger l = DefaultActivityLogger.Create();

            // Binds the TestHelper.Logger logger to this one.
            l.Output.RegisterMuxClient(TestHelper.Logger.Output.ExternalInput);

            var log = new StringImpl();

            l.Register(log);

            // No explicit close conclusion: Success!
            using (l.OpenGroup(LogLevel.Trace, () => "Success!", "First"))
            {
                l.Error("Pouf");
            }
            Assert.That(log.Writer.ToString(), Is.StringContaining("Pouf"));
            Assert.That(log.Writer.ToString(), Is.Not.StringContaining("Failed!"), "Default conclusion wins.");
            Assert.That(log.Writer.ToString(), Is.StringContaining("Success!"), "Default conclusion.");

            log.Writer.GetStringBuilder().Clear();
            Assert.That(log.Writer.ToString(), Is.Empty);

            // Explicit conclusion: Failed!
            using (l.OpenGroup(LogLevel.Trace, () => "Success!", "First"))
            {
                l.Error("Pouf");
                l.CloseGroup("Failed!");
            }
            Console.WriteLine(log.Writer.ToString());

            Assert.That(log.Writer.ToString(), Is.StringContaining("Pouf"));
            Assert.That(log.Writer.ToString(), Is.StringContaining("Failed!"), "Explicit conclusion wins.");
            Assert.That(log.Writer.ToString(), Is.Not.StringContaining("Success!"), "Explicit conclusion wins.");
        }