public void PutAsync_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.PutAsync(It.IsAny <string>(), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>())) .ReturnsAsync(httpClientResponse); var config = new TestRestConfig(); var restClient = new TestRestClient(config, httpClient.Object); //Act var responseTask = restClient.PutAsync <SimpleTestObject, SimpleTestObject>("TestObject", testObject); var response = responseTask.GetAwaiter().GetResult(); //Assert Assert.IsFalse(response.IsSuccessStatusCode); Assert.IsNull(response.Data); Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError); }
public void PutAsync_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.PutAsync(It.IsAny <string>(), It.IsAny <HttpContent>(), It.IsAny <CancellationToken>())) .ReturnsAsync(httpClientResponse); var config = new TestRestConfig(); var restClient = new TestRestClient(config, httpClient.Object); //Act var responseTask = restClient.PutAsync <SimpleTestObject, SimpleTestObject>("TestObject", testObject); var response = responseTask.GetAwaiter().GetResult(); //Assert Assert.IsTrue(response.IsSuccessStatusCode); Assert.AreEqual(response.Data.TestProperty, testObject.TestProperty); }