public void DefaultCreateAuthorizationRequestBodySerializesAsEmptyJsonObject() { var body = new CreateAuthorizationRequestBody(); string serialized = JsonConvert.SerializeObject(body); Assert.Matches("^\\s*{\\s*}\\s*$", serialized); }
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); }
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); }
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)); }
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); }