public void CanDeserializeCommitComment() { const string commitCommentResponseJson = "{\"html_url\": \"https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e#commitcomment-1\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/comments/1\"," + "\"id\": 1," + "\"body\": \"Me too\"," + "\"path\": \"file1.txt\"," + "\"position\": 4," + "\"line\": 14," + "\"commit_id\": \"6dcb09b5b57875f334f61aebed695e2e4193db5e\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var httpResponse = new Response( HttpStatusCode.OK, commitCommentResponseJson, new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <CommitComment>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(commitCommentResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Id); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{\"id\": 1," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + "\"body\": \"Me too\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var response = new ApiResponse <IssueComment> { Body = issueResponseJson, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(issueResponseJson, response.Body); Assert.Equal(1, response.BodyAsObject.Id); }
public void CanDeserializeIssue() { const string issueResponseJson = "{\"url\":\"https://api.github.com/repos/octokit-net-test/public-repo-" + "20131022050247078/issues/1\",\"labels_url\":\"https://api.github.com/repos/octokit-net-test/publ" + "ic-repo-20131022050247078/issues/1/labels{/name}\",\"comments_url\":\"https://api.github.com/rep" + "os/octokit-net-test/public-repo-20131022050247078/issues/1/comments\",\"events_url\":\"https://a" + "pi.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events\",\"html_url" + "\":\"https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1\",\"id\":2139915" + "4,\"number\":1,\"title\":\"A test issue\",\"user\":{\"login\":\"octokit-net-test\",\"id\":558045" + "0,\"avatar_url\":\"https://2.gravatar.com/avatar/20724e5085dcbe92e660a61d282f665c?d=https%3A%2F%" + "2Fidenticons.github.com%2Fb21d03168ecd65836d6407e4cdd61e0c.png\",\"gravatar_id\":\"20724e5085dcb" + "e92e660a61d282f665c\",\"url\":\"https://api.github.com/users/octokit-net-test\",\"html_url\":\"h" + "ttps://github.com/octokit-net-test\",\"followers_url\":\"https://api.github.com/users/octokit-ne" + "t-test/followers\",\"following_url\":\"https://api.github.com/users/octokit-net-test/following{/" + "other_user}\",\"gists_url\":\"https://api.github.com/users/octokit-net-test/gists{/gist_id}\",\"" + "starred_url\":\"https://api.github.com/users/octokit-net-test/starred{/owner}{/repo}\",\"subscri" + "ptions_url\":\"https://api.github.com/users/octokit-net-test/subscriptions\",\"organizations_url" + "\":\"https://api.github.com/users/octokit-net-test/orgs\",\"repos_url\":\"https://api.github.com" + "/users/octokit-net-test/repos\",\"events_url\":\"https://api.github.com/users/octokit-net-test/e" + "vents{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octokit-net-test/receiv" + "ed_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[],\"state\":\"open\",\"assignee" + "\":null,\"milestone\":null,\"comments\":0,\"created_at\":\"2013-10-22T17:02:48Z\",\"updated_at\"" + ":\"2013-10-22T17:02:48Z\",\"closed_at\":null,\"body\":\"A new unassigned issue\",\"closed_by\":null}"; var response = new ApiResponse <Issue> { Body = issueResponseJson, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(issueResponseJson, response.Body); }
protected async Task <T> ProcessRequest <T>(string endPoint, Method method, IDictionary <string, object> parameters = null, object body = null) where T : new() { string url = endPoint.StartsWith("http") ? endPoint : $"{BaseUrl}{endPoint}"; var client = new RestClient(url); var request = new RestRequest(method); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Authorization", $"Bearer {this.bearerToken}"); request.AddHeader("Harvest-Account-ID", $"{this.accountId}"); if (parameters != null) { foreach (var parameter in parameters) { request.AddQueryParameter(parameter.Key, parameter.Value?.ToString()); } } if (body != null) { request.AddJsonBody(body); } IRestResponse response = await client.ExecuteTaskAsync(request); HandleErrors(response); var result = jsonPipeline.DeserializeResponse <T>(response); return(result); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{\"id\": 1," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + "\"body\": \"Me too\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var httpResponse = new Response( HttpStatusCode.OK, issueResponseJson, new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <IssueComment>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Id); }
async Task <IApiResponse <T> > Run <T>(IRequest request, CancellationToken cancellationToken) { _jsonPipeline.SerializeRequest(request); var response = await RunRequest(request, cancellationToken).ConfigureAwait(false); return(_jsonPipeline.DeserializeResponse <T>(response)); }
async Task <IResponse <T> > Run <T>(IRequest request) { _jsonPipeline.SerializeRequest(request); var response = await RunRequest <T>(request).ConfigureAwait(false); _jsonPipeline.DeserializeResponse(response); return(response); }
public void DeserializesSingleObjectResponseIntoCollectionWithOneItem() { const string data = "{\"name\":\"Haack\"}"; var jsonPipeline = new JsonHttpPipeline(); var httpResponse = CreateResponse( HttpStatusCode.OK, data); var response = jsonPipeline.DeserializeResponse <List <SomeObject> >(httpResponse); Assert.Single(response.Body); Assert.Equal("Haack", response.Body.First().Name); }
public void IgnoresResponsesNotIdentifiedAsJson() { const string data = "works"; var response = new ApiResponse <string> { Body = SimpleJson.SerializeObject(data), ContentType = "text/html" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.Null(response.BodyAsObject); }
public void DeserializeResponsesNotIdentifiedAsJsonWhenNotDeserializingToString() { const string data = "works"; var httpResponse = new Response( HttpStatusCode.OK, JsonConvert.SerializeObject(data), new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <string>(httpResponse); Assert.Equal("works", response.Body); }
public void IgnoresResponsesNotIdentifiedAsJsonWhenNotDeserializingToString() { const string data = "works"; var httpResponse = new Response( HttpStatusCode.OK, SimpleJson.SerializeObject(data), new Dictionary <string, string>(), "text/html"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <Commit>(httpResponse); Assert.Null(response.Body); }
public void DeserializesResponse() { const string data = "works"; var httpResponse = CreateResponse( HttpStatusCode.OK, SimpleJson.SerializeObject(data)); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <string>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(data, response.Body); }
public void DeserializesResponse() { const string data = "works"; var response = new ApiResponse <string> { Body = SimpleJson.SerializeObject(data), ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(data, response.BodyAsObject); }
public void DeserializesResponse() { const string data = "works"; var httpResponse = new Response( HttpStatusCode.OK, SimpleJson.SerializeObject(data), new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <string>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(data, response.Body); }
public void DeserializesSingleObjectResponseIntoCollectionWithOneItem() { const string data = "{\"name\":\"Haack\"}"; var jsonPipeline = new JsonHttpPipeline(); var httpResponse = new Response( HttpStatusCode.OK, data, new Dictionary <string, string>(), "application/json"); var response = jsonPipeline.DeserializeResponse <List <SomeObject> >(httpResponse); Assert.Equal(1, response.Body.Count); Assert.Equal("Haack", response.Body.First().Name); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{" + "\"sha\": \"9fb037999f264ba9a7fc6274d15fa3ae2ab98312\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312\"," + "\"tree\": [" + "{" + "\"path\": \"file.rb\"," + "\"mode\": \"100644\"," + "\"type\": \"blob\"," + "\"size\": 30," + "\"sha\": \"44b4fc6d56897b048c772eb4087f854f46256132\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132\"" + "}," + "{" + "\"path\": \"subdir\"," + "\"mode\": \"040000\"," + "\"type\": \"tree\"," + "\"sha\": \"f484d249c660418515fb01c2b9662073663c242e\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/f484d249c660418515fb01c2b9662073663c242e\"" + "}," + "{" + "\"path\": \"exec_file\"," + "\"mode\": \"100755\"," + "\"type\": \"blob\"," + "\"size\": 75," + "\"sha\": \"45b983be36b73c0788dc9cbcb76cbb80fc7bb057\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/45b983be36b73c0788dc9cbcb76cbb80fc7bb057\"" + "}" + "]" + "}"; var httpResponse = new Response( HttpStatusCode.OK, issueResponseJson, new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <TreeResponse>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal("9fb037999f264ba9a7fc6274d15fa3ae2ab98312", response.Body.Sha); }
public void CanDeserializeIssueCommentWithReactions() { const string issueResponseJson = "{\"id\": 1," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + "\"body\": \"Me too\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"," + "\"reactions\": {" + "\"total_count\": 5," + "\"+1\": 3," + "\"-1\": 1," + "\"laugh\": 0," + "\"confused\": 0," + "\"heart\": 1," + "\"hooray\": 0," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1/reactions\"" + "}" + "}"; var httpResponse = CreateResponse( HttpStatusCode.OK, issueResponseJson); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <IssueComment>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Id); Assert.NotNull(response.Body.Reactions); Assert.Equal(5, response.Body.Reactions.TotalCount); Assert.Equal(3, response.Body.Reactions.Plus1); }
public void CanDeserializeBlob() { const string blobResponseJson = "{\"content\": \"Content of the blob\", " + "\"encoding\": \"utf-8\"," + "\"sha\": \"3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15\"," + "\"size\": 100" + "}"; var httpResponse = CreateResponse( HttpStatusCode.OK, blobResponseJson); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <Blob>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(blobResponseJson, (string)response.HttpResponse.Body); Assert.Equal(100, response.Body.Size); Assert.Equal(EncodingType.Utf8, response.Body.Encoding); }
public void CanDeserializeBlob() { const string blobResponseJson = "{\"content\": \"Content of the blob\", " + "\"encoding\": \"utf-8\"," + "\"sha\": \"3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15\"," + "\"size\": 100" + "}"; var response = new ApiResponse <Blob> { Body = blobResponseJson, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(blobResponseJson, response.Body); Assert.Equal(100, response.BodyAsObject.Size); Assert.Equal(EncodingType.Utf8, response.BodyAsObject.Encoding); }
public void PerformsGitTagMapping() { const string data = @"{ ""tag"":""tag-name"", ""sha"": ""tag-sha"", ""url"": ""tag-url"", ""message"": ""tag-message"", ""tagger"": { ""name"": ""tagger-name"", ""email"": ""tagger-email"", ""date"": ""2011-06-17T14:53:35-07:00"" }, ""object"": { ""type"": ""commit"", ""sha"": ""object-sha"", ""url"": ""object-url"" }}"; var response = new ApiResponse <GitTag> { Body = data, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal("tag-name", response.BodyAsObject.Tag); Assert.Equal("tag-sha", response.BodyAsObject.Sha); Assert.Equal("tag-url", response.BodyAsObject.Url); Assert.Equal("tag-message", response.BodyAsObject.Message); Assert.Equal("tagger-name", response.BodyAsObject.Tagger.Name); Assert.Equal("tagger-email", response.BodyAsObject.Tagger.Email); //Adjust expected date for time zone adjustment Assert.Equal(new DateTime(2011, 06, 17, 21, 53, 35), response.BodyAsObject.Tagger.Date); Assert.Equal(TaggedType.Commit, response.BodyAsObject.Object.Type); Assert.Equal("object-sha", response.BodyAsObject.Object.Sha); Assert.Equal("object-url", response.BodyAsObject.Object.Url); }
public void CanDeserializeBlob() { const string blobResponseJson = "{\"content\": \"Content of the blob\", " + "\"encoding\": \"utf-8\"," + "\"sha\": \"3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15\"," + "\"size\": 100" + "}"; var httpResponse = new Response( HttpStatusCode.OK, blobResponseJson, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<Blob>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(blobResponseJson, (string)response.HttpResponse.Body); Assert.Equal(100, response.Body.Size); Assert.Equal(EncodingType.Utf8, response.Body.Encoding); }
public void CanDeserializeBlob() { const string blobResponseJson = "{\"content\": \"Content of the blob\", " + "\"encoding\": \"utf-8\"," + "\"sha\": \"3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15\"," + "\"size\": 100" + "}"; var response = new ApiResponse<Blob> { Body = blobResponseJson, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(blobResponseJson, response.Body); Assert.Equal(100, response.BodyAsObject.Size); Assert.Equal(EncodingType.Utf8, response.BodyAsObject.Encoding); }
public void PerformsGitTagMapping() { const string data = @"{ ""tag"":""tag-name"", ""sha"": ""tag-sha"", ""url"": ""tag-url"", ""message"": ""tag-message"", ""tagger"": { ""name"": ""tagger-name"", ""email"": ""tagger-email"", ""date"": ""2011-06-17T14:53:35-07:00"" }, ""object"": { ""type"": ""commit"", ""sha"": ""object-sha"", ""url"": ""object-url"" }}"; var httpResponse = new Response( HttpStatusCode.OK, data, new Dictionary <string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse <GitTag>(httpResponse); Assert.NotNull(response.Body); Assert.Equal("tag-name", response.Body.Tag); Assert.Equal("tag-sha", response.Body.Sha); Assert.Equal("tag-url", response.Body.Url); Assert.Equal("tag-message", response.Body.Message); Assert.Equal("tagger-name", response.Body.Tagger.Name); Assert.Equal("tagger-email", response.Body.Tagger.Email); //Adjust expected date for time zone adjustment Assert.Equal(new DateTimeOffset(2011, 06, 17, 21, 53, 35, TimeSpan.Zero), response.Body.Tagger.Date); Assert.Equal(TaggedType.Commit, response.Body.Object.Type); Assert.Equal("object-sha", response.Body.Object.Sha); Assert.Equal("object-url", response.Body.Object.Url); }
public void CanDeserializeIssue() { const string issueResponseJson = "{\"url\":\"https://api.github.com/repos/octokit-net-test/public-repo-" + "20131022050247078/issues/1\",\"labels_url\":\"https://api.github.com/repos/octokit-net-test/publ" + "ic-repo-20131022050247078/issues/1/labels{/name}\",\"comments_url\":\"https://api.github.com/rep" + "os/octokit-net-test/public-repo-20131022050247078/issues/1/comments\",\"events_url\":\"https://a" + "pi.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1/events\",\"html_url" + "\":\"https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1\",\"id\":2139915" + "4,\"number\":1,\"title\":\"A test issue\",\"user\":{\"login\":\"octokit-net-test\",\"id\":558045" + "0,\"avatar_url\":\"https://2.gravatar.com/avatar/20724e5085dcbe92e660a61d282f665c?d=https%3A%2F%" + "2Fidenticons.github.com%2Fb21d03168ecd65836d6407e4cdd61e0c.png\",\"gravatar_id\":\"20724e5085dcb" + "e92e660a61d282f665c\",\"url\":\"https://api.github.com/users/octokit-net-test\",\"html_url\":\"h" + "ttps://github.com/octokit-net-test\",\"followers_url\":\"https://api.github.com/users/octokit-ne" + "t-test/followers\",\"following_url\":\"https://api.github.com/users/octokit-net-test/following{/" + "other_user}\",\"gists_url\":\"https://api.github.com/users/octokit-net-test/gists{/gist_id}\",\"" + "starred_url\":\"https://api.github.com/users/octokit-net-test/starred{/owner}{/repo}\",\"subscri" + "ptions_url\":\"https://api.github.com/users/octokit-net-test/subscriptions\",\"organizations_url" + "\":\"https://api.github.com/users/octokit-net-test/orgs\",\"repos_url\":\"https://api.github.com" + "/users/octokit-net-test/repos\",\"events_url\":\"https://api.github.com/users/octokit-net-test/e" + "vents{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octokit-net-test/receiv" + "ed_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[],\"state\":\"open\",\"assignee" + "\":null,\"milestone\":null,\"comments\":0,\"created_at\":\"2013-10-22T17:02:48Z\",\"updated_at\"" + ":\"2013-10-22T17:02:48Z\",\"closed_at\":null,\"body\":\"A new unassigned issue\",\"closed_by\":null}"; var httpResponse = new Response( HttpStatusCode.OK, issueResponseJson, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<Issue>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Number); Assert.Equal(new Uri("https://api.github.com/repos/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.Url); Assert.Equal(new Uri("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1"), response.Body.HtmlUrl); }
public void DeserializesResponse() { const string data = "works"; var httpResponse = new Response( HttpStatusCode.OK, SimpleJson.SerializeObject(data), new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<string>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(data, response.Body); }
public void PerformsGitTagMapping() { const string data = @"{ ""tag"":""tag-name"", ""sha"": ""tag-sha"", ""url"": ""tag-url"", ""message"": ""tag-message"", ""tagger"": { ""name"": ""tagger-name"", ""email"": ""tagger-email"", ""date"": ""2011-06-17T14:53:35-07:00"" }, ""object"": { ""type"": ""commit"", ""sha"": ""object-sha"", ""url"": ""object-url"" }}"; var response = new ApiResponse<GitTag> { Body = data, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal("tag-name", response.BodyAsObject.Tag); Assert.Equal("tag-sha", response.BodyAsObject.Sha); Assert.Equal("tag-url", response.BodyAsObject.Url); Assert.Equal("tag-message", response.BodyAsObject.Message); Assert.Equal("tagger-name", response.BodyAsObject.Tagger.Name); Assert.Equal("tagger-email", response.BodyAsObject.Tagger.Email); //Adjust expected date for time zone adjustment Assert.Equal(new DateTime(2011, 06, 17, 21, 53, 35), response.BodyAsObject.Tagger.Date); Assert.Equal(TaggedType.Commit, response.BodyAsObject.Object.Type); Assert.Equal("object-sha", response.BodyAsObject.Object.Sha); Assert.Equal("object-url", response.BodyAsObject.Object.Url); }
public void IgnoresResponsesNotIdentifiedAsJson() { const string data = "works"; var response = new ApiResponse<string> { Body = SimpleJson.SerializeObject(data), ContentType = "text/html" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.Null(response.BodyAsObject); }
public void DeserializesResponse() { const string data = "works"; var response = new ApiResponse<string> { Body = SimpleJson.SerializeObject(data), ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(data, response.BodyAsObject); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{\"id\": 1," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + "\"body\": \"Me too\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var response = new ApiResponse<IssueComment> { Body = issueResponseJson, ContentType = "application/json" }; var jsonPipeline = new JsonHttpPipeline(); jsonPipeline.DeserializeResponse(response); Assert.NotNull(response.BodyAsObject); Assert.Equal(issueResponseJson, response.Body); Assert.Equal(1, response.BodyAsObject.Id); }
public void PerformsGitTagMapping() { const string data = @"{ ""tag"":""tag-name"", ""sha"": ""tag-sha"", ""url"": ""tag-url"", ""message"": ""tag-message"", ""tagger"": { ""name"": ""tagger-name"", ""email"": ""tagger-email"", ""date"": ""2011-06-17T14:53:35-07:00"" }, ""object"": { ""type"": ""commit"", ""sha"": ""object-sha"", ""url"": ""object-url"" }}"; var httpResponse = new Response( HttpStatusCode.OK, data, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<GitTag>(httpResponse); Assert.NotNull(response.Body); Assert.Equal("tag-name", response.Body.Tag); Assert.Equal("tag-sha", response.Body.Sha); Assert.Equal("tag-url", response.Body.Url); Assert.Equal("tag-message", response.Body.Message); Assert.Equal("tagger-name", response.Body.Tagger.Name); Assert.Equal("tagger-email", response.Body.Tagger.Email); //Adjust expected date for time zone adjustment Assert.Equal(new DateTimeOffset(2011, 06, 17, 21, 53, 35, TimeSpan.Zero), response.Body.Tagger.Date); Assert.Equal(TaggedType.Commit, response.Body.Object.Type); Assert.Equal("object-sha", response.Body.Object.Sha); Assert.Equal("object-url", response.Body.Object.Url); }
public void DeserializesSingleObjectResponseIntoCollectionWithOneItem() { const string data = "{\"name\":\"Haack\"}"; var jsonPipeline = new JsonHttpPipeline(); var httpResponse = new Response( HttpStatusCode.OK, data, new Dictionary<string, string>(), "application/json"); var response = jsonPipeline.DeserializeResponse<List<SomeObject>>(httpResponse); Assert.Equal(1, response.Body.Count); Assert.Equal("Haack", response.Body.First().Name); }
public void IgnoresResponsesNotIdentifiedAsJsonWhenNotDeserializingToString() { const string data = "works"; var httpResponse = new Response( HttpStatusCode.OK, SimpleJson.SerializeObject(data), new Dictionary<string, string>(), "text/html"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<Commit>(httpResponse); Assert.Null(response.Body); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{" + "\"sha\": \"9fb037999f264ba9a7fc6274d15fa3ae2ab98312\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/trees/9fb037999f264ba9a7fc6274d15fa3ae2ab98312\"," + "\"tree\": [" + "{" + "\"path\": \"file.rb\"," + "\"mode\": \"100644\"," + "\"type\": \"blob\"," + "\"size\": 30," + "\"sha\": \"44b4fc6d56897b048c772eb4087f854f46256132\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/44b4fc6d56897b048c772eb4087f854f46256132\"" + "}," + "{" + "\"path\": \"subdir\"," + "\"mode\": \"040000\"," + "\"type\": \"tree\"," + "\"sha\": \"f484d249c660418515fb01c2b9662073663c242e\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/f484d249c660418515fb01c2b9662073663c242e\"" + "}," + "{" + "\"path\": \"exec_file\"," + "\"mode\": \"100755\"," + "\"type\": \"blob\"," + "\"size\": 75," + "\"sha\": \"45b983be36b73c0788dc9cbcb76cbb80fc7bb057\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/git/blobs/45b983be36b73c0788dc9cbcb76cbb80fc7bb057\"" + "}" + "]" + "}"; var httpResponse = new Response( HttpStatusCode.OK, issueResponseJson, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<TreeResponse>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal("9fb037999f264ba9a7fc6274d15fa3ae2ab98312", response.Body.Sha); }
public void CanDeserializeCommitComment() { const string commitCommentResponseJson = "{\"html_url\": \"https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e#commitcomment-1\"," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/comments/1\"," + "\"id\": 1," + "\"body\": \"Me too\"," + "\"path\": \"file1.txt\"," + "\"position\": 4," + "\"line\": 14," + "\"commit_id\": \"6dcb09b5b57875f334f61aebed695e2e4193db5e\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var httpResponse = new Response( HttpStatusCode.OK, commitCommentResponseJson, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<CommitComment>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(commitCommentResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Id); }
public void CanDeserializeIssueComment() { const string issueResponseJson = "{\"id\": 1," + "\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," + "\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," + "\"body\": \"Me too\"," + "\"user\": {" + "\"login\": \"octocat\"," + "\"id\": 1," + "\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," + "\"gravatar_id\": \"somehexcode\"," + "\"url\": \"https://api.github.com/users/octocat\"" + "}," + "\"created_at\": \"2011-04-14T16:00:49Z\"," + "\"updated_at\": \"2011-04-14T16:00:49Z\"" + "}"; var httpResponse = new Response( HttpStatusCode.OK, issueResponseJson, new Dictionary<string, string>(), "application/json"); var jsonPipeline = new JsonHttpPipeline(); var response = jsonPipeline.DeserializeResponse<IssueComment>(httpResponse); Assert.NotNull(response.Body); Assert.Equal(issueResponseJson, response.HttpResponse.Body); Assert.Equal(1, response.Body.Id); }