public void SelectAction_DoesNotWrapHttpActionDescriptorTracer()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            Mock<IHttpActionSelector> mockSelector = new Mock<IHttpActionSelector>();

            HttpActionDescriptorTracer actionDescriptorTracer = new HttpActionDescriptorTracer(_controllerContext, _mockActionDescriptor.Object, traceWriter);
            mockSelector.Setup(s => s.SelectAction(_controllerContext)).Returns(actionDescriptorTracer);
            HttpActionSelectorTracer tracer = new HttpActionSelectorTracer(mockSelector.Object, traceWriter);

            // Act
            HttpActionDescriptor selectedActionDescriptor = ((IHttpActionSelector)tracer).SelectAction(_controllerContext);

            // Assert
            Assert.Same(actionDescriptorTracer, selectedActionDescriptor);
        }
        public void SelectAction_Traces_And_Returns_ActionDescriptor_Tracer()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            Mock<IHttpActionSelector> mockSelector = new Mock<IHttpActionSelector>();
            mockSelector.Setup(s => s.SelectAction(_controllerContext)).Returns(_mockActionDescriptor.Object);
            HttpActionSelectorTracer tracer = new HttpActionSelectorTracer(mockSelector.Object, traceWriter);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(_actionContext.Request, TraceCategories.ActionCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
                new TraceRecord(_actionContext.Request, TraceCategories.ActionCategory, TraceLevel.Info) { Kind = TraceKind.End }
            };

            // Act
            HttpActionDescriptor selectedActionDescriptor = ((IHttpActionSelector)tracer).SelectAction(_controllerContext);

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.IsAssignableFrom<HttpActionDescriptorTracer>(selectedActionDescriptor);
        }
        public void SelectAction_Traces_And_Throws_Exception_Thrown_From_Inner()
        {
            // Arrange
            TestTraceWriter traceWriter = new TestTraceWriter();
            Mock<IHttpActionSelector> mockSelector = new Mock<IHttpActionSelector>();
            InvalidOperationException exception = new InvalidOperationException();
            mockSelector.Setup(s => s.SelectAction(_controllerContext)).Throws(exception);
            HttpActionSelectorTracer tracer = new HttpActionSelectorTracer(mockSelector.Object, traceWriter);

            TraceRecord[] expectedTraces = new TraceRecord[]
            {
                new TraceRecord(_actionContext.Request, TraceCategories.ActionCategory, TraceLevel.Info) { Kind = TraceKind.Begin },
                new TraceRecord(_actionContext.Request, TraceCategories.ActionCategory, TraceLevel.Error) { Kind = TraceKind.End }
            };

            // Act
            Exception thrown = Assert.Throws<InvalidOperationException>(() => ((IHttpActionSelector)tracer).SelectAction(_controllerContext));

            // Assert
            Assert.Equal<TraceRecord>(expectedTraces, traceWriter.Traces, new TraceRecordComparer());
            Assert.Same(exception, thrown);
            Assert.Same(exception, traceWriter.Traces[1].Exception);
        }
        public void Decorator_GetInner_On_HttpActionSelectorTracer_Returns_IHttpActionSelector()
        {
            // Arrange
            IHttpActionSelector expectedInner = new Mock<IHttpActionSelector>().Object;
            HttpActionSelectorTracer productUnderTest = new HttpActionSelectorTracer(expectedInner, new TestTraceWriter());

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

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
        public void Inner_Property_On_HttpActionSelectorTracer_Returns_IHttpActionSelector()
        {
            // Arrange
            IHttpActionSelector expectedInner = new Mock<IHttpActionSelector>().Object;
            HttpActionSelectorTracer productUnderTest = new HttpActionSelectorTracer(expectedInner, new TestTraceWriter());

            // Act
            IHttpActionSelector actualInner = productUnderTest.Inner;

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
Example #6
0
 private static void CreateActionSelectorTracer(HttpConfiguration configuration, ITraceWriter traceWriter)
 {
     IHttpActionSelector selector = configuration.ServiceResolver.GetService(typeof(IHttpActionSelector)) as IHttpActionSelector;
     HttpActionSelectorTracer tracer = new HttpActionSelectorTracer(selector, traceWriter);
     configuration.ServiceResolver.SetService(typeof(IHttpActionSelector), tracer);
 }
 private static void CreateActionSelectorTracer(HttpConfiguration configuration, ITraceWriter traceWriter)
 {
     IHttpActionSelector selector = configuration.Services.GetActionSelector();
     HttpActionSelectorTracer tracer = new HttpActionSelectorTracer(selector, traceWriter);
     configuration.Services.Replace(typeof(IHttpActionSelector), tracer);
 }