public void WritesOverloads() { var capture = new ConsoleCapture(); var o = new object(); HConsole.Configure(o, config => config.SetMaxLevel(0)); using (capture.Output()) { HConsole.WriteLine(o, "text0"); HConsole.WriteLine(o, 0, "text1"); HConsole.WriteLine(o, 2); HConsole.WriteLine(o, 0, 3); HConsole.WriteLine(o, "-{0}-", 4); HConsole.WriteLine(o, 0, "-{0}-", 5); HConsole.WriteLine(o, 1, "text1"); HConsole.WriteLine(o, 1, 3); HConsole.WriteLine(o, 1, "-{0}-", 5); } Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo($@"{Prefix()}text0 {Prefix()}text1 {Prefix()}2 {Prefix()}3 {Prefix()}-4- {Prefix()}-5- ".ToLf())); }
public void Captures() { var capture = new ConsoleCapture(); using (capture.Output()) { Console.WriteLine("test"); } Assert.AreEqual("test" + Environment.NewLine, capture.ReadToEnd()); }
public void WriteAndClear() { var capture = new ConsoleCapture(); HConsole.WriteAndClear(); Assert.That(HConsole.Text.Length, Is.Zero); HConsole.WriteAndClear(); Assert.That(HConsole.Text.Length, Is.Zero); HConsole.Configure(x => x.Set(xx => xx.Verbose())); HConsole.WriteLine(this, "meh"); Assert.That(HConsole.Text.Length, Is.GreaterThan(0)); using (capture.Output()) { HConsole.WriteAndClear(); } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine)); HConsole.WriteLine(this, "meh"); Assert.That(HConsole.Text.Length, Is.GreaterThan(0)); using (capture.Output()) { HConsole.Clear(); } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd().Length, Is.Zero); HConsole.WriteLine(this, "meh"); using (capture.Output()) { using (HConsole.Capture()) { } } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine)); }
public void Do() { var capture = new ConsoleCapture(); using (capture.Output()) { LogA.WriteLine(this, "BLAHA"); LogB.WriteLine(this, "BLAHB"); } Assert.AreEqual("XXXA BLAHA\n", capture.ReadToEnd().ToLf()); }
public void WritesNothingByDefault() { var capture = new ConsoleCapture(); var o = new object(); using (capture.Output()) { HConsole.WriteLine(o, "text0"); // default level is 0 HConsole.WriteLine(o, 1, "text1"); } Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo("".ToLf())); }
public void CanResetConfiguration() { var capture = new ConsoleCapture(); var o = new object(); HConsole.Configure(o, config => config.SetMaxLevel(1)); using (capture.Output()) { HConsole.WriteLine(o, 1, "text1"); } Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo($"{Prefix()}text1\n".ToLf())); HConsole.Reset(); using (capture.Output()) { HConsole.WriteLine(o, 1, "text0"); } Assert.That(capture.ReadToEnd(), Is.EqualTo("")); }
public void WritesOtherLevelsIfConfigured() { var capture = new ConsoleCapture(); var o = new object(); HConsole.Configure(o, config => config.SetMaxLevel(1)); using (capture.Output()) { HConsole.WriteLine(o, "text0"); // default level is 0 HConsole.WriteLine(o, 1, "text1"); } Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo($"{Prefix()}text0\n{Prefix()}text1\n".ToLf())); }
public void WritesWithPrefix() { HConsole.Configure <object>(config => config.SetPrefix("XX")); var capture = new ConsoleCapture(); var o = new object(); HConsole.Configure(o, config => config.SetMaxLevel(0)); using (capture.Output()) { HConsole.WriteLine(o, "text0"); } Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo($"{Prefix("XX")}text0\n".ToLf())); }