public void ErrorCounterTests() { var logger = new ActivityLogger(); // Binds the TestHelper.Logger logger to this one. logger.Output.RegisterMuxClient(TestHelper.Logger.Output.ExternalInput); // Registers the ErrorCounter first: it will be the last one to be called, but // this does not prevent the PathCatcher to work: the path elements reference the group // so that aany conclusion arriving after PathCatcher.OnClosing are available. ActivityLoggerErrorCounter c = new ActivityLoggerErrorCounter(); logger.Output.RegisterMuxClient(c); // Registers the PathCatcher now: it will be called BEFORE the ErrorCounter. ActivityLoggerPathCatcher p = new ActivityLoggerPathCatcher(); logger.Output.RegisterClient(p); Assert.That(c.GenerateConclusion, Is.True, "Must be the default."); Assert.That(c.Root.MaxLogLevel == LogLevel.None); logger.Trace("T1"); Assert.That(!c.Root.HasWarnOrError && !c.Root.HasError); Assert.That(c.Root.MaxLogLevel == LogLevel.Trace); Assert.That(c.Root.ToString(), Is.Null); logger.Warn("W1"); Assert.That(c.Root.HasWarnOrError && !c.Root.HasError); Assert.That(c.Root.MaxLogLevel == LogLevel.Warn); Assert.That(c.Root.ToString(), Is.Not.Null.And.Not.Empty); logger.Error("E2"); Assert.That(c.Root.HasWarnOrError && c.Root.HasError); Assert.That(c.Root.ErrorCount == 1); Assert.That(c.Root.MaxLogLevel == LogLevel.Error); Assert.That(c.Root.ToString(), Is.Not.Null.And.Not.Empty); c.Root.ClearError(); Assert.That(c.Root.HasWarnOrError && !c.Root.HasError); Assert.That(c.Root.ErrorCount == 0); Assert.That(c.Root.MaxLogLevel == LogLevel.Warn); Assert.That(c.Root.ToString(), Is.Not.Null); c.Root.ClearWarn(); Assert.That(!c.Root.HasWarnOrError && !c.Root.HasError); Assert.That(c.Root.MaxLogLevel == LogLevel.Info); Assert.That(c.Root.ToString(), Is.Null); using (logger.OpenGroup(LogLevel.Trace, "G1")) { using (logger.OpenGroup(LogLevel.Info, "G2")) { logger.Error("E1"); logger.Fatal("F1"); Assert.That(c.Root.HasWarnOrError && c.Root.HasError); Assert.That(c.Root.ErrorCount == 1 && c.Root.FatalCount == 1); Assert.That(c.Root.WarnCount == 0); using (logger.OpenGroup(LogLevel.Info, "G3")) { Assert.That(!c.Current.HasWarnOrError && !c.Current.HasError); Assert.That(c.Current.ErrorCount == 0 && c.Current.FatalCount == 0 && c.Current.WarnCount == 0); logger.Error("E2"); Assert.That(c.Current.HasWarnOrError && c.Current.HasError); Assert.That(c.Current.ErrorCount == 1 && c.Current.FatalCount == 0 && c.Current.WarnCount == 0); } } Assert.That(String.Join(">", p.LastErrorPath.Select(e => e.Text + '-' + e.GroupConclusion.ToStringGroupConclusion())), Is.EqualTo("G1->G2-1 Fatal error, 2 Errors>G3-1 Error>E2-")); logger.Error("E3"); logger.Fatal("F2"); logger.Warn("W2"); Assert.That(c.Root.HasWarnOrError && c.Root.HasError); Assert.That(c.Root.FatalCount == 2); Assert.That(c.Root.ErrorCount == 3); Assert.That(c.Root.MaxLogLevel == LogLevel.Fatal); } Assert.That(String.Join(">", p.LastErrorPath.Select(e => e.Text + '-' + e.GroupConclusion.ToStringGroupConclusion())), Is.EqualTo("G1-2 Fatal errors, 3 Errors, 1 Warning>F2-")); Assert.That(String.Join(">", p.LastWarnOrErrorPath.Select(e => e.Text + '-' + e.GroupConclusion.ToStringGroupConclusion())), Is.EqualTo("G1-2 Fatal errors, 3 Errors, 1 Warning>W2-")); }