public void PostAsync_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.PostAsync(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(TaskHelper.CreateTaskFromResult(_failureResponse)); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When, Then Assert.Throws <HttpException>(async() => await client.PostAsync <string>(new Uri("http://someurl.co.uk/resource"))); }
public void PostAsync_Success_ReturnsSuccessResult() { // Given var http = new Mock <IHttpChannel>(); var httpResponseTask = new TaskCompletionSource <IHttpResponse>(); httpResponseTask.SetResult(_successResponse); http.Setup(h => h.PostAsync(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(httpResponseTask.Task); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.PostAsync <string>(new Uri("http://someurl.co.uk/resource")); // Then Assert.That(result.Result, Is.EqualTo(_successResponse.Content)); }
public void PostAsync_Success_ReturnsSuccessResult() { // Given var http = new Mock<IHttpChannel>(); var httpResponseTask = new TaskCompletionSource<IHttpResponse>(); httpResponseTask.SetResult(_successResponse); http.Setup(h => h.PostAsync(It.IsAny<IHttpRequest>())) .Returns(httpResponseTask.Task); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.PostAsync<string>(new Uri("http://someurl.co.uk/resource")); // Then Assert.That(result.Result, Is.EqualTo(_successResponse.Content)); }
public void PostAsync_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock<IHttpChannel>(); http.Setup(h => h.PostAsync(It.IsAny<IHttpRequest>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) .Returns(TaskHelper.CreateTaskFromResult(_failureResponse)); IRestClient client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When, Then Assert.Throws<HttpException>(async () => await client.PostAsync<string>(new Uri("http://someurl.co.uk/resource"))); }