Inheritance: TraceListener
 public void IndentSizeTest()
 {
     var listener = new TestTraceListener();
     listener.IndentSize = 0;
     Assert.Equal(0, listener.IndentSize);
     listener.IndentSize = 2;
     Assert.Equal(2, listener.IndentSize);
     Assert.Throws<ArgumentOutOfRangeException>(() => listener.IndentSize = -1);
 }
 public void IndentLevelTest()
 {
     var listener = new TestTraceListener();
     listener.IndentLevel = 0;
     Assert.Equal(0, listener.IndentLevel);
     listener.IndentLevel = 2;
     Assert.Equal(2, listener.IndentLevel);
     listener.IndentLevel = -1;
     Assert.Equal(0, listener.IndentLevel);
 }
Example #3
0
 public void TraceInformationTest()
 {
     var trace = new TraceSource("TestTraceSource", SourceLevels.All);
     var listener = new TestTraceListener();
     trace.Listeners.Add(listener);
     trace.TraceInformation("message");
     Assert.Equal(0, listener.GetCallCount(Method.TraceData));
     Assert.Equal(0, listener.GetCallCount(Method.Write));
     Assert.Equal(1, listener.GetCallCount(Method.TraceEvent));
     trace.TraceInformation("format", "arg1", "arg2");
     Assert.Equal(2, listener.GetCallCount(Method.TraceEvent));
 }
Example #4
0
        public void CloseTest()
        {
            var trace = new TraceSource("T1", SourceLevels.All);
            trace.Listeners.Clear();

            var listener = new TestTraceListener();
            trace.Listeners.Add(listener);
            trace.Close();
            // NOTE: this assertion fails on .net 4.5
            // where TraceSource.Close calls TraceListener.Close, not Dispose.
            Assert.Equal(1, listener.GetCallCount(Method.Dispose));
            // Assert that writing to a closed TraceSource is not an error.
            trace.TraceEvent(TraceEventType.Critical, 0);
        }
Example #5
0
        public void CloseTest()
        {
            var trace = new TraceSource("T1", SourceLevels.All);

            trace.Listeners.Clear();

            var listener = new TestTraceListener();

            trace.Listeners.Add(listener);
            trace.Close();
            Assert.Equal(1, listener.GetCallCount(Method.Close));
            // Assert that writing to a closed TraceSource is not an error.
            trace.TraceEvent(TraceEventType.Critical, 0);
        }
Example #6
0
        public void Assert1Test()
        {
            var listener = new TestTraceListener();

            // 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.Assert(true);
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(0, listener.GetCallCount(Method.Fail));
            Trace.Assert(false);
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
            Assert.Equal(1, listener.GetCallCount(Method.Fail));
        }
        public void WriteObjectTest()
        {
            var listener = new TestTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.Write((Object)"Message");
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Filter = new TestTraceFilter(true);

            listener.Write((Object)null);
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Write((Object)"Message");
            Assert.Equal(1, listener.GetCallCount(Method.Write));
        }
Example #8
0
        public void Close()
        {
            var trace = new TraceSource("T1", SourceLevels.All);

            trace.Listeners.Clear();

            var listener = new TestTraceListener();

            trace.Listeners.Add(listener);
            trace.Close();
            // NOTE: this assertion fails on .net 4.5
            // where TraceSource.Close calls TraceListener.Close, not Dispose.
            Assert.Equal(1, listener.GetCallCount(Method.Dispose));
            // Assert that writing to a closed TraceSource is not an error.
            trace.TraceEvent(TraceEventType.Critical, 0);
        }
Example #9
0
        public void WriteObjectTest()
        {
            var listener = new TestTraceListener();

            listener.Filter = new TestTraceFilter(false);
            listener.Write((Object)"Message");
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Filter = new TestTraceFilter(true);

            listener.Write((Object)null);
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Write((Object)"Message");
            Assert.Equal(1, listener.GetCallCount(Method.Write));
        }
        public void TraceOutputOptionsTest()
        {
            var listener = new TestTraceListener();
            listener.TraceOutputOptions = TraceOptions.None;

            // NOTE: TraceOptions includes values for 0x01 and 0x20 in .Net 4.5, but not in CoreFX
            // These assertions test for thos missing values, and the exceptional contidion that
            // maintains compatibility with 4.5
            var missingValue = (TraceOptions)0x01;
            listener.TraceOutputOptions = missingValue;

            missingValue = (TraceOptions)0x20;
            listener.TraceOutputOptions = missingValue;

            var badValue = (TraceOptions)0x80;
            Assert.Throws<ArgumentOutOfRangeException>(() => listener.TraceOutputOptions = badValue);
        }
Example #11
0
        public void WriteLineObjectTest()
        {
            var listener = new TestTraceListener();

            listener.Filter = new TestTraceFilter(false);
            listener.WriteLine((Object)"Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));

            listener.Filter = new TestTraceFilter(true);

            // NOTE: Writing null will result in a newline being written
            listener.WriteLine((Object)null);
            Assert.Equal(1, listener.GetCallCount(Method.WriteLine));

            listener.WriteLine((Object)"Message");
            Assert.Equal(2, listener.GetCallCount(Method.WriteLine));
        }
Example #12
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);
        }
Example #13
0
        public void WriteCategoryTest()
        {
            var listener = new TestTraceListener();

            listener.Filter = new TestTraceFilter(false);
            listener.Write("Message", "Category");
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Filter = new TestTraceFilter(true);

            listener.Write("Message", null);
            Assert.Equal(1, listener.GetCallCount(Method.Write));

            listener.Write("Message", "Category");
            Assert.Equal(2, listener.GetCallCount(Method.Write));

            listener.Write(null, "Category");
            Assert.Equal(3, listener.GetCallCount(Method.Write));
        }
Example #14
0
        public void TraceOutputOptionsTest()
        {
            var listener = new TestTraceListener();

            listener.TraceOutputOptions = TraceOptions.None;

            // NOTE: TraceOptions includes values for 0x01 and 0x20 in .Net 4.5, but not in CoreFX
            // These assertions test for those missing values, and the exceptional condition that
            // maintains compatibility with 4.5
            var missingValue = (TraceOptions)0x01;

            listener.TraceOutputOptions = missingValue;

            missingValue = (TraceOptions)0x20;
            listener.TraceOutputOptions = missingValue;

            var badValue = (TraceOptions)0x80;

            Assert.Throws <ArgumentOutOfRangeException>(() => listener.TraceOutputOptions = badValue);
        }
Example #15
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);
        }
Example #16
0
        public void TraceOutputOptionsTest_Invalid(TraceOptions options)
        {
            var listener = new TestTraceListener();

            Assert.Throws <ArgumentOutOfRangeException>(() => listener.TraceOutputOptions = options);
        }
Example #17
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);
 }
Example #18
0
 public void WriteIf1Test()
 {
     var listener = new TestTraceListener();
     Trace.Listeners.Add(listener);
     Trace.WriteIf(false, (Object)"Message");
     Assert.Equal(0, listener.GetCallCount(Method.Write));
     Trace.WriteIf(true, (Object)"Message");
     Assert.Equal(1, listener.GetCallCount(Method.Write));
 }
Example #19
0
 public void FailTest()
 {
     var listener = new TestTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Fail("Text");
     Assert.Equal(1, listener.GetCallCount(Method.Fail));
     Trace.Fail("Text", "Detail");
     Assert.Equal(2, listener.GetCallCount(Method.Fail));
 }
Example #20
0
 public void WriteLineIf4Test()
 {
     var listener = new TestTraceListener();
     Trace.Listeners.Add(listener);
     Trace.WriteLineIf(false, "Message", "Category");
     Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
     Trace.WriteLineIf(true, "Message", "Category");
     Assert.Equal(1, listener.GetCallCount(Method.WriteLine));
 }
Example #21
0
 public void CloseTest()
 {
     var listener = new TestTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Close();
     Assert.Equal(1, listener.GetCallCount(Method.Dispose));
 }
        public void WriteCategoryTest()
        {
            var listener = new TestTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.Write("Message", "Category");
            Assert.Equal(0, listener.GetCallCount(Method.Write));

            listener.Filter = new TestTraceFilter(true);

            listener.Write("Message", null);
            Assert.Equal(1, listener.GetCallCount(Method.Write));

            listener.Write("Message", "Category");
            Assert.Equal(2, listener.GetCallCount(Method.Write));

            listener.Write(null, "Category");
            Assert.Equal(3, listener.GetCallCount(Method.Write));
        }
Example #23
0
 public void SwitchLevelTest(SourceLevels sourceLevel, TraceEventType messageLevel, int expected)
 {
     var trace = new TraceSource("TestTraceSource");
     var listener = new TestTraceListener();
     trace.Listeners.Add(listener);
     trace.Switch.Level = sourceLevel;
     trace.TraceEvent(messageLevel, 0);
     Assert.Equal(expected, listener.GetCallCount(Method.TraceEvent));
 }
 public void FilterTest()
 {
     var listener = new TestTraceListener();
     listener.Filter = new SourceFilter("TestSource");
     Assert.NotNull(listener.Filter);
 }
 public void NameTest()
 {
     var listener = new TestTraceListener();
     listener.Name = null;
     Assert.Equal("", listener.Name);
 }
Example #26
0
 public void Assert1Test()
 {
     var listener = new TestTraceListener();
     Trace.Listeners.Add(listener);
     Trace.Assert(true);
     Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
     Assert.Equal(0, listener.GetCallCount(Method.Fail));
     Trace.Assert(false);
     Assert.Equal(0, listener.GetCallCount(Method.WriteLine));
     Assert.Equal(1, listener.GetCallCount(Method.Fail));
 }
        public void WriteLineObjectTest()
        {
            var listener = new TestTraceListener();
            listener.Filter = new TestTraceFilter(false);
            listener.WriteLine((Object)"Message");
            Assert.Equal(0, listener.GetCallCount(Method.WriteLine));

            listener.Filter = new TestTraceFilter(true);

            // NOTE: Writing null will result in a newline being written
            listener.WriteLine((Object)null);
            Assert.Equal(1, listener.GetCallCount(Method.WriteLine));

            listener.WriteLine((Object)"Message");
            Assert.Equal(2, listener.GetCallCount(Method.WriteLine));
        }