public void FormatHttpRequestUrlTest()
        {
            var mockHttpTraceContext = new MockHttpTraceContext();

            mockHttpTraceContext.RequestUrl = new Uri("http://test/x");
            var traceFormatter = new TraceFormatter();

            traceFormatter.HttpTraceContext = mockHttpTraceContext;
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "|{RequestUrl}|";
            string   expected = "|http://test/x|";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatIdAndMessageTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{Id}.{Message}";
            string expected = "5.fnord";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatProcessIdTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{ProcessId}";
            string   expected = Process.GetCurrentProcess().Id.ToString();

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatMessagePrefixSentinel()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceEventCache eventCache        = null;
            TraceListener   listener          = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 0;
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "<{MessagePrefix}>";
            string   message  = "Something to say. the rest of the trace.";
            string   expected = "<Something to say>";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatIdAndMessageTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{Id}.{Message}";
            string   expected = "5.fnord";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatEmptyHttpContextTest()
        {
            // The default is HttpContext.Current, which should be empty when running unit test
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "|{RequestUrl}|";
            string expected = "||";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatEmptyHttpContextTest()
        {
            // The default is HttpContext.Current, which should be empty when running unit test
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "|{RequestUrl}|";
            string   expected = "||";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatHttpRequestUrlTest()
        {
            var mockHttpTraceContext  =new MockHttpTraceContext();
            mockHttpTraceContext.RequestUrl = new Uri("http://test/x");
            var traceFormatter = new TraceFormatter();
            traceFormatter.HttpTraceContext = mockHttpTraceContext;
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "|{RequestUrl}|";
            string expected = "|http://test/x|";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatPrincipalNameTest()
        {
            var             traceFormatter    = new TraceFormatter();
            TraceListener   listener          = null;
            TraceEventCache eventCache        = null;
            string          source            = "test";
            TraceEventType  eventType         = TraceEventType.Warning;
            int             id                = 5;
            string          message           = "fnord";
            Guid?           relatedActivityId = null;

            object[] data     = null;
            string   template = "{Id}.{PrincipalName}";
            string   expected = "5.testuser";
            string   actual   = null;

            using (var scope = new UserResetScope("testuser"))
            {
                actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                                               message, relatedActivityId, data);
            }

            Assert.AreEqual(expected, actual);
        }
        public void FormatMessagePrefixAll()
        {
            var traceFormatter = new TraceFormatter();
            TraceEventCache eventCache = null;
            TraceListener listener = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 0;
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "<{MessagePrefix}>";
            string message = "Something to say";

            string expected = "<Something to say>";

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatProcessIdTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{ProcessId}";
            string expected = Process.GetCurrentProcess().Id.ToString();

            var actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);

            Assert.AreEqual(expected, actual);
        }
        public void FormatPrincipalNameTest()
        {
            var traceFormatter = new TraceFormatter();
            TraceListener listener = null;
            TraceEventCache eventCache = null;
            string source = "test";
            TraceEventType eventType = TraceEventType.Warning;
            int id = 5;
            string message = "fnord";
            Guid? relatedActivityId = null;
            object[] data = null;
            string template = "{Id}.{PrincipalName}";
            string expected = "5.testuser";
            string actual = null;

            using (var scope = new UserResetScope("testuser"))
            {
                actual = traceFormatter.Format(template, listener, eventCache, source, eventType, id,
                    message, relatedActivityId, data);
            }

            Assert.AreEqual(expected, actual);
        }
示例#13
0
 public override string ToString()
 {
     return(TraceFormatter.Format(error, data));
 }