Пример #1
0
        public void GithubRequestsShouldAffectTheRateLimitRemaining()
        {
            var baseGithubRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.NullAuthProvider.NullAuthProvider(),
                ""
                );

            var response = baseGithubRequest.GetResponse();

            var first = response.RateLimitRemaining;

            response = baseGithubRequest.GetResponse();

            Assert.IsTrue(first > response.RateLimitRemaining,
                          string.Format("Rate Limit should decrease: {0} should be larger than {1}", first, response.RateLimitRemaining));
        }
        public void GithubRequestsShouldAffectTheRateLimitRemaining()
        {
            var baseGithubRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.NullAuthProvider.NullAuthProvider(),
                ""
                );

            var response = baseGithubRequest.GetResponse();

            var first = response.RateLimitRemaining;

            response = baseGithubRequest.GetResponse();

            Assert.IsTrue(first > response.RateLimitRemaining,
                string.Format("Rate Limit should decrease: {0} should be larger than {1}", first, response.RateLimitRemaining));
        }
Пример #3
0
        public void GithubRequestsPagingShouldHavePaginationLink()
        {
            var baseGithubRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.NullAuthProvider.NullAuthProvider(),
                "users/jenkinsci/repos"
                );

            baseGithubRequest.PagingCurrentPage   = 3;
            baseGithubRequest.PagingRequestAmount = 5;

            var response = baseGithubRequest.GetResponse();

            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=4&per_page=5", response.LinkNext);
            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=2&per_page=5", response.LinkPrevious);
            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=1&per_page=5", response.LinkFirst);
            Assert.That(response.LinkLast.StartsWith("https://api.github.com/users/jenkinsci/repos"));
        }
        public void GithubRequestsPagingShouldHavePaginationLink()
        {
            var baseGithubRequest = new Core.GithubRequest(
                new Plugins.LogProviders.NullLogger.NullLogger(true),
                new Plugins.CacheProviders.NullCacher.NullCacher(),
                new Plugins.AuthProviders.NullAuthProvider.NullAuthProvider(),
                "users/jenkinsci/repos"
                );

            baseGithubRequest.PagingCurrentPage = 3;
            baseGithubRequest.PagingRequestAmount = 5;

            var response = baseGithubRequest.GetResponse();

            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=4&per_page=5", response.LinkNext);
            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=2&per_page=5", response.LinkPrevious);
            Assert.AreEqual("https://api.github.com/users/jenkinsci/repos?page=1&per_page=5", response.LinkFirst);
            Assert.That(response.LinkLast.StartsWith("https://api.github.com/users/jenkinsci/repos"));
        }
Пример #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);
        }