public void PostsToTheCorrectUrl()
        {
            var connection = Substitute.For<IApiConnection>();
            var client = new GistsClient(connection);

            var updateGist = new GistUpdate();
            updateGist.Description = "my newly updated gist";
            var gistFileUpdate = new GistFileUpdate 
            { 
                NewFileName = "myNewGistTestFile.cs",
                Content = "new GistsClient(connection).Edit();"
            };

            updateGist.Files.Add("myGistTestFile.cs", gistFileUpdate);

            client.Edit("1", updateGist);

            connection.Received().Patch<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), Arg.Any<object>());
        }
Esempio n. 2
0
    public async Task CanCreateEditAndDeleteAGist()
    {
        var newGist = new NewGist { Description = "my new gist", Public = true };

        newGist.Files.Add("myGistTestFile.cs", "new GistsClient(connection).Create();");

        var createdGist = await _fixture.Create(newGist);

        Assert.NotNull(createdGist);
        Assert.Equal(newGist.Description, createdGist.Description);
        Assert.Equal(newGist.Public, createdGist.Public);

        var gistUpdate = new GistUpdate { Description = "my newly updated gist" };
        var gistFileUpdate = new GistFileUpdate
        {
            NewFileName = "myNewGistTestFile.cs",
            Content = "new GistsClient(connection).Edit();"
        };

        gistUpdate.Files.Add("myGistTestFile.cs", gistFileUpdate);

        var updatedGist = await _fixture.Edit(createdGist.Id, gistUpdate);

        Assert.NotNull(updatedGist);
        Assert.Equal(updatedGist.Description, gistUpdate.Description);

        await _fixture.Delete(createdGist.Id);
    }
Esempio n. 3
0
        protected override async System.Threading.Tasks.Task<Gist> SaveGist()
        {
            if (Gist == null)
                throw new InvalidOperationException("Missing Gist context to update!");

            var gistUpdate = new GistUpdate { Description = Description ?? string.Empty };

            foreach (var file in Gist.Files)
                gistUpdate.Files[file.Key] = null;

            foreach (var file in Files)
                gistUpdate.Files[file.Name] = new GistFileUpdate { Content = file.Content };

            using (_alertDialogFactory.Activate("Updating Gist..."))
                return await _sessionService.GitHubClient.Gist.Edit(Gist.Id, gistUpdate);
        }
Esempio n. 4
0
        /// <summary>
        /// Edits a gist
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/gists/#delete-a-gist
        /// </remarks>
        /// <param name="id">The id of the gist</param>
        /// <param name="gistUpdate">The update to the gist</param>
        public Task <Gist> Edit(string id, GistUpdate gistUpdate)
        {
            Ensure.ArgumentNotNull(id, "id");
            Ensure.ArgumentNotNull(gistUpdate, "gistUpdate");

            var filesAsJsonObject = new JsonObject();

            foreach (var kvp in gistUpdate.Files)
            {
                filesAsJsonObject.Add(kvp.Key, new { Content = kvp.Value.Content, Filename = kvp.Value.NewFileName });
            }

            var gist = new
            {
                Description = gistUpdate.Description,
                Files       = filesAsJsonObject
            };

            return(ApiConnection.Patch <Gist>(ApiUrls.Gist(id), gist));
        }
        /// <summary>
        /// Edits a gist
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/gists/#delete-a-gist
        /// </remarks>
        /// <param name="id">The id of the gist</param>
        /// <param name="gistUpdate">The update to the gist</param>
        public Task<Gist> Edit(string id, GistUpdate gistUpdate)
        {
            Ensure.ArgumentNotNull(id, "id");
            Ensure.ArgumentNotNull(gistUpdate, "gistUpdate");

            var filesAsJsonObject = new JsonObject();
            foreach (var kvp in gistUpdate.Files)
            {
                filesAsJsonObject.Add(kvp.Key, new { Content = kvp.Value.Content, Filename = kvp.Value.NewFileName });
            }

            var gist = new
            {
                Description = gistUpdate.Description,
                Files = filesAsJsonObject
            };

            return ApiConnection.Patch<Gist>(ApiUrls.Gist(id), gist);
        }