コード例 #1
0
        public void DefaultCreateAuthorizationRequestBodySerializesAsEmptyJsonObject()
        {
            var    body       = new CreateAuthorizationRequestBody();
            string serialized = JsonConvert.SerializeObject(body);

            Assert.Matches("^\\s*{\\s*}\\s*$", serialized);
        }
コード例 #2
0
        public void AuthorizationRequestBodyWithNoteSerializesNoteAsProperty()
        {
            var body = new CreateAuthorizationRequestBody
            {
                Note = "this is a note"
            };

            string serialized = JsonConvert.SerializeObject(body);

            Assert.Matches("^\\s*{\\s*\"note\"\\s*:\\s*\"this is a note\"\\s*}\\s*$", serialized);
        }
コード例 #3
0
        public void AuthorizationRequestBodyWithScopesSerializesThemAsArray()
        {
            var body = new CreateAuthorizationRequestBody
            {
                Scopes = new List <string> {
                    "repo", "user", "gist"
                }
            };

            string serialized = JsonConvert.SerializeObject(body);

            Assert.Matches("\\{", "\"scopes\"", ":", "\\[", "\"repo\"", ",", "\"user\"", ",", "\"gist\"", "]",
                           serialized);
        }
コード例 #4
0
        public Authorization CreateAuthorization(string note, string noteUri, IEnumerable <string> scopes)
        {
            var request = new CreateAuthorizationRequestBody {
                Note = note, NoteUrl = noteUri
            };

            if (scopes != null)
            {
                request.Scopes = new List <string>(scopes);
            }

            HttpResponseMessage response = GetResponse("/authorizations", HttpMethod.Post, request);
            AuthorizationData   authData = response.Content.ReadAsAsync <AuthorizationData>().Result;

            return(new Authorization(authData));
        }
コード例 #5
0
        public void AuthorizationRequestBodyWithNoteUrlAndScopesSerializesAll()
        {
            var body = new CreateAuthorizationRequestBody
            {
                Note    = "this is a note",
                NoteUrl = "http://some/app/url",
                Scopes  = new List <string> {
                    "repo", "gist"
                }
            };

            string serialized = JsonConvert.SerializeObject(body);

            Assert.Matches("\"note\"", ":", "\"" + body.Note + "\"", serialized);
            Assert.Matches("\"note_url\"", ":", "\"" + body.NoteUrl + "\"", serialized);
            Assert.Matches("\"scopes\"", ":", "\\[", "\"repo\"", ",", "\"gist\"", "]", serialized);
        }