public void Initialize_Repairs_Handler_Collection_If_RequestTracer_Inserted() { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); TestTraceWriter traceWriter = new TestTraceWriter(); DelegatingHandler messageHandler = new Mock <DelegatingHandler>().Object; DelegatingHandler msgHandlerTracer = new MessageHandlerTracer(messageHandler, traceWriter); RequestMessageHandlerTracer requestMsgtracer = new RequestMessageHandlerTracer(traceWriter); List <DelegatingHandler> handlerList = new List <DelegatingHandler>() { messageHandler, msgHandlerTracer, requestMsgtracer }; foreach (var eachHandler in handlerList) { config.MessageHandlers.Add(eachHandler); } TraceManager traceManager = new TraceManager(); traceManager.Initialize(config); Collection <DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; // Act config.MessageHandlers.Insert(0, requestMsgtracer); traceManager.Initialize(config); // Assert Collection <DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }
public void Multiple_Initialize_DoesNotAlter_MessageHandlerCollection( List <DelegatingHandler> handlerList ) { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); foreach (var eachHandler in handlerList) { config.MessageHandlers.Add(eachHandler); } TraceManager traceManager = new TraceManager(); traceManager.Initialize(config); Collection <DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; // Act traceManager.Initialize(config); // Assert Collection <DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }
public void TraceManager_Initialize_After_HttpServer_Initialize_DoesNotAlter_MessageHandlerCollection() { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); DelegatingHandler messageHandler = new Mock <DelegatingHandler>().Object; config.MessageHandlers.Add(messageHandler); TraceManager traceManager = new TraceManager(); Collection <DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; HttpRequestMessage request = new HttpRequestMessage(); Mock <HttpControllerDispatcher> dispatcherMock = new Mock <HttpControllerDispatcher>(config); dispatcherMock.Protected().Setup <Task <HttpResponseMessage> >("SendAsync", request, CancellationToken.None) .Returns(TaskHelpers.FromResult <HttpResponseMessage>(request.CreateResponse())); HttpServer server = new HttpServer(config, dispatcherMock.Object); HttpMessageInvoker invoker = new HttpMessageInvoker(server); // Act Task <HttpResponseMessage> response = invoker.SendAsync(request, CancellationToken.None); traceManager.Initialize(config); // Assert Collection <DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }
public void Multiple_Initialize_DoesNotAlter_Num_Of_MessageHandlers_With_No_TraceWriter() { // Arrange HttpConfiguration config = new HttpConfiguration(); TraceManager traceManager = new TraceManager(); traceManager.Initialize(config); int expectedHandlerCount = config.MessageHandlers.Count; // Act traceManager.Initialize(config); // Assert int actualHandlerCount = config.MessageHandlers.Count; Assert.Equal(expectedHandlerCount, actualHandlerCount); }
public void Initialize_Repairs_Handler_Collection_If_RequestTracer_Inserted() { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); TestTraceWriter traceWriter = new TestTraceWriter(); DelegatingHandler messageHandler = new Mock<DelegatingHandler>().Object; DelegatingHandler msgHandlerTracer = new MessageHandlerTracer(messageHandler, traceWriter); RequestMessageHandlerTracer requestMsgtracer = new RequestMessageHandlerTracer(traceWriter); List<DelegatingHandler> handlerList = new List<DelegatingHandler>() { messageHandler, msgHandlerTracer, requestMsgtracer }; foreach (var eachHandler in handlerList) { config.MessageHandlers.Add(eachHandler); } TraceManager traceManager = new TraceManager(); traceManager.Initialize(config); Collection<DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; // Act config.MessageHandlers.Insert(0, requestMsgtracer); traceManager.Initialize(config); // Assert Collection<DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }
public void TraceManager_Initialize_After_HttpServer_Initialize_DoesNotAlter_MessageHandlerCollection() { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); DelegatingHandler messageHandler = new Mock<DelegatingHandler>().Object; config.MessageHandlers.Add(messageHandler); TraceManager traceManager = new TraceManager(); Collection<DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; HttpRequestMessage request = new HttpRequestMessage(); Mock<HttpControllerDispatcher> dispatcherMock = new Mock<HttpControllerDispatcher>(config); dispatcherMock.Protected().Setup<Task<HttpResponseMessage>>("SendAsync", request, CancellationToken.None) .Returns(TaskHelpers.FromResult<HttpResponseMessage>(request.CreateResponse())); HttpServer server = new HttpServer(config, dispatcherMock.Object); HttpMessageInvoker invoker = new HttpMessageInvoker(server); // Act Task<HttpResponseMessage> response = invoker.SendAsync(request, CancellationToken.None); traceManager.Initialize(config); // Assert Collection<DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }
public void Multiple_Initialize_DoesNotAlter_MessageHandlerCollection(List<DelegatingHandler> handlerList) { // Arrange HttpConfiguration config = new HttpConfiguration(); config.Services.Replace(typeof(ITraceWriter), new TestTraceWriter()); foreach (var eachHandler in handlerList) { config.MessageHandlers.Add(eachHandler); } TraceManager traceManager = new TraceManager(); traceManager.Initialize(config); Collection<DelegatingHandler> expectedMessageHandlers = config.MessageHandlers; // Act traceManager.Initialize(config); // Assert Collection<DelegatingHandler> actualMessageHandlers = config.MessageHandlers; Assert.Equal(expectedMessageHandlers, actualMessageHandlers); Assert.True(IsMessageHandlerCollectionValid(config.MessageHandlers)); }