コード例 #1
0
    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);
    }
コード例 #2
0
    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);
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    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);
    }
コード例 #5
0
        /// <summary>
        /// Creates a new connection instance used to make requests of the GitHub API.
        /// </summary>
        /// <remarks>
        /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required
        /// </remarks>
        /// <param name="productInformation">
        /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of
        /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems.
        /// </param>
        /// <param name="baseAddress">
        /// The address to point this client to such as https://api.github.com or the URL to a GitHub Enterprise
        /// instance</param>
        /// <param name="credentialStore">Provides credentials to the client when making requests</param>
        /// <param name="httpClient">A raw <see cref="IHttpClient"/> used to make requests</param>
        /// <param name="serializer">Class used to serialize and deserialize JSON requests</param>
        public Connection(
            ProductHeaderValue productInformation,
            Uri baseAddress,
            ICredentialStore credentialStore,
            IHttpClient httpClient,
            IJsonSerializer serializer)
        {
            Ensure.ArgumentNotNull(productInformation, nameof(productInformation));
            Ensure.ArgumentNotNull(baseAddress, nameof(baseAddress));
            Ensure.ArgumentNotNull(credentialStore, nameof(credentialStore));
            Ensure.ArgumentNotNull(httpClient, nameof(httpClient));
            Ensure.ArgumentNotNull(serializer, nameof(serializer));

            if (!baseAddress.IsAbsoluteUri)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "The base address '{0}' must be an absolute URI",
                                        baseAddress), nameof(baseAddress));
            }

            UserAgent      = FormatUserAgent(productInformation);
            BaseAddress    = baseAddress;
            _authenticator = new Authenticator(credentialStore);
            _httpClient    = httpClient;
            _jsonPipeline  = new JsonHttpPipeline(serializer);
        }
コード例 #6
0
            public void LeavesNullBodyAlone()
            {
                var request = new Request { Body = null };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Null(request.Body);
            }
コード例 #7
0
            public void EncodesObjectBody()
            {
                var request = new Request { Body = new { test = "value" } };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal("{\"test\":\"value\"}", request.Body);
            }
コード例 #8
0
            public void SetsRequestAcceptHeader()
            {
                var request = new Request();
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.v3+json; charset=utf-8", request.Headers["Accept"]);
            }
コード例 #9
0
            public void LeavesStreamBodyAlone()
            {
                var stream = new MemoryStream();
                var request = new Request { Body = stream };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Same(stream, request.Body);
            }
コード例 #10
0
            public void LeavesStringBodyAlone()
            {
                const string json = "just some string data";
                var request = new Request { Body = json };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal(json, request.Body);
            }
コード例 #11
0
            public void SetsRequestAcceptHeader()
            {
                var request      = new Request();
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.v3+json; charset=utf-8", request.Headers["Accept"]);
            }
コード例 #12
0
            public void DoesNotChangeExistingAcceptsHeader()
            {
                var request = new Request();
                request.Headers.Add("Accept", "application/vnd.github.manifold-preview; charset=utf-8");
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.manifold-preview; charset=utf-8", request.Headers["Accept"]);
            }
コード例 #13
0
            public void EncodesObjectBody()
            {
                var request = new Request {
                    Body = new { test = "value" }
                };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal("{\"test\":\"value\"}", request.Body);
            }
コード例 #14
0
            public void LeavesNullBodyAlone()
            {
                var request = new Request {
                    Body = null
                };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Null(request.Body);
            }
コード例 #15
0
            public void LeavesStreamBodyAlone()
            {
                var stream  = new MemoryStream();
                var request = new Request {
                    Body = stream
                };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Same(stream, request.Body);
            }
コード例 #16
0
            public void DoesNotChangeExistingAcceptsHeader()
            {
                var request = new Request();

                request.Headers.Add("Accept", "application/vnd.github.manifold-preview; charset=utf-8");
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Contains("Accept", request.Headers.Keys);
                Assert.Equal("application/vnd.github.manifold-preview; charset=utf-8", request.Headers["Accept"]);
            }
コード例 #17
0
            public void LeavesStringBodyAlone()
            {
                const string json    = "just some string data";
                var          request = new Request {
                    Body = json
                };
                var jsonPipeline = new JsonHttpPipeline();

                jsonPipeline.SerializeRequest(request);

                Assert.Equal(json, request.Body);
            }
コード例 #18
0
            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);
            }
コード例 #19
0
            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);
            }
コード例 #20
0
            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);
            }
コード例 #21
0
            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);
            }
コード例 #22
0
            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);
            }
コード例 #23
0
            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);
            }
コード例 #24
0
            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);
            }
コード例 #25
0
            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);
            }
コード例 #26
0
ファイル: TreesClientTests.cs プロジェクト: rms81/octokit.net
        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);
        }
コード例 #27
0
        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);
        }
コード例 #28
0
ファイル: BlobClientTests.cs プロジェクト: x5a/octokit.net
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }
コード例 #31
0
        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);
        }
コード例 #32
0
            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);
            }
コード例 #33
0
            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);
            }
コード例 #34
0
        /// <summary>
        /// Creates a new connection instance used to make requests of the GitHub API.
        /// </summary>
        /// <remarks>
        /// See more information regarding User-Agent requirements here: https://developer.github.com/v3/#user-agent-required
        /// </remarks>
        /// <param name="productInformation">
        /// The name (and optionally version) of the product using this library, the name of your GitHub organization, or your GitHub username (in that order of preference). This is sent to the server as part of
        /// the user agent for analytics purposes, and used by GitHub to contact you if there are problems.
        /// </param>
        /// <param name="baseAddress">
        /// The address to point this client to such as https://api.github.com or the URL to a GitHub Enterprise
        /// instance</param>
        /// <param name="credentialStore">Provides credentials to the client when making requests</param>
        /// <param name="httpClient">A raw <see cref="IHttpClient"/> used to make requests</param>
        /// <param name="serializer">Class used to serialize and deserialize JSON requests</param>
        public Connection(
            ProductHeaderValue productInformation,
            Uri baseAddress,
            IHttpClient httpClient,
            string apiToken)
        {
            Ensure.ArgumentNotNull(productInformation, nameof(productInformation));
            Ensure.ArgumentNotNull(baseAddress, nameof(baseAddress));
            Ensure.ArgumentNotNull(httpClient, nameof(httpClient));
            Ensure.ArgumentNotNull(apiToken, nameof(apiToken));

            if (!baseAddress.IsAbsoluteUri)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "The base address '{0}' must be an absolute URI",
                                        baseAddress), "baseAddress");
            }

            UserAgent     = FormatUserAgent(productInformation);
            BaseAddress   = baseAddress;
            ApiToken      = apiToken;
            _httpClient   = httpClient;
            _jsonPipeline = new JsonHttpPipeline();
        }
コード例 #35
0
    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);
    }
コード例 #36
0
        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);
        }
コード例 #37
0
    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);
    }
コード例 #38
0
            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);
            }
コード例 #39
0
            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);
            }
コード例 #40
0
            public void EnsuresArguments()
            {
                var jsonPipeline = new JsonHttpPipeline();

                Assert.Throws<ArgumentNullException>(() => jsonPipeline.SerializeRequest(null));
            }
コード例 #41
0
        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);
        }
コード例 #42
0
            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);
            }
コード例 #43
0
            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);
            }
コード例 #44
0
            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);
            }
コード例 #45
0
            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);
            }
コード例 #46
0
 public BaseApiClient(string bearerToken, string accountId)
 {
     this.bearerToken = bearerToken ?? throw new ArgumentNullException(nameof(bearerToken));
     this.accountId   = accountId;
     jsonPipeline     = new JsonHttpPipeline();
 }
コード例 #47
0
            public void EnsuresArguments()
            {
                var jsonPipeline = new JsonHttpPipeline();

                Assert.Throws <ArgumentNullException>(() => jsonPipeline.SerializeRequest(null));
            }
コード例 #48
0
    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);
    }
コード例 #49
0
            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);
            }