public void GetAsync_Happy_Test()
        {
            //Arrange
            var testObject = new SimpleTestObject {
                TestProperty = "Test Value", TestProperty2 = 2
            };
            var content            = new StringContent(testObject.ToJsonString());
            var httpClientResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = content
            };
            var httpClient = new Mock <IHttpClient>();

            httpClient.Setup(x => x.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(httpClientResponse);
            var config = new TestRestConfig();
            var client = new TestRestClient(config, httpClient.Object);

            //Act
            var responseTask = client.GetAsync <SimpleTestObject>("TestObject");
            var response     = responseTask.GetAwaiter().GetResult();

            //Assert
            Assert.IsTrue(response.IsSuccessStatusCode);
            Assert.AreEqual(response.Data.TestProperty, testObject.TestProperty);
        }
        public void PatchAsync_Sad_Test()
        {
            //Arrange
            var testObject = new SimpleTestObject {
                TestProperty = "Test Value", TestProperty2 = 2
            };
            var httpClientResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError)
            {
                Content = null
            };
            var httpClient = new Mock <IHttpClient>();

            httpClient.Setup(x => x.SendAsync(It.IsAny <HttpRequestMessage>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(httpClientResponse);
            var config     = new TestRestConfig();
            var restClient = new TestRestClient(config, httpClient.Object);

            //Act
            var responseTask = restClient.PatchAsync <SimpleTestObject, SimpleTestObject>("TestObject", testObject);
            var response     = responseTask.GetAwaiter().GetResult();

            //Assert
            Assert.IsFalse(response.IsSuccessStatusCode);
            Assert.IsNull(response.Data);
            Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError);
        }
Example #3
0
        public void GetStringAsync_Happy_Test()
        {
            //Arrange
            var testObject = new SimpleTestObject {
                TestProperty = "Test Value", TestProperty2 = 2
            };
            var httpClient = new Mock <IHttpClient>();

            httpClient.Setup(x => x.GetStringAsync(It.IsAny <string>()))
            .ReturnsAsync(testObject.ToJsonString());
            var config = new TestRestConfig();
            var client = new TestRestClient(config, httpClient.Object);

            //Act
            var responseTask = client.GetStringAsync("TestObject");
            var response     = responseTask.GetAwaiter().GetResult();

            //Assert
            Assert.AreEqual(response, testObject.ToJsonString());
        }