Ejemplo n.º 1
0
        public void SendAsync_ThrowsIfRequestIsNull()
        {
            // Arrange
            ETagMessageHandler handler = new ETagMessageHandler();

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

            // Act & Assert
            Assert.ThrowsArgumentNull(() => { var result = handler.SendAsync(null).Result; }, "request");
        }
Ejemplo n.º 3
0
        public void SendAsync_ThrowsInvalidOperationExceptionIfRequestDoesNotHaveConfiguration()
        {
            // 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.");
        }
Ejemplo n.º 4
0
        public void SendAsync_ThrowsInvalidOperationExceptionIfRequestDoesNotHaveConfiguration()
        {
            // 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.");
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void SendAsync_DoesNotWriteETagIfResponseIsNoContent()
        {
            // 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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public void GetSingleEntityEntityType_ReturnsEntityTypeForSingleEntityResources(string odataPath, string typeName)
        {
            // Arrange
            IEdmModel         model       = SetupModel();
            IODataPathHandler pathHandler = new DefaultODataPathHandler();
            ODataPath         path        = pathHandler.Parse(model, odataPath);

            // Guard
            Assert.NotNull(path);

            // Act
            IEdmEntityType entityType = ETagMessageHandler.GetSingleEntityEntityType(path);

            // Assert
            Assert.NotNull(entityType);
            Assert.Equal(typeName, entityType.FullName());
        }
Ejemplo n.º 9
0
        public void SendAsync_DoesNotWriteETagIfResponseIsNoContent()
        {
            // 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);
        }
Ejemplo n.º 10
0
        public void SendAsync_DoesNotWriteETagIfContentIsNull()
        {
            // Arrange
            HttpRequestMessage  request          = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                                                                 typeof(ETagCustomer),
                                                                 value: null);

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

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

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Ejemplo n.º 11
0
        public void SendAsync_DoesNotWriteETagIfContentIsntObjectContent()
        {
            // 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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public void SendAsync_DoesNotWriteETagIfETagIsNull()
        {
            // 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);
        }
Ejemplo n.º 14
0
        public void SendAsync_DoesNotWriteETagIfETagIsNull()
        {
            // 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);
        }
Ejemplo n.º 15
0
        public void SendAsync_DoesNotWriteETagIfContentIsntObjectContent()
        {
            // 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);
        }
Ejemplo n.º 16
0
        public void SendAsync_DoesNotWriteETagIfContentIsNull()
        {
            // Arrange
            HttpRequestMessage request = SetupRequest(HttpMethod.Get, "Customers(3)");
            HttpResponseMessage originalResponse = SetupResponse(HttpStatusCode.OK,
                typeof(ETagCustomer),
                value: null);

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

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

            // Assert
            Assert.Null(response.Headers.ETag);
        }
Ejemplo 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);
        }