public void Post_HttpReturnsNull_ReturnsNull()
        {
            // Arrange
            var content = "content";

            var postResourceContext = new PostRestResourceContext(content);

            var httpRequest = new HttpRequest
            {
                HttpMethod      = HttpMethod.POST,
                ResourcePath    = postResourceContext.ResourcePath,
                Content         = postResourceContext.Content,
                ContentType     = "application/xml",
                ContentEncoding = Encoding.UTF8
            };

            HttpResponse httpResponse = null;

            mockHttpClient.Setup(hc => hc.Submit(httpRequest))
            .Returns(httpResponse);

            // Act
            var actualResponse = restClient.Post(postResourceContext);

            // Assert
            Assert.IsNull(actualResponse);
        }
Esempio n. 2
0
        public void Post_HttpReturnsIn200Range_ReturnsRestResponse()
        {
            // Arrange
            string content = "content";

            PostRestResourceContext postResourceContext = new PostRestResourceContext(content);

            HttpRequest httpRequest = new HttpRequest()
            {
                HttpMethod      = HttpMethod.POST,
                ResourcePath    = postResourceContext.ResourcePath,
                Content         = postResourceContext.Content,
                ContentType     = "application/xml",
                ContentEncoding = Encoding.UTF8
            };

            RestResponse expectedResponse = new RestResponse()
            {
                StatusCode = HttpStatusCode.OK
            };

            HttpResponse httpResponse = new HttpResponse()
            {
                StatusCode = HttpStatusCode.OK
            };

            mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse);

            // Act
            RestResponse actualResponse = restClient.Post(postResourceContext);

            // Assert
            Assert.IsNotNull(actualResponse);
            Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode);
        }
        public void Post_HttpReturnsNull_ReturnsNull()
        {
            // Arrange
            string content = "content";

            PostRestResourceContext postResourceContext = new PostRestResourceContext(content);

            HttpRequest httpRequest = new HttpRequest()
            {
                HttpMethod = HttpMethod.POST,
                ResourcePath = postResourceContext.ResourcePath,
                Content = postResourceContext.Content,
                ContentType = "application/xml",
                ContentEncoding = Encoding.UTF8
            };

            RestResponse expectedResponse = new RestResponse()
            {
                StatusCode = HttpStatusCode.NotFound
            };

            HttpResponse httpResponse = null;

            mockHttpClient.Setup(hc => hc.Submit(httpRequest)).Returns(httpResponse);

            // Act
            RestResponse actualResponse = restClient.Post(postResourceContext);

            // Assert
            Assert.IsNull(actualResponse);
        }
        public void Post_HttpReturnsNull_ReturnsNull()
        {
            // Arrange
            var content = "content";

            var postResourceContext = new PostRestResourceContext(content);

            var httpRequest = new HttpRequest
            {
                HttpMethod = HttpMethod.POST,
                ResourcePath = postResourceContext.ResourcePath,
                Content = postResourceContext.Content,
                ContentType = "application/xml",
                ContentEncoding = Encoding.UTF8
            };

            HttpResponse httpResponse = null;

            mockHttpClient.Setup(hc => hc.Submit(httpRequest))
                          .Returns(httpResponse);

            // Act
            var actualResponse = restClient.Post(postResourceContext);

            // Assert
            Assert.IsNull(actualResponse);
        }
        public void Post_HttpReturnsIn200Range_ReturnsRestResponse()
        {
            // Arrange
            var content = "content";

            var postResourceContext = new PostRestResourceContext(content);

            var httpRequest = new HttpRequest
            {
                HttpMethod = HttpMethod.POST,
                ResourcePath = postResourceContext.ResourcePath,
                Content = postResourceContext.Content,
                ContentType = "application/xml",
                ContentEncoding = Encoding.UTF8
            };

            var expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK
            };

            var httpResponse = new HttpResponse
            {
                StatusCode = HttpStatusCode.OK
            };

            mockHttpClient.Setup(hc => hc.Submit(httpRequest))
                          .Returns(httpResponse);

            // Act
            var actualResponse = restClient.Post(postResourceContext);

            // Assert
            Assert.IsNotNull(actualResponse);
            Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode);
        }