Beispiel #1
0
        public void TraceTest02()
        {
            var textTL = new TestTextTraceListener();

            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.IndentSize  = 2;
            Trace.WriteLineIf(true, "Message start.");
            Trace.Indent();
            Trace.Indent();
            Trace.WriteIf(true, "This message should be indented.");
            Trace.WriteIf(false, "This message should be ignored.");
            Trace.Indent();
            Trace.WriteLine("This should not be indented.");
            Trace.WriteLineIf(false, "This message will be ignored");
            Trace.Fail("This failure is reported", "with a detailed message");
            Trace.Assert(false);
            Trace.Assert(false, "This assert is reported");
            Trace.Assert(true, "This assert is not reported");
            Trace.Unindent();
            Trace.Unindent();
            Trace.Unindent();
            Trace.WriteLine("Message end.");
            textTL.Flush();
            String newLine  = Environment.NewLine;
            var    expected = "Message start." + newLine + "    This message should be indented.This should not be indented." + newLine + "      Fail: This failure is reported with a detailed message" + newLine + "      Fail: " + newLine + "      Fail: This assert is reported" + newLine + "Message end." + newLine;

            Assert.Equal(expected, textTL.Output);
        }
Beispiel #2
0
        public void TraceTest02()
        {
            var textTL = new TestTextTraceListener();

            // We have to clear the listeners list on Trace since there is a trace listener by default with AssertUiEnabled = true in Desktop and that will pop up an assert window with Trace.Fail
            Trace.Listeners.Clear();
            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.IndentSize  = 2;
            Trace.WriteLineIf(true, "Message start.");
            Trace.Indent();
            Trace.Indent();
            Trace.WriteIf(true, "This message should be indented.");
            Trace.WriteIf(false, "This message should be ignored.");
            Trace.Indent();
            Trace.WriteLine("This should not be indented.");
            Trace.WriteLineIf(false, "This message will be ignored");
            Trace.Fail("This failure is reported", "with a detailed message");
            Trace.Assert(false);
            Trace.Assert(false, "This assert is reported");
            Trace.Assert(true, "This assert is not reported");
            Trace.Unindent();
            Trace.Unindent();
            Trace.Unindent();
            Trace.WriteLine("Message end.");
            textTL.Flush();
            String newLine  = Environment.NewLine;
            var    expected = "Message start." + newLine + "    This message should be indented.This should not be indented." + newLine + "      Fail: This failure is reported with a detailed message" + newLine + "      Fail: " + newLine + "      Fail: This assert is reported" + newLine + "Message end." + newLine;

            Assert.Equal(expected, textTL.Output);
        }
Beispiel #3
0
        public void WriteFooterTest_LogicalOperationStack()
        {
            for (int i = 0; i <= 3; i++)
            {
                int[] items = Enumerable.Range(42, i).ToArray();

                foreach (int item in items)
                {
                    Trace.CorrelationManager.LogicalOperationStack.Push(item.ToString());
                }

                try
                {
                    var cache    = new TraceEventCache();
                    var listener = new TestTextTraceListener()
                    {
                        TraceOutputOptions = TraceOptions.LogicalOperationStack
                    };
                    listener.TraceEvent(cache, "Source", TraceEventType.Critical, 42);
                    listener.Flush();

                    Assert.Contains("LogicalOperationStack=", listener.Output);
                    Assert.Contains(string.Join(", ", items.Reverse()), listener.Output);
                }
                finally
                {
                    foreach (int _ in items)
                    {
                        Trace.CorrelationManager.LogicalOperationStack.Pop();
                    }
                }
            }
        }
Beispiel #4
0
        public void TraceTest01()
        {
            var textTL = new TestTextTraceListener();

            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message start.");
            Trace.IndentSize  = 2;
            Trace.IndentLevel = 2;
            Trace.Write("This message should be indented.");
            Trace.TraceError("This error not be indented.");
            Trace.TraceError("{0}", "This error is indendented");
            Trace.TraceWarning("This warning is indented");
            Trace.TraceWarning("{0}", "This warning is also indented");
            Trace.TraceInformation("This information in indented");
            Trace.TraceInformation("{0}", "This information is also indented");
            Trace.IndentSize  = 0;
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message end.");
            textTL.Flush();
            String newLine  = Environment.NewLine;
            var    expected =
                String.Format(
                    "Message start." + newLine + "    This message should be indented.{0} Error: 0 : This error not be indented." + newLine + "    {0} Error: 0 : This error is indendented" + newLine + "    {0} Warning: 0 : This warning is indented" + newLine + "    {0} Warning: 0 : This warning is also indented" + newLine + "    {0} Information: 0 : This information in indented" + newLine + "    {0} Information: 0 : This information is also indented" + newLine + "Message end." + newLine + "",
                    "DEFAULT_APPNAME" //DEFAULT_APPNAME this a bug which needs to be fixed.
                    );

            Assert.Equal(expected, textTL.Output);
        }
Beispiel #5
0
        public void TraceTest01()
        {
            var textTL = new TestTextTraceListener();

            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message start.");
            Trace.IndentSize  = 2;
            Trace.IndentLevel = 2;
            Trace.Write("This message should be indented.");
            Trace.TraceError("This error not be indented.");
            Trace.TraceError("{0}", "This error is indented");
            Trace.TraceWarning("This warning is indented");
            Trace.TraceWarning("{0}", "This warning is also indented");
            Trace.TraceInformation("This information in indented");
            Trace.TraceInformation("{0}", "This information is also indented");
            Trace.IndentSize  = 0;
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message end.");
            textTL.Flush();
            string testRunnerAssemblyName = Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty;
            string newLine  = Environment.NewLine;
            var    expected =
                string.Format(
                    "Message start." + newLine + "    This message should be indented.{0} Error: 0 : This error not be indented." + newLine + "    {0} Error: 0 : This error is indented" + newLine + "    {0} Warning: 0 : This warning is indented" + newLine + "    {0} Warning: 0 : This warning is also indented" + newLine + "    {0} Information: 0 : This information in indented" + newLine + "    {0} Information: 0 : This information is also indented" + newLine + "Message end." + newLine + "",
                    testRunnerAssemblyName
                    );

            Assert.Equal(expected, textTL.Output);
        }
Beispiel #6
0
        public void WriteLine2Test()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.WriteLine((Object)"Message", "Category");
            listener.Flush();
            Assert.Equal("Category: Message" + Environment.NewLine, listener.Output);
        }
Beispiel #7
0
        public void WriteLineObjectTest()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.WriteLine((Object)"Text");
            listener.Flush();
            Assert.Equal("Text" + Environment.NewLine, listener.Output);
        }
Beispiel #8
0
        public void WriteObject1Test()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.Write((Object)"Text");
            listener.Flush();
            Assert.Equal("Text", listener.Output);
        }
Beispiel #9
0
        public void Assert2Test()
        {
            var listener = new TestTraceListener();
            var text     = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.Listeners.Add(text);
            Trace.Assert(true, "Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(0, listener.GetCallCount(Method.Fail));
            text.Flush();
            Assert.DoesNotContain("Message", text.Output);
            Trace.Assert(false, "Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(1, listener.GetCallCount(Method.Fail));
            text.Flush();
            Assert.Contains("Message", text.Output);
        }
Beispiel #10
0
        public void Assert2Test()
        {
            var listener = new TestTraceListener();
            var text     = new TestTextTraceListener();

            // We have to clear the listeners list on Trace since there is a trace listener by default with AssertUiEnabled = true in Desktop and that will pop up an assert window with Trace.Fail
            Trace.Listeners.Clear();
            Trace.Listeners.Add(listener);
            Trace.Listeners.Add(text);
            Trace.Assert(true, "Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(0, listener.GetCallCount(Method.Fail));
            text.Flush();
            Assert.DoesNotContain("Message", text.Output);
            Trace.Assert(false, "Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(1, listener.GetCallCount(Method.Fail));
            text.Flush();
            Assert.Contains("Message", text.Output);
        }
Beispiel #11
0
        public void WriteFooterTest_Timestamp()
        {
            var cache    = new TraceEventCache();
            var listener = new TestTextTraceListener()
            {
                TraceOutputOptions = TraceOptions.Timestamp
            };

            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 42);
            listener.Flush();

            Assert.Contains("Timestamp=", listener.Output);
            Assert.Contains(cache.Timestamp.ToString(), listener.Output);
        }
Beispiel #12
0
        public void WriteFooterTest_Callstack()
        {
            var cache    = new TraceEventCache();
            var listener = new TestTextTraceListener()
            {
                TraceOutputOptions = TraceOptions.Callstack
            };

            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 42);
            listener.Flush();

            Assert.Contains("Callstack=", listener.Output);
            Assert.Contains(nameof(WriteFooterTest_Callstack), listener.Output);
        }
Beispiel #13
0
        public void IndentTest()
        {
            var listener = new TestTextTraceListener();

            listener.IndentLevel = 2;
            listener.IndentSize  = 4;

            listener.Write("Message");
            listener.Flush();
            Assert.Equal("        Message", listener.Output);

            listener             = new TestTextTraceListener();
            listener.IndentLevel = 1;
            listener.IndentSize  = 3;

            listener.Write("Message");
            listener.Flush();
            Assert.Equal("   Message", listener.Output);
        }
Beispiel #14
0
        public void TraceTest01()
        {
            var textTL = new TestTextTraceListener();
            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message start.");
            Trace.IndentSize = 2;
            Trace.IndentLevel = 2;
            Trace.Write("This message should be indented.");
            Trace.TraceError("This error not be indented.");
            Trace.TraceError("{0}", "This error is indented");
            Trace.TraceWarning("This warning is indented");
            Trace.TraceWarning("{0}", "This warning is also indented");
            Trace.TraceInformation("This information in indented");
            Trace.TraceInformation("{0}", "This information is also indented");
            Trace.IndentSize = 0;
            Trace.IndentLevel = 0;
            Trace.WriteLine("Message end.");
            textTL.Flush();
            String newLine = Environment.NewLine;
            var expected =
                String.Format(
                    "Message start." + newLine + "    This message should be indented.{0} Error: 0 : This error not be indented." + newLine + "    {0} Error: 0 : This error is indented" + newLine + "    {0} Warning: 0 : This warning is indented" + newLine + "    {0} Warning: 0 : This warning is also indented" + newLine + "    {0} Information: 0 : This information in indented" + newLine + "    {0} Information: 0 : This information is also indented" + newLine + "Message end." + newLine + "",
                    TestRunnerAssemblyName
                );

            Assert.Equal(expected, textTL.Output);
        }
Beispiel #15
0
 public void WriteLine2Test()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.WriteLine((Object)"Message", "Category");
     listener.Flush();
     Assert.Equal("Category: Message" + Environment.NewLine, listener.Output);
 }
Beispiel #16
0
 public void WriteLineObjectTest()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.WriteLine((Object)"Text");
     listener.Flush();
     Assert.Equal("Text" + Environment.NewLine, listener.Output);
 }
Beispiel #17
0
 public void WriteObject1Test()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Write((Object)"Text");
     listener.Flush();
     Assert.Equal("Text", listener.Output);
 }
Beispiel #18
0
 public void Assert3Test()
 {
     var listener = new TestTraceListener();
     var text = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Listeners.Add(text);
     Trace.Assert(true, "Message", "Detail");
     Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
     Assert.Equal(0, listener.GetCallCount(Method.Fail));
     text.Flush();
     Assert.DoesNotContain("Message", text.Output);
     Trace.Assert(false, "Message", "Detail");
     Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
     Assert.Equal(1, listener.GetCallCount(Method.Fail));
     text.Flush();
     Assert.Contains("Message", text.Output);
     Assert.Contains("Detail", text.Output);
 }
Beispiel #19
0
 public void TraceTest02()
 {
     var textTL = new TestTextTraceListener();
     Trace.Listeners.Add(textTL);
     Trace.IndentLevel = 0;
     Trace.IndentSize = 2;
     Trace.WriteLineIf(true, "Message start.");
     Trace.Indent();
     Trace.Indent();
     Trace.WriteIf(true, "This message should be indented.");
     Trace.WriteIf(false, "This message should be ignored.");
     Trace.Indent();
     Trace.WriteLine("This should not be indented.");
     Trace.WriteLineIf(false, "This message will be ignored");
     Trace.Fail("This failure is reported", "with a detailed message");
     Trace.Assert(false);
     Trace.Assert(false, "This assert is reported");
     Trace.Assert(true, "This assert is not reported");
     Trace.Unindent();
     Trace.Unindent();
     Trace.Unindent();
     Trace.WriteLine("Message end.");
     textTL.Flush();
     String newLine = Environment.NewLine;
     var expected = "Message start." + newLine + "    This message should be indented.This should not be indented." + newLine + "      Fail: This failure is reported with a detailed message" + newLine + "      Fail: " + newLine + "      Fail: This assert is reported" + newLine + "Message end." + newLine;
     Assert.Equal(expected, textTL.Output);
 }
        public void IndentTest()
        {
            var listener = new TestTextTraceListener();
            listener.IndentLevel = 2;
            listener.IndentSize = 4;

            listener.Write("Message");
            listener.Flush();
            Assert.Equal("        Message", listener.Output);

            listener = new TestTextTraceListener();
            listener.IndentLevel = 1;
            listener.IndentSize = 3;

            listener.Write("Message");
            listener.Flush();
            Assert.Equal("   Message", listener.Output);
        }