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); }
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); }
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); }
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); }
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); }