Exemplo n.º 1
0
        public void SendAsync_WritesETagToResponseHeaders_InUntyped()
        {
            // Arrange
            IEdmModel          model   = GetUnTypeEdmModel();
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)", model);

            IEdmEntityType  entityType = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer");
            EdmEntityObject customer   = new EdmEntityObject(entityType);

            customer.TrySetPropertyValue("ID", 3);
            customer.TrySetPropertyValue("Name", "Sam");

            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK, typeof(EdmEntityObject), customer);
            ETagMessageHandler  handler          = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.NotNull(response.Headers.ETag);
            Assert.Equal("\"J1NhbSc=\"", response.Headers.ETag.Tag);
        }
Exemplo n.º 2
0
        public async Task SendAsync_ThrowsIfRequestIsNull()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();

            // Act & Assert
            await ExceptionAssert.ThrowsArgumentNullAsync(() => handler.SendAsync(null), "request");
        }
        public void SendAsync_ThrowsIfRequestIsNull()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => { var result = handler.SendAsync(null).Result; }, "request");
        }
Exemplo n.º 4
0
        public void SendAsync_ThrowsIfRequestIsNull()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();

            // Act & Assert
            Assert.ThrowsArgumentNull(() => { var result = handler.SendAsync(null).Result; }, "request");
        }
Exemplo n.º 5
0
        public async Task SendAsync_ThrowsInvalidOperationExceptionIfRequestDoesntHaveConfiguration()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/");

            // Act & Assert
            await ExceptionAssert.ThrowsAsync <InvalidOperationException>(
                () => handler.SendAsync(request),
                "Request message does not contain an HttpConfiguration object.");
        }
Exemplo n.º 6
0
        public void SendAsync_ThrowsInvalidOperationExceptionIfRequestDoesntHaveConfiguration()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/");

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => { var result = handler.SendAsync(request).Result; },
                "Request message does not contain an HttpConfiguration object.");
        }
        public void SendAsync_ThrowsInvalidOperationExceptionIfRequestDoesntHaveConfiguration()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://host/");

            // Act & Assert
            Assert.Throws<InvalidOperationException>(
                () => { var result = handler.SendAsync(request).Result; },
                "Request message does not contain an HttpConfiguration object.");
        }
        public void SendAsync_ReturnsNullIfInnerHandlerReturnsNull()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/Customers(3)");
            request.SetConfiguration(new HttpConfiguration());
            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(null) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response);
        }
        public void SendAsync_DoesntWriteETagIfResponseIsNotSuccessful()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/Customers(3)");
            request.SetConfiguration(new HttpConfiguration());
            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.NotFound);
            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 10
0
        public void SendAsync_ReturnsNullIfInnerHandlerReturnsNull()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/Customers(3)");

            request.SetConfiguration(new HttpConfiguration());
            ETagMessageHandler handler = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(null)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response);
        }
Exemplo n.º 11
0
        public async Task SendAsync_DoesntWriteETagIfResponseIsNotSuccessful()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/Customers(3)");

            request.SetConfiguration(new HttpConfiguration());
            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.NotFound);
            ETagMessageHandler  handler          = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = await handler.SendAsync(request);

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 12
0
        public void SendAsync_DoesntWriteETagIfResponseIsNoContent()
        {
            // Arrange
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "/Customers(3)");

            request.SetConfiguration(new HttpConfiguration());
            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.NoContent);
            ETagMessageHandler  handler          = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 13
0
        public void SendAsync_DoesntWriteETagIfContentIsNull()
        {
            // Arrange
            HttpRequestMessage  request          = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                                                                 typeof(ETagCustomer),
                                                                 null);

            ETagMessageHandler handler = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 14
0
        public void SendAsync_DoesntWriteETagIfContentIsntObjectContent()
        {
            // Arrange
            HttpRequestMessage  request          = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.OK);

            originalResponse.Content = new StringContent("Some content");

            ETagMessageHandler handler = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 15
0
        public void SendAsync_WritesETagToResponseHeaders()
        {
            // Arrange
            HttpRequestMessage  request          = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                                                                 typeof(ETagCustomer),
                                                                 new ETagCustomer {
                Id = 3, Timestamp = new byte[] { (byte)3 }
            });
            ETagMessageHandler handler = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.NotNull(response.Headers.ETag);
        }
Exemplo n.º 16
0
        public void SendAsync_DoesntWriteETagIfETagIsNull()
        {
            // Arrange
            HttpRequestMessage  request          = SetupRequest(HttpMethod.Get, "NonEtagEntity(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                                                                 typeof(NonEtagEntity),
                                                                 new NonEtagEntity {
                Id = 3
            });

            ETagMessageHandler handler = new ETagMessageHandler()
            {
                InnerHandler = new TestHandler(originalResponse)
            };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 17
0
        public void SendAsync_WritesETagToResponseHeaders()
        {
            // Arrange
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                typeof(ETagCustomer),
                new ETagCustomer { Id = 3, Timestamp = new byte[] { (byte)3 } });
            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.NotNull(response.Headers.ETag);
        }
Exemplo n.º 18
0
        public void SendAsync_DoesntWriteETagIfContentIsntObjectContent()
        {
            // Arrange
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = new HttpResponseMessage(HttpStatusCode.OK);
            originalResponse.Content = new StringContent("Some content");

            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 19
0
        public void SendAsync_DoesntWriteETagIfContentIsNull()
        {
            // Arrange
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                typeof(ETagCustomer),
                null);

            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Exemplo n.º 20
0
        public void SendAsync_DoesntWriteETagIfETagIsNull()
        {
            // Arrange
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "NonEtagEntity(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                typeof(NonEtagEntity),
                new NonEtagEntity { Id = 3 });

            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.Null(response.Headers.ETag);
        }
        public void SendAsync_WritesETagToResponseHeaders_InUntyped()
        {
            // Arrange
            IEdmModel model = GetUnTypeEdmModel();
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)", model);

            IEdmEntityType entityType = model.SchemaElements.OfType<IEdmEntityType>().First(c => c.Name == "Customer");
            EdmEntityObject customer = new EdmEntityObject(entityType);
            customer.TrySetPropertyValue("ID", 3);
            customer.TrySetPropertyValue("Name", "Sam");

            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK, typeof(EdmEntityObject), customer);
            ETagMessageHandler handler = new ETagMessageHandler() { InnerHandler = new TestHandler(originalResponse) };

            // Act
            HttpResponseMessage response = handler.SendAsync(request).Result;

            // Assert
            Assert.NotNull(response.Headers.ETag);
            Assert.Equal("\"J1NhbSc=\"", response.Headers.ETag.Tag);
        }