Example #1
0
        public void HttpServerDoesNotReplaceOriginalRequestContext()
        {
            // Arrange
            HttpServer server  = new HttpServer();
            var        handler = new ThrowIfNoContext();

            server.Configuration.MessageHandlers.Add(handler);
            server.Configuration.MapHttpAttributeRoutes();
            server.Configuration.EnsureInitialized();

            HttpMessageInvoker invoker = new HttpMessageInvoker(server);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers");

            HttpRequestContext context = new HttpRequestContext();

            request.SetRequestContext(context);

            // Act
            var response = invoker.SendAsync(request, CancellationToken.None).Result;

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.True(handler.ContextFound);
            Assert.Equal(context, response.RequestMessage.GetRequestContext());
        }
        public async Task HttpServerAddsDefaultRequestContext()
        {
            // Arrange
            HttpServer server  = new HttpServer();
            var        handler = new ThrowIfNoContext();

            server.Configuration.MessageHandlers.Add(handler);
            server.Configuration.MapHttpAttributeRoutes();
            server.Configuration.EnsureInitialized();

            var invoker = new HttpMessageInvoker(server);

            var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers");

            // Act
            var response = await invoker.SendAsync(request, CancellationToken.None);

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.True(handler.ContextFound);
        }
        public void HttpServerDoesNotReplaceOriginalRequestContext()
        {
            // Arrange
            HttpServer server = new HttpServer();
            var handler = new ThrowIfNoContext();

            server.Configuration.MessageHandlers.Add(handler);
            server.Configuration.MapHttpAttributeRoutes();
            server.Configuration.EnsureInitialized();

            HttpMessageInvoker invoker = new HttpMessageInvoker(server);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Customers");

            HttpRequestContext context = new HttpRequestContext();

            request.SetRequestContext(context);

            // Act
            var response = invoker.SendAsync(request, CancellationToken.None).Result;

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.True(handler.ContextFound);
            Assert.Equal(context, response.RequestMessage.GetRequestContext());
        }