Пример #1
0
        public void CreateController_Throws_And_Traces_When_Inner_Throws()
        {
            // Arrange
            Mock <HttpControllerDescriptor> mockControllerDescriptor = CreateMockControllerDescriptor();

            mockControllerDescriptor.Setup(b => b.CreateController(It.IsAny <HttpRequestMessage>())).Throws(_exception);
            TestTraceWriter traceWriter           = new TestTraceWriter();
            HttpControllerDescriptorTracer tracer = GetHttpControllerDescriptorTracer(mockControllerDescriptor.Object, traceWriter);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(_request, TraceCategories.ControllersCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.Begin, Operation = "CreateController"
                },
                new TraceRecord(_request, TraceCategories.ControllersCategory, TraceLevel.Error)
                {
                    Kind = TraceKind.End, Operation = "CreateController"
                }
            };

            // Act
            Exception thrown = Assert.Throws <InvalidOperationException>(() => tracer.CreateController(_request));

            // Assert
            Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(_exception, thrown);
            Assert.Same(_exception, traceWriter.Traces[1].Exception);
        }
Пример #2
0
        public void CreateController_Invokes_Inner_And_Traces()
        {
            // Arrange
            Mock <HttpControllerDescriptor> mockControllerDescriptor = CreateMockControllerDescriptor();

            mockControllerDescriptor.Setup(b => b.CreateController(It.IsAny <HttpRequestMessage>())).Returns(_controller);
            TestTraceWriter traceWriter           = new TestTraceWriter();
            HttpControllerDescriptorTracer tracer = GetHttpControllerDescriptorTracer(mockControllerDescriptor.Object, traceWriter);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(_request, TraceCategories.ControllersCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.Begin, Operation = "CreateController"
                },
                new TraceRecord(_request, TraceCategories.ControllersCategory, TraceLevel.Info)
                {
                    Kind = TraceKind.End, Operation = "CreateController"
                }
            };

            // Act
            IHttpController controller = tracer.CreateController(_request);

            // Assert
            Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.IsAssignableFrom <HttpControllerTracer>(controller);
        }