当前位置: 首页>>代码示例>>C#>>正文


C# Tracing.TestTraceWriter类代码示例

本文整理汇总了C#中System.Web.Http.Tracing.TestTraceWriter的典型用法代码示例。如果您正苦于以下问题:C# TestTraceWriter类的具体用法?C# TestTraceWriter怎么用?C# TestTraceWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TestTraceWriter类属于System.Web.Http.Tracing命名空间,在下文中一共展示了TestTraceWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Info_With_Message_Traces

        public void Info_With_Message_Traces()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, "testCategory", TraceLevel.Info) { Kind = TraceKind.Trace, Message = "The formatted message" },
            };

            // Act
            traceWriter.Info(request, "testCategory", "The {0} message", "formatted");

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:16,代码来源:ITraceWriterExtensionsTest.cs

示例2: Debug_With_Message_And_Exception_Traces

        public void Debug_With_Message_And_Exception_Traces()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            InvalidOperationException exception = new InvalidOperationException();
            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, "testCategory", TraceLevel.Debug) { Kind = TraceKind.Trace, Message = "The formatted message", Exception = exception },
            };

            // Act
            traceWriter.Debug(request, "testCategory", exception, "The {0} message", "formatted");

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:17,代码来源:ITraceWriterExtensionsTest.cs

示例3: TraceBeginEnd_Invokes_ErrorTrace_When_Tracing_Only_Errors

        public void TraceBeginEnd_Invokes_ErrorTrace_When_Tracing_Only_Errors()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            traceWriter.TraceSelector = (rqst, category, level) => level >= TraceLevel.Error;
            HttpRequestMessage request = new HttpRequestMessage();
            Exception exception = new InvalidOperationException();
            bool invoked = false;

            // Act
            Exception thrown = Assert.Throws<InvalidOperationException>(
                    () => traceWriter.TraceBeginEnd(request,
                                 "",
                                 TraceLevel.Off,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => { throw exception; },
                                 endTrace: (tr) => { },
                                 errorTrace: (tr) => { invoked = true; }));

            // Assert
            Assert.True(invoked);
            Assert.Same(exception, thrown);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:25,代码来源:ITraceWriterExtensionsTest.cs

示例4: TraceBeginEnd_Does_Not_Invoke_ErrorTrace_Unless_Error_Occurs

        public void TraceBeginEnd_Does_Not_Invoke_ErrorTrace_Unless_Error_Occurs()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;

            // Act
            traceWriter.TraceBeginEnd(request,
                                 "",
                                 TraceLevel.Info,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => { },
                                 endTrace: (tr) => { },
                                 errorTrace: (tr) => { invoked = true; });

            // Assert
            Assert.False(invoked);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:21,代码来源:ITraceWriterExtensionsTest.cs

示例5: TraceBeginEndAsync_Traces

        public void TraceBeginEndAsync_Traces()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(request, "testCategory", TraceLevel.Info) { Kind = TraceKind.Begin, Operator = "tester", Operation = "testOp", Message = "beginMessage" },
                new TraceRecord(request, "testCategory", TraceLevel.Info) { Kind = TraceKind.End, Operator = "tester", Operation = "testOp", Message = "endMessage" },
            };

            // Act
            traceWriter.TraceBeginEndAsync(request,
                                 "testCategory",
                                 TraceLevel.Info,
                                 "tester",
                                 "testOp",
                                 beginTrace: (tr) => { tr.Message = "beginMessage"; },
                                 execute: () => TaskHelpers.Completed(),
                                 endTrace: (tr) => { tr.Message = "endMessage"; },
                                 errorTrace: (tr) => { tr.Message = "won't happen"; }).Wait();

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:25,代码来源:ITraceWriterExtensionsTest.cs

示例6: TraceBeginEndAsyncGeneric_Does_Not_Invoke_ErrorTrace_When_Tracing_Only_Higher_Level

        public void TraceBeginEndAsyncGeneric_Does_Not_Invoke_ErrorTrace_When_Tracing_Only_Higher_Level()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            traceWriter.TraceSelector = (rqst, category, level) => level >= TraceLevel.Fatal;
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;
            Exception exception = new InvalidOperationException();
            TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(0);
            tcs.TrySetException(exception);

            // Act & Assert
            Exception thrown = Assert.Throws<InvalidOperationException>(
                () => traceWriter.TraceBeginEndAsync<int>(request,
                                 "",
                                 TraceLevel.Info,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => tcs.Task,
                                 endTrace: (tr, value) => { },
                                 errorTrace: (tr) => { invoked = true; }).Wait());
            Assert.False(invoked);
            Assert.Same(exception, thrown);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:25,代码来源:ITraceWriterExtensionsTest.cs

示例7: TraceBeginEndAsync_Does_Not_Invoke_EndTrace_When_Tracing_Only_Higher_Level

        public void TraceBeginEndAsync_Does_Not_Invoke_EndTrace_When_Tracing_Only_Higher_Level()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            traceWriter.TraceSelector = (rqst, category, level) => level >= TraceLevel.Error;
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;

            // Act
            traceWriter.TraceBeginEndAsync(request,
                                 "",
                                 TraceLevel.Info,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => TaskHelpers.Completed(),
                                 endTrace: (tr) => { invoked = true; },
                                 errorTrace: (tr) => { }).Wait();

            // Assert
            Assert.False(invoked);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:22,代码来源:ITraceWriterExtensionsTest.cs

示例8: TraceBeginEndAsync_Invokes_ErrorTrace_When_Tracing_Only_Errors

        public void TraceBeginEndAsync_Invokes_ErrorTrace_When_Tracing_Only_Errors()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            traceWriter.TraceSelector = (rqst, category, level) => level >= TraceLevel.Error;
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;
            Exception exception = new InvalidOperationException();
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>(null);
            tcs.TrySetException(exception);

            // Act
            Exception thrown = Assert.Throws<InvalidOperationException>(
                        () => traceWriter.TraceBeginEndAsync(request,
                                 "",
                                 TraceLevel.Info,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => tcs.Task,
                                 endTrace: (tr) => { },
                                 errorTrace: (tr) => { invoked = true; }).Wait());

            // Assert
            Assert.True(invoked);
            Assert.Same(exception, thrown);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:27,代码来源:ITraceWriterExtensionsTest.cs

示例9: TraceBeginEndAsync_Throws_With_Null_Execute_Action

        public void TraceBeginEndAsync_Throws_With_Null_Execute_Action()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => traceWriter.TraceBeginEndAsync(request,
                                             "",
                                             TraceLevel.Off,
                                             "",
                                             "",
                                             beginTrace: null,
                                             execute: null,
                                             endTrace: null,
                                             errorTrace: null),
                                       "execute");
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:18,代码来源:ITraceWriterExtensionsTest.cs

示例10: TraceBeginEnd_Traces_And_Throws_AggregateException

        public void TraceBeginEnd_Traces_And_Throws_AggregateException()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            List<TraceRecord> expectedTraces = new List<TraceRecord>
            {
                new TraceRecord(request, "testCategory", TraceLevel.Error) { Kind = TraceKind.Begin, Operator = "tester", Operation = "testOp", Message = "beginMessage" },
                new TraceRecord(request, "testCategory", TraceLevel.Warn)
                { 
                    Kind = TraceKind.End, Operator = "tester", Operation = "testOp", Exception = null,
                    // In the aggregateException, only the httpResponseException with the highest status code will be reflected in the trace record's message.
                    // In this test case, it should be NotFound.
                    Message = "UserMessage='The request is invalid.', ModelStateError=[key=[error], username=[invalid]]",
                    Status = Net.HttpStatusCode.NotFound
                },
            };

            // Act
            // Errors and exceptions are instantiated in the `execute` func to avoid the variation of error messages for culture issues.
            Exception thrown = Assert.Throws<AggregateException>(
                                () => traceWriter.TraceBeginEnd(request,
                                    "testCategory",
                                    TraceLevel.Error,
                                    "tester",
                                    "testOp",
                                    beginTrace: (tr) => { tr.Message = "beginMessage"; },
                                    execute: () =>
                                    {
                                        AggregateException aggEx = CreateAggregateException(request);
                                        // To satisfy TraceRecordComparer().
                                        expectedTraces[1].Exception = aggEx;
                                        throw aggEx;
                                    },
                                    endTrace: (tr) => { tr.Message = "won't Happen"; },
                                    errorTrace: null));

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(thrown, expectedTraces[1].Exception);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:41,代码来源:ITraceWriterExtensionsTest.cs

示例11: TraceBeginEndAsyncGeneric_Invokes_EndTrace

        public void TraceBeginEndAsyncGeneric_Invokes_EndTrace()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;
            int invokedValue = 0;

            // Act
            traceWriter.TraceBeginEndAsync<int>(request,
                                 "",
                                 TraceLevel.Off,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => TaskHelpers.FromResult<int>(1),
                                 endTrace: (tr, value) => { invoked = true; invokedValue = value; },
                                 errorTrace: (tr) => { }).Wait();

            // Assert
            Assert.True(invoked);
            Assert.Equal(1, invokedValue);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:23,代码来源:ITraceWriterExtensionsTest.cs

示例12: TraceBeginEndAsyncGeneric_Invokes_ErrorTrace

        public void TraceBeginEndAsyncGeneric_Invokes_ErrorTrace()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;
            Exception exception = new InvalidOperationException();
            TaskCompletionSource<int> tcs = new TaskCompletionSource<int>(0);
            tcs.TrySetException(exception);

            // Act
            Exception thrown = Assert.Throws<InvalidOperationException>(
                () => traceWriter.TraceBeginEndAsync<int>(request,
                                 "",
                                 TraceLevel.Off,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () => tcs.Task,
                                 endTrace: (tr, value) => { },
                                 errorTrace: (tr) => { invoked = true; }).Wait());

            // Assert
            Assert.True(invoked);
            Assert.Same(exception, thrown);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:26,代码来源:ITraceWriterExtensionsTest.cs

示例13: TraceBeginEndAsyncGeneric_Invokes_Execute

        public void TraceBeginEndAsyncGeneric_Invokes_Execute()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;

            // Act
            int result = traceWriter.TraceBeginEndAsync<int>(request,
                                 "",
                                 TraceLevel.Fatal,
                                 "",
                                 "",
                                 beginTrace: (tr) => { },
                                 execute: () =>
                                 {
                                     invoked = true;
                                     return TaskHelpers.FromResult<int>(1);
                                 },
                                 endTrace: (tr, value) => { },
                                 errorTrace: (tr) => { }).Result;

            // Assert
            Assert.True(invoked);
            Assert.Equal(1, result);
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:26,代码来源:ITraceWriterExtensionsTest.cs

示例14: TraceBeginEndAsync_Does_Not_Trace_HttpResponseException_When_Tracing_Only_Higher_Level

        public void TraceBeginEndAsync_Does_Not_Trace_HttpResponseException_When_Tracing_Only_Higher_Level()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            traceWriter.TraceSelector = (rqst, category, level) => level >= TraceLevel.Error;
            HttpRequestMessage request = new HttpRequestMessage();
            bool invoked = false;
            Exception exception = new HttpResponseException(Net.HttpStatusCode.NotFound);

            // Act
            Exception thrown = Assert.Throws<HttpResponseException>(
                                () => traceWriter.TraceBeginEndAsync(request,
                                "",
                                TraceLevel.Info,
                                "",
                                "",
                                beginTrace: (tr) => { invoked = true; },
                                execute: () => TaskHelpers.FromError(exception),
                                endTrace: (tr) => { },
                                errorTrace: (tr) => { }).Wait());

            // Assert
            Assert.False(invoked);
            Assert.Empty(traceWriter.Traces);
            Assert.Same(thrown, exception);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:26,代码来源:ITraceWriterExtensionsTest.cs

示例15: TraceBeginEndAsync_Traces_And_Throws_HttpResponseException

        public void TraceBeginEndAsync_Traces_And_Throws_HttpResponseException()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpRequestMessage request = new HttpRequestMessage();
            HttpResponseException exception = new HttpResponseException(Net.HttpStatusCode.InternalServerError);
            List<TraceRecord> expectedTraces = new List<TraceRecord>
            {
                new TraceRecord(request, "testCategory", TraceLevel.Info) { Kind = TraceKind.Begin, Operator = "tester", Operation = "testOp", Message = "beginMessage" },
                new TraceRecord(request, "testCategory", TraceLevel.Error) { Kind = TraceKind.End, Operator = "tester", Operation = "testOp", Exception = exception, Message = "errorMessage",
                    Status = Net.HttpStatusCode.InternalServerError },
            };

            // Act
            Exception thrown = Assert.Throws<HttpResponseException>(
                                () => traceWriter.TraceBeginEndAsync(request,
                                    "testCategory",
                                    TraceLevel.Info,
                                    "tester",
                                    "testOp",
                                    beginTrace: (tr) => { tr.Message = "beginMessage"; },
                                    execute: () => { throw exception; },
                                    endTrace: (tr) => { tr.Message = "won't Happen"; },
                                    errorTrace: (tr) => { tr.Message = "errorMessage"; }).Wait());

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(thrown, exception);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:29,代码来源:ITraceWriterExtensionsTest.cs


注:本文中的System.Web.Http.Tracing.TestTraceWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。