예제 #1
0
        public void SelectController_Throws_And_Traces_When_Inner_Throws()
        {
            // Arrange
            Mock <IHttpControllerSelector> mockSelector = new Mock <IHttpControllerSelector>();
            InvalidOperationException      exception    = new InvalidOperationException("test");

            mockSelector.Setup(b => b.SelectController(It.IsAny <HttpRequestMessage>())).Throws(exception);
            TestTraceWriter traceWriter         = new TestTraceWriter();
            HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(mockSelector.Object, traceWriter);

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

            // Act
            Exception thrown = Assert.Throws <InvalidOperationException>(() => ((IHttpControllerSelector)tracer).SelectController(_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 SelectController_Invokes_Inner_And_Traces()
        {
            // Arrange
            Mock <HttpControllerDescriptor> mockControllerDescriptor = new Mock <HttpControllerDescriptor>(_controllerContext.Configuration, "AnyController", _controller.GetType());
            Mock <IHttpControllerSelector>  mockSelector             = new Mock <IHttpControllerSelector>();

            mockSelector.Setup(b => b.SelectController(It.IsAny <HttpRequestMessage>())).Returns(mockControllerDescriptor.Object);
            TestTraceWriter traceWriter         = new TestTraceWriter();
            HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(mockSelector.Object, traceWriter);

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

            // Act
            HttpControllerDescriptor controllerDescriptor = ((IHttpControllerSelector)tracer).SelectController(_request);

            // Assert
            Assert.Equal <TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.IsAssignableFrom <HttpControllerDescriptorTracer>(controllerDescriptor);
        }
        public void Decorator_GetInner_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
        {
            // Arrange
            IHttpControllerSelector expectedInner = new Mock<IHttpControllerSelector>().Object;
            HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());

            // Act
            IHttpControllerSelector actualInner = Decorator.GetInner(productUnderTest as IHttpControllerSelector);

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
        public void Inner_Property_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
        {
            // Arrange
            IHttpControllerSelector expectedInner = new Mock<IHttpControllerSelector>().Object;
            HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());

            // Act
            IHttpControllerSelector actualInner = productUnderTest.Inner;

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
예제 #5
0
        public void Decorator_GetInner_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
        {
            // Arrange
            IHttpControllerSelector      expectedInner    = new Mock <IHttpControllerSelector>().Object;
            HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());

            // Act
            IHttpControllerSelector actualInner = Decorator.GetInner(productUnderTest as IHttpControllerSelector);

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
예제 #6
0
        public void Inner_Property_On_HttpControllerSelectorTracer_Returns_IHttpControllerSelector()
        {
            // Arrange
            IHttpControllerSelector      expectedInner    = new Mock <IHttpControllerSelector>().Object;
            HttpControllerSelectorTracer productUnderTest = new HttpControllerSelectorTracer(expectedInner, new TestTraceWriter());

            // Act
            IHttpControllerSelector actualInner = productUnderTest.Inner;

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
        public void SelectController_Invokes_Inner_And_Traces()
        {
            // Arrange
            Mock<HttpControllerDescriptor> mockControllerDescriptor = new Mock<HttpControllerDescriptor>(_controllerContext.Configuration, "AnyController", _controller.GetType());
            Mock<IHttpControllerSelector> mockSelector = new Mock<IHttpControllerSelector>();
            mockSelector.Setup(b => b.SelectController(It.IsAny<HttpRequestMessage>())).Returns(mockControllerDescriptor.Object);
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(mockSelector.Object, traceWriter);

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

            // Act
            HttpControllerDescriptor controllerDescriptor = ((IHttpControllerSelector)tracer).SelectController(_request);

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.IsAssignableFrom<HttpControllerDescriptorTracer>(controllerDescriptor);
        }
        public void SelectController_Throws_And_Traces_When_Inner_Throws()
        {
            // Arrange
            Mock<IHttpControllerSelector> mockSelector = new Mock<IHttpControllerSelector>();
            InvalidOperationException exception = new InvalidOperationException("test");
            mockSelector.Setup(b => b.SelectController(It.IsAny<HttpRequestMessage>())).Throws(exception);
            TestTraceWriter traceWriter = new TestTraceWriter();
            HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(mockSelector.Object, traceWriter);

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

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

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(exception, thrown);
            Assert.Same(exception, traceWriter.Traces[1].Exception);
        }
예제 #9
0
 private static void CreateControllerSelectorTracer(HttpConfiguration configuration, ITraceWriter traceWriter)
 {
     IHttpControllerSelector controllerSelector = configuration.ServiceResolver.GetService(typeof(IHttpControllerSelector)) as IHttpControllerSelector;
     HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(controllerSelector, traceWriter);
     configuration.ServiceResolver.SetService(typeof(IHttpControllerSelector), tracer);
 }
 private static void CreateControllerSelectorTracer(HttpConfiguration configuration, ITraceWriter traceWriter)
 {
     IHttpControllerSelector controllerSelector = configuration.Services.GetHttpControllerSelector();
     HttpControllerSelectorTracer tracer = new HttpControllerSelectorTracer(controllerSelector, traceWriter);
     configuration.Services.Replace(typeof(IHttpControllerSelector), tracer);
 }