public void Get_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock<IHttpChannel>(); http.Setup(h => h.Get(It.IsAny<IHttpRequest>())) .Returns(_failureResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When, Then Assert.Throws<HttpException>(() => client.Get<string>(new Uri("http://someurl.co.uk/resource"))); }
public void GetAsync_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.GetAsync(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.GetAsync <string>(new Uri("http://someurl.co.uk/resource"))); }
public void Post_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.Post(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(_failureResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When, Then Assert.Throws <HttpException>(() => client.Post <string>(new Uri("http://someurl.co.uk/resource"))); }
public void Get_Success_ReturnsSuccessResult() { // Given var http = new Mock<IHttpChannel>(); http.Setup(h => h.Get(It.IsAny<IHttpRequest>())) .Returns(_successResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.Get<string>(new Uri("http://someurl.co.uk/resource")); // Then Assert.That(result, Is.EqualTo(_successResponse.Content)); }
public void Get_Success_ReturnsSuccessResult() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.Get(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(_successResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.Get <string>(new Uri("http://someurl.co.uk/resource")); // Then Assert.That(result, Is.EqualTo(_successResponse.Content)); }
public void Delete_Success_CallsDeleteOnHttp() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.Delete(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(_successResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When client.Delete(new Uri("http://someurl.co.uk/resource")); // Then http.Verify(h => h.Delete(It.IsAny <HttpRequest>(), It.IsAny <string>(), It.IsAny <string>())); }
public void PostFile_Success_ReturnsSuccessResult() { // Given var http = new Mock <IHttpChannel>(); http.Setup(h => h.Post(It.IsAny <IHttpRequest>(), It.IsAny <IHttpPostedFile>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(_successResponse); var file = new Mock <IHttpPostedFile>(); IRestClient client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.PostFile <string>(new Uri("http://someurl.co.uk/resource"), file.Object); // Then Assert.Equal(result, _successResponse.Content); }
public void PutAsync_Success_ReturnsSuccessResult() { // Given var http = new Mock <IHttpChannel>(); var httpResponseTask = new TaskCompletionSource <IHttpResponse>(); httpResponseTask.SetResult(_successResponse); http.Setup(h => h.PutAsync(It.IsAny <IHttpRequest>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(httpResponseTask.Task); IRestClient client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When var result = client.PutAsync <string>(new Uri("http://someurl.co.uk/resource")); // Then Assert.Equal(result.Result, _successResponse.Content); }
public void DeleteAsync_Success_CallsDeleteOnHttp() { // Given var http = new Mock <IHttpChannel>(); var httpResponseTask = new TaskCompletionSource <IHttpResponse>(); httpResponseTask.SetResult(_successResponse); http.Setup(h => h.DeleteAsync(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.DeleteAsync(new Uri("http://someurl.co.uk/resource")); // Then http.Verify(h => h.DeleteAsync(It.IsAny <HttpRequest>(), It.IsAny <string>(), It.IsAny <string>())); Assert.That(result.IsCompleted, Is.EqualTo(true)); }
public void DeleteAsync_Success_CallsDeleteOnHttp() { // Given var http = new Mock<IHttpChannel>(); var httpResponseTask = new TaskCompletionSource<IHttpResponse>(); httpResponseTask.SetResult(_successResponse); http.Setup(h => h.DeleteAsync(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.DeleteAsync(new Uri("http://someurl.co.uk/resource")); // Then http.Verify(h => h.DeleteAsync(It.IsAny<HttpRequest>())); Assert.That(result.IsCompleted, Is.EqualTo(true)); }
public void Delete_Success_CallsDeleteOnHttp() { // Given var http = new Mock<IHttpChannel>(); http.Setup(h => h.Delete(It.IsAny<IHttpRequest>())) .Returns(_successResponse); var client = new ZendeskClient(new Uri("http://someurl.co.uk"), new ZendeskDefaultConfiguration("bob", "x1234//#"), _serializer.Object, http.Object); // When client.Delete(new Uri("http://someurl.co.uk/resource")); // Then http.Verify(h => h.Delete(It.IsAny<HttpRequest>())); }
public void GetAsync_HttpReturnsFailResult_ThrowsException() { // Given var http = new Mock<IHttpChannel>(); http.Setup(h => h.GetAsync(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.GetAsync<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>(), It.IsAny<string>())) .Returns(httpResponseTask.Task); IRestClient 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 BeforeScenario() { _client = new ZendeskClient(new Uri(ConfigurationManager.AppSettings["zendeskhost"]), new ZendeskDefaultConfiguration(ConfigurationManager.AppSettings["zendeskusername"], ConfigurationManager.AppSettings["zendesktoken"])); }