Ejemplo n.º 1
0
        public void WriteTest()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.Write("Message", "Category");
            Trace.Flush();
            Assert.Equal("Category: Message", listener.Output);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void WriteObject1Test()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Add(listener);
            Trace.Write((Object)"Text");
            listener.Flush();
            Assert.Equal("Text", listener.Output);
        }
Ejemplo n.º 5
0
 public void FlushTest()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Clear();
     Trace.AutoFlush = false;
     Trace.Listeners.Add(listener);
     Trace.Write("Test");
     Assert.DoesNotContain("Test", listener.Output);
     Trace.Flush();
     Assert.Contains("Test", listener.Output);
 }
Ejemplo n.º 6
0
        public void FlushTest()
        {
            var listener = new TestTextTraceListener();

            Trace.Listeners.Clear();
            Trace.AutoFlush = false;
            Trace.Listeners.Add(listener);
            Trace.Write("Test");
            Assert.DoesNotContain("Test", listener.Output);
            Trace.Flush();
            Assert.Contains("Test", listener.Output);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void TraceEventTest2()
        {
            var cache    = new TraceEventCache();
            var listener = new TestTextTraceListener();

            listener.Filter = new TestTraceFilter(false);
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            Assert.Equal(0, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            var expected = 2; // header and message.

            Assert.Equal(expected, listener.WriteCount);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public void TraceDataTest()
        {
            var cache    = new TraceEventCache();
            var listener = new TestTextTraceListener();

            listener.Filter = new TestTraceFilter(false);
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, new Object());
            Assert.Equal(0, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, new Object());
            var expected = 2; // header and message.

            Assert.Equal(expected, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, (Object)null);
            Assert.Equal(expected, listener.WriteCount);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        public void TraceTest02()
        {
            string newLine = Environment.NewLine;
            var    textTL  = new TestTextTraceListener();

            Trace.Listeners.Clear();
            Trace.Listeners.Add(textTL);
            Trace.IndentLevel = 0;
            Trace.Fail("");
            textTL.Flush();
            var fail = textTL.Output.TrimEnd(newLine.ToCharArray());

            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();
            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);
        }
Ejemplo n.º 15
0
        public void WriteFooterTest(TraceOptions opts, int flagCount)
        {
            var cache = new TraceEventCache();
            var listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.Filter = new TestTraceFilter(false);
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1);
            Assert.Equal(0, listener.WriteCount);

            var baseExpected = 2; // header + message
            var expected = baseExpected;

            listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.TraceEvent(null, "Source", TraceEventType.Critical, 1);
            Assert.Equal(expected, listener.WriteCount);

            // Two calls to write per flag, one call for writing the indent, one for the message.
            expected = baseExpected + flagCount * 2;
            listener = new TestTextTraceListener();
            listener.TraceOutputOptions = opts;
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1);
            Assert.Equal(expected, listener.WriteCount);
        }
Ejemplo n.º 16
0
        public void TraceEventTest2()
        {
            var cache = new TraceEventCache();
            var listener = new TestTextTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            Assert.Equal(0, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceEvent(cache, "Source", TraceEventType.Critical, 1, "Format", "arg1");
            var expected = 2; // header and message.
            Assert.Equal(expected, listener.WriteCount);
        }
Ejemplo n.º 17
0
 public void WriteObject1Test()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Write((Object)"Text");
     listener.Flush();
     Assert.Equal("Text", listener.Output);
 }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
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);
 }
Ejemplo n.º 20
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);
 }
Ejemplo n.º 21
0
 public void WriteObject2Test()
 {
     var listener = new TestTextTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Write((Object)"Message", "Category");
     Trace.Flush();
     Assert.Equal("Category: Message", listener.Output);
 }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
        public void TraceDataTest2()
        {
            var cache = new TraceEventCache();
            var listener = new TestTextTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, new Object[0]);
            Assert.Equal(0, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, (Object[])null);
            var expected = 2; // header and message.
            Assert.Equal(expected, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, "Arg1", "Arg2");
            Assert.Equal(expected, listener.WriteCount);

            listener = new TestTextTraceListener();
            listener.TraceData(cache, "Source", TraceEventType.Critical, 1, "Arg1", null);
            Assert.Equal(expected, listener.WriteCount);
        }
Ejemplo n.º 24
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);
 }
Ejemplo n.º 25
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);
 }