Пример #1
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();
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
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);
        }