public void TestCreateEditAndDelete()
        {
            var gistModel = GetAuthenticatedGistApi();

            var gistFiles = new Dictionary<string, Core.Models.GistFileForCreation>
                                {
                                    {
                                        "fileName.txt", new Core.Models.GistFileForCreation
                                                            {
                                                                content = System.Guid.NewGuid().ToString()
                                                            }
                                        }
                                };


            var toCreate = new Core.Models.GistToCreateOrEdit
            {
                description = "test gist",
                @public = false,
                files = gistFiles
            };

            var createdGist = gistModel.Create(toCreate);

            Assert.IsNotNull(createdGist);
            Assert.AreEqual(createdGist.description, toCreate.description);
            Assert.AreEqual(createdGist.files["fileName.txt"].content, toCreate.files["fileName.txt"].content);

            toCreate.files["fileName.txt"].content = System.Guid.NewGuid().ToString();

            var editedGist = gistModel.Edit(createdGist.id, toCreate);

            Assert.AreEqual(editedGist.files["fileName.txt"].content, toCreate.files["fileName.txt"].content);
            Assert.AreNotEqual(editedGist.files["fileName.txt"].content, createdGist.files["fileName.txt"].content);
            Assert.AreEqual(editedGist.id, createdGist.id);

            gistModel.Delete(editedGist.id);
        }
Example #2
0
        public void TestCreateEditAndDelete()
        {
            var gistModel = GetAuthenticatedGistApi();

            var gistFiles = new Dictionary <string, Core.Models.GistFileForCreation>
            {
                {
                    "fileName.txt", new Core.Models.GistFileForCreation
                    {
                        content = System.Guid.NewGuid().ToString()
                    }
                }
            };


            var toCreate = new Core.Models.GistToCreateOrEdit
            {
                description = "test gist",
                @public     = false,
                files       = gistFiles
            };

            var createdGist = gistModel.Create(toCreate);

            Assert.IsNotNull(createdGist);
            Assert.AreEqual(createdGist.description, toCreate.description);
            Assert.AreEqual(createdGist.files["fileName.txt"].content, toCreate.files["fileName.txt"].content);

            toCreate.files["fileName.txt"].content = System.Guid.NewGuid().ToString();

            var editedGist = gistModel.Edit(createdGist.id, toCreate);

            Assert.AreEqual(editedGist.files["fileName.txt"].content, toCreate.files["fileName.txt"].content);
            Assert.AreNotEqual(editedGist.files["fileName.txt"].content, createdGist.files["fileName.txt"].content);
            Assert.AreEqual(editedGist.id, createdGist.id);

            gistModel.Delete(editedGist.id);
        }
Example #3
0
        private static Core.Models.Gist CreateGist(Core.API.Gist gistApi)
        {
            var gistFiles = new Dictionary <string, Core.Models.GistFileForCreation>
            {
                {
                    "fileName.txt", new Core.Models.GistFileForCreation
                    {
                        content = System.Guid.NewGuid().ToString()
                    }
                }
            };


            var toCreate = new Core.Models.GistToCreateOrEdit
            {
                description = "test gist",
                @public     = false,
                files       = gistFiles
            };

            var createdGist = gistApi.Create(toCreate);

            return(createdGist);
        }
        private static Core.Models.Gist CreateGist(Core.API.Gist gistApi)
        {
            var gistFiles = new Dictionary<string, Core.Models.GistFileForCreation>
                                {
                                    {
                                        "fileName.txt", new Core.Models.GistFileForCreation
                                                            {
                                                                content = System.Guid.NewGuid().ToString()
                                                            }
                                        }
                                };


            var toCreate = new Core.Models.GistToCreateOrEdit
            {
                description = "test gist",
                @public = false,
                files = gistFiles
            };

            var createdGist = gistApi.Create(toCreate);

            return createdGist;
        }
Example #5
0
        public void GithubRequestWithInput()
        {
            var gistFiles = new Dictionary <string, GithubSharp.Core.Models.GistFileForCreation>
            {
                {
                    "fileName.txt", new Core.Models.GistFileForCreation
                    {
                        content = "bla bla"
                    }
                }
            };

            var gistToCreate = new Core.Models.GistToCreateOrEdit
            {
                @public     = true,
                description = "testGist",
                files       = gistFiles
            };
            var baseGithubRequest = new Core.GithubRequestWithInputAndReturnType
                                    <GithubSharp.Core.Models.GistToCreateOrEdit, GithubSharp.Core.Models.Gist>(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
                    (TestSettings.Username, TestSettings.Password),
                "gists",
                GithubSharpHttpVerbs.Post,
                gistToCreate
                );

            GithubSharp.Core.IGithubResponseWithReturnType <GithubSharp.Core.Models.Gist> response = null;

            try
            {
                response = baseGithubRequest.GetResponseWithReturnType();
            }
            catch (Exception err)
            {
                if (err is GithubSharp.Core.GithubException)
                {
                    var githuberr = err as GithubSharp.Core.GithubException;
                    Assert.Fail("StatusCode : {0}, StatusText : {1}, Message : {2}",
                                githuberr.StatusCode, githuberr.StatusText, githuberr.GithubErrorResult.message);
                    return;
                }
                Assert.Fail(err.Message);
                return;
            }
            Assert.IsNotNull(response.Result);
            Assert.AreEqual(response.Result.description, gistToCreate.description);

            Assert.AreEqual(response.Result.files["fileName.txt"].content, gistToCreate.files["fileName.txt"].content);

            //Let's clean up
            var gistDeleteRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
                    (TestSettings.Username, TestSettings.Password),
                string.Format("gists/{0}", response.Result.id),
                GithubSharpHttpVerbs.Delete

                );

            var deleteResult = gistDeleteRequest.GetResponse();

            Assert.IsNotNull(deleteResult);

            Assert.AreEqual(deleteResult.StatusCode, 204);
        }
        public void GithubRequestWithInput()
        {
            var gistFiles = new Dictionary<string, GithubSharp.Core.Models.GistFileForCreation>
                                {
                                    {
                                        "fileName.txt", new Core.Models.GistFileForCreation
                                                            {
                                                                content = "bla bla"
                                                            }
                                        }
                                };

            var gistToCreate = new Core.Models.GistToCreateOrEdit
            {
                @public = true,
                description = "testGist",
                files = gistFiles
            };
            var baseGithubRequest = new Core.GithubRequestWithInputAndReturnType
                    <GithubSharp.Core.Models.GistToCreateOrEdit, GithubSharp.Core.Models.Gist>(
                        new Plugins.LogProviders.NullLogger.NullLogger(true),
                        new Plugins.CacheProviders.NullCacher.NullCacher(),
                        new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
                                (TestSettings.Username, TestSettings.Password),
                        "gists",
                        GithubSharpHttpVerbs.Post,
                        gistToCreate
                );

            GithubSharp.Core.IGithubResponseWithReturnType<GithubSharp.Core.Models.Gist> response = null;

            try
            {
                response = baseGithubRequest.GetResponseWithReturnType();
            }
            catch (Exception err)
            {
                if (err is GithubSharp.Core.GithubException)
                {
                    var githuberr = err as GithubSharp.Core.GithubException;
                    Assert.Fail("StatusCode : {0}, StatusText : {1}, Message : {2}",
                        githuberr.StatusCode, githuberr.StatusText, githuberr.GithubErrorResult.message);
                    return;
                }
                Assert.Fail(err.Message);
                return;
            }
            Assert.IsNotNull(response.Result);
            Assert.AreEqual(response.Result.description, gistToCreate.description);

            Assert.AreEqual(response.Result.files["fileName.txt"].content, gistToCreate.files["fileName.txt"].content);

            //Let's clean up 
            var gistDeleteRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                        new Plugins.CacheProviders.NullCacher.NullCacher(),
                        new Plugins.AuthProviders.UserPasswordAuthProvider.UserPasswordAuthProvider
                                (TestSettings.Username, TestSettings.Password),
                        string.Format("gists/{0}", response.Result.id),
                        GithubSharpHttpVerbs.Delete

                );

            var deleteResult = gistDeleteRequest.GetResponse();

            Assert.IsNotNull(deleteResult);

            Assert.AreEqual(deleteResult.StatusCode, 204);
        }