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());
        }
Example #3
0
        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));
        }
Example #4
0
        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());
        }
Example #5
0
            public void TestDisplayedWhenHelpArgument(string helpArg)
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(new[] { helpArg });

                    Assert.AreEqual(0, code);
                    Assert.AreEqual("", consoleCap.Error());
                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }
Example #6
0
            public void TestHelpTrumpsOtherArguments()
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(
                        new[] { "load", "doesnt-exist.aasx", "help" });

                    Assert.AreEqual(0, code);
                    Assert.AreEqual("", consoleCap.Error());
                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }
        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()));
        }
Example #11
0
            public void TestDisplayedWhenHelpArgument(string helpArg)
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(new[] { helpArg });

                    if (consoleCap.Error() != "")
                    {
                        throw new AssertionException(
                                  $"Expected no stderr, but got:{System.Environment.NewLine}" +
                                  consoleCap.Error());
                    }

                    Assert.AreEqual(0, code);

                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }
Example #12
0
            public void TestHelpTrumpsOtherArguments()
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(
                        new[] { "load", "doesnt-exist.aasx", "help" });

                    if (consoleCap.Error() != "")
                    {
                        throw new AssertionException(
                                  $"Expected no stderr, but got:{System.Environment.NewLine}" +
                                  consoleCap.Error());
                    }

                    Assert.AreEqual(0, code);

                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }