示例#1
0
        async public Task AuthorizeWithGistAndUserEmailScopes()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest(new[] { Scopes.Gist, Scopes.UserEmail });

            Assert.IsTrue(api.Context.Authorization.Scopes.Matches(new[] { Scopes.Gist, Scopes.UserEmail }));
        }
示例#2
0
        async public Task SearchRepositories()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var repoList = await api.Search.Repositories("IronGitHub");

            var repo = repoList.Repositories.FirstOrDefault(x => x.Name == "IronGitHub");

            Assert.IsNotNull(repo);

            Assert.AreEqual(new DateTime(2013, 5, 26, 2, 25, 58, DateTimeKind.Utc), repo.Created);
            Assert.AreEqual(new DateTime(2013, 5, 26, 2, 25, 58, DateTimeKind.Utc), repo.CreatedAt);
            Assert.AreEqual("C# GitHub Api", repo.Description);
            Assert.AreEqual(1, repo.Followers);
            Assert.AreEqual(false, repo.Fork);
            Assert.AreEqual(0, repo.Forks);
            Assert.AreEqual(true, repo.HasDownloads);
            Assert.AreEqual(true, repo.HasIssues);
            Assert.AreEqual(true, repo.HasWiki);
            Assert.AreEqual(null, repo.Homepage);
            Assert.AreEqual("C#", repo.Language);
            Assert.AreEqual("IronGitHub", repo.Name);
            Assert.AreEqual(2, repo.OpenIssues);
            Assert.AreEqual("in2bits", repo.Owner);
            Assert.AreEqual(false, repo.Private);
            Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 8, DateTimeKind.Utc) <= repo.Pushed);
            Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 8, DateTimeKind.Utc) <= repo.PushedAt);
            Assert.IsTrue(0 < repo.Score);
            Assert.IsTrue(260 <= repo.Size);
            Assert.AreEqual("repo", repo.Type);
            Assert.AreEqual("https://github.com/in2bits/IronGitHub", repo.Url);
            Assert.AreEqual("in2bits", repo.Username);
            Assert.IsTrue(1 <= repo.Watchers);
        }
示例#3
0
        async public Task SearchUsers()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var userList = await api.Search.Users("timerickson");

            var user = userList.Users.FirstOrDefault(x => x.Id == "user-57726");

            Assert.IsNotNull(user);

            Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.Created);
            Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.CreatedAt);
            Assert.AreEqual(4, user.Followers);
            Assert.AreEqual(4, user.FollowersCount);
            Assert.AreEqual("Tim Erickson", user.FullName);
            Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", user.GravatarId);
            Assert.AreEqual("user-57726", user.Id);
            Assert.AreEqual("JavaScript", user.Language);
            Assert.AreEqual("Seattle, WA", user.Location);
            Assert.AreEqual("timerickson", user.Login);
            Assert.AreEqual("Tim Erickson", user.Name);
            Assert.AreEqual(4, user.PublicRepoCount);
            Assert.AreEqual(4, user.Repos);
            Assert.IsTrue(0 < user.Score);
            Assert.AreEqual("user", user.Type);
            Assert.AreEqual("timerickson", user.Username);
        }
示例#4
0
        async public Task PatchGist()
        {
            var files = new Dictionary <string, string>
            {
                { "theAnswer", "42" },
                { "the Question", "I dunno" }
            };
            var api = GitHubApi.Create();
            await api.in2bitstest(new[] { Scopes.Gist });

            var gist = await api.Gists.New(files);

            Assert.AreEqual("42", gist.Files["theAnswer"].Content);
            var patch     = new Gist.EditGistPost(gist);
            var patchFile = patch.Files["theAnswer"];

            patchFile.Filename          = "theWrongAnswer";
            patchFile.Content           = "43";
            patch.Files["the Question"] = null;
            var patchedGist = await api.Gists.Edit(patch);

            Assert.AreEqual(1, patchedGist.Files.Count);
            var file = patchedGist.Files["theWrongAnswer"];

            Assert.IsNotNull(file);
            Assert.AreEqual("43", file.Content);
            Assert.AreEqual(gist.Id, patchedGist.Id);
        }
示例#5
0
        public void FixtureSetup()
        {
            _config = new Dictionary <string, string>()
            {
                { "url", this.PostUrl }, { "content-type", "json" }
            };
            _events = new[] { SupportedEvents.Push };

            Api = GitHubApi.Create();

            Authorize(new[] { Scopes.Repo })
            .ContinueWith(t =>
                          this.ClearHooks())
            .ContinueWith(
                t =>
            {
                Task.Delay(10000);
                _tempHook =
                    Api.Hooks.Create(
                        _testUsername,
                        _testRepo,
                        new HookBase()
                {
                    Name     = HookName.Web,
                    IsActive = true,
                    Events   = _events,
                    Config   = _config
                }).Result;
            }).Wait();
        }
示例#6
0
        async public Task GetGist()
        {
            const long id  = 5731704;
            var        api = GitHubApi.Create();
            await api.in2bitstest();

            var gist = await api.Gists.Get(id);

            Assert.AreEqual("https://api.github.com/gists/5731704/comments", gist.CommentsUrl);
            Assert.AreEqual("https://api.github.com/gists/5731704/commits", gist.CommitsUrl);
            Assert.AreEqual(new DateTime(2013, 6, 7, 19, 22, 52, DateTimeKind.Utc), gist.CreatedAt);
            Assert.IsNull(gist.Description);
            Assert.AreEqual(2, gist.Files.Count);
            Assert.IsTrue(gist.Files.ContainsKey("theAnswer"));
            var file = gist.Files["theAnswer"];

            Assert.AreEqual("42", file.Content);
            Assert.AreEqual("theAnswer", file.Filename);
            Assert.IsNull(file.Language);
            Assert.AreEqual("https://gist.github.com/raw/5731704/f70d7bba4ae1f07682e0358bd7a2068094fc023b/theAnswer", file.RawUrl);
            Assert.AreEqual(2, file.Size);
            Assert.AreEqual("text/plain", file.Type);
            Assert.AreEqual(0, gist.Forks.Count());
            Assert.AreEqual("https://api.github.com/gists/5731704/forks", gist.ForksUrl);
            Assert.AreEqual("https://gist.github.com/5731704.git", gist.GitPullUrl);
            Assert.AreEqual("https://gist.github.com/5731704.git", gist.GitPushUrl);
            Assert.AreEqual(1, gist.History.Count());
            Assert.AreEqual("https://gist.github.com/5731704", gist.HtmlUrl);
            Assert.AreEqual(id, gist.Id);
            Assert.AreEqual(true, gist.Public);
            Assert.IsTrue(gist.CreatedAt <= gist.UpdatedAt);
            Assert.AreEqual("https://api.github.com/gists/5731704", gist.Url);
            Assert.IsNull(gist.User);
        }
示例#7
0
        async public Task SearchIssues()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var text      = "TEST Open Issue";
            var issueList = await api.Search.Issues("in2bits", "IronGitHub", IssueStates.Open, text);

            Assert.IsTrue(1 <= issueList.Issues.Count(x => x.Title == text));
            var issue = issueList.Issues.First();

            Assert.AreEqual("This is a test issue that should remain open.", issue.Body);
            Assert.AreEqual(1, issue.Comments);
            Assert.AreEqual(new DateTime(2013, 6, 17, 23, 30, 44, DateTimeKind.Utc), issue.CreatedAt);
            Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", issue.GravatarId);
            Assert.AreEqual("https://github.com/in2bits/IronGitHub/issues/2", issue.HtmlUrl);
            Assert.AreEqual(2, issue.Labels.Count());
            Assert.AreEqual("TEST", issue.Labels.ElementAt(0));
            Assert.AreEqual("TEST2", issue.Labels.ElementAt(1));
            Assert.AreEqual(2, issue.Number);
            Assert.AreEqual(1, issue.Position);
            Assert.AreEqual(IssueStates.Open, issue.State);
            Assert.AreEqual(text, issue.Title);
            Assert.AreEqual(new DateTime(2013, 6, 19, 19, 42, 0, DateTimeKind.Utc), issue.UpdatedAt);
            Assert.AreEqual("timerickson", issue.User);
            Assert.AreEqual(0, issue.Votes);
        }
示例#8
0
        async public Task GetAuthenticatedUser()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var user = await api.Users.GetAuthenticatedUser();
        }
示例#9
0
        async public Task SearchEmail()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var email   = "*****@*****.**";
            var results = await api.Search.Email(email);

            Assert.IsTrue(results.Users.Any());
            var user = results.Users.First();

            Assert.AreEqual("http://myxls.in2bits.org", user.Blog);
            Assert.AreEqual("", user.Company);
            Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.Created);
            Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.CreatedAt);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(4, user.FollowersCount);
            Assert.AreEqual(3, user.FollowingCount);
            Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", user.GravatarId);
            Assert.AreEqual(57726, user.Id);
            Assert.AreEqual("Seattle, WA", user.Location);
            Assert.AreEqual("timerickson", user.Login);
            Assert.AreEqual("Tim Erickson", user.Name);
            Assert.IsTrue(1 <= user.PublicGistCount);
            Assert.AreEqual(4, user.PublicRepoCount);
            Assert.AreEqual("User", user.Type);
        }
示例#10
0
        async public Task ListRepositoriesSince10()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var repos = await api.Repositories.List(10);

            Assert.IsTrue(10 <= repos.ElementAt(0).Id);
        }
示例#11
0
        async public Task GetIssue()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var issue = await api.Issues.Get("in2bits", "IronGitHub", 3);

            AssertSecondOpenIssue(issue);
        }
示例#12
0
        async public Task ListRepositores()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var repos = await api.Repositories.List();

            Assert.IsTrue(1 < repos.Count());
        }
示例#13
0
        async public Task AuthorizeWithCredential()
        {
            var api = GitHubApi.Create();

            Assert.AreEqual(Authorization.Anonymous, api.Context.Authorization);
            await api.in2bitstest();

            Assert.IsNotNull(api.Context.Authorization);
        }
示例#14
0
 async public Task CreateNewAnonymousGist()
 {
     var files = new Dictionary <string, string>
     {
         { "theAnswer", "42" },
         { "the Question", "I dunno" }
     };
     var api  = GitHubApi.Create();
     var gist = await api.Gists.New(files);
 }
示例#15
0
        async public Task GetAll()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest(new[] { Scopes.Repo, Scopes.PublicRepo });

            //await api.in2bitstest();
            var issueList = await api.Issues.Get();

            Assert.IsTrue(1 <= issueList.Count());
            var issue = issueList.First();

            AssertSecondOpenIssue(issue);
        }
示例#16
0
        async public Task CreateAndDeleteUserGist()
        {
            var files = new Dictionary <string, string>
            {
                { "theAnswer", "42" },
                { "the Question", "I dunno" }
            };
            var api = GitHubApi.Create();
            await api.in2bitstest(new [] { Scopes.Gist });

            var gist = await api.Gists.New(files);

            await api.Gists.Delete(gist);
        }
示例#17
0
        public IDictionary <string, GistFile> GetGist(string gistId)
        {
            var api = GitHubApi.Create();

            //var gists =  api.Gists.Get(gistId).GetAwaiter().GetResult();
            var task = Task.Run(async() =>
            {
                var result = await api.Gists.Get(gistId);
                return(result.Files);
            });

            task.Wait();
            return(task.Result);
        }
示例#18
0
        async public Task GetOrganization()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest(new[] { Scopes.Repo });

            var organization = await api.Organizations.GetOrganization("in2bits");

            Assert.AreEqual("in2bits.org", organization.Name);
            Assert.AreEqual(null, organization.Company);
            Assert.AreEqual(null, organization.Blog);
            Assert.AreEqual(null, organization.Location);
            Assert.AreEqual("*****@*****.**", organization.Email);
            Assert.AreEqual(5, organization.PublicRepositoryCount);
            Assert.AreEqual(0, organization.PublicGistCount);
            Assert.AreEqual(0, organization.FollowersCount);
            Assert.AreEqual(0, organization.FollowingCount);
            Assert.AreEqual(new DateTime(2013, 5, 26, 0, 11, 14, DateTimeKind.Utc), organization.CreatedAt);
            Assert.AreEqual("Organization", organization.Type);
            Assert.AreEqual("4529897", organization.Id);
            Assert.AreEqual("https://secure.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-org-420.png", organization.AvatarUrl);
        }
示例#19
0
        async public Task Get57726()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var user = await api.Users.Get(57726);

            Assert.AreEqual("https://secure.gravatar.com/avatar/e9fbbfd2de96fdb0cec592a4b6792f0e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png", user.AvatarUrl);
            Assert.AreEqual(null, user.Bio);
            Assert.AreEqual("http://myxls.in2bits.org", user.Blog);
            Assert.AreEqual("", user.Company);
            Assert.AreEqual(new DateTime(2009, 2, 25, 3, 57, 50, DateTimeKind.Utc), user.CreatedAt);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual("https://api.github.com/users/timerickson/events{/privacy}", user.EventsUrl);
            Assert.AreEqual(4, user.Followers);
            Assert.AreEqual("https://api.github.com/users/timerickson/followers", user.FollowersUrl);
            Assert.AreEqual(3, user.Following);
            Assert.AreEqual("https://api.github.com/users/timerickson/following{/other_user}", user.FollowingUrl);
            Assert.AreEqual("https://api.github.com/users/timerickson/gists{/gist_id}", user.GistsUrl);
            Assert.AreEqual("e9fbbfd2de96fdb0cec592a4b6792f0e", user.GravatarId);
            Assert.AreEqual(false, user.Hireable);
            Assert.AreEqual("https://github.com/timerickson", user.HtmlUrl);
            //Assert.AreEqual(57726, user.Id);
            Assert.AreEqual("Seattle, WA", user.Location);
            Assert.AreEqual("timerickson", user.Login);
            Assert.AreEqual("Tim Erickson", user.Name);
            Assert.AreEqual("https://api.github.com/users/timerickson/orgs", user.OrganizationsUrl);
            Assert.IsTrue(1 <= user.PublicGists);
            Assert.AreEqual(4, user.PublicRepos);
            Assert.AreEqual("https://api.github.com/users/timerickson/received_events", user.ReceivedEventsUrl);
            Assert.AreEqual("https://api.github.com/users/timerickson/repos", user.ReposUrl);
            Assert.AreEqual("https://api.github.com/users/timerickson/starred{/owner}{/repo}", user.StarredUrl);
            Assert.AreEqual("https://api.github.com/users/timerickson/subscriptions", user.SubscriptionsUrl);
            Assert.AreEqual("User", user.Type);
            Assert.IsTrue(new DateTime(2013, 5, 27, 7, 27, 32, DateTimeKind.Utc) <= user.UpdatedAt);
            Assert.AreEqual("https://api.github.com/users/timerickson", user.Url);
        }
示例#20
0
 //[SetUp]
 public void CreateGitHubApi()
 {
     Api = GitHubApi.Create();
 }
示例#21
0
        async public Task GetRepository()
        {
            var api = GitHubApi.Create();
            await api.in2bitstest();

            var repo = await api.Repositories.Get("in2bits", "IronGitHub");

            Assert.IsNotNull(repo);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/{archive_format}{/ref}", repo.ArchiveUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/assignees{/user}", repo.AssigneesUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/git/blobs{/sha}", repo.BlobsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/branches{/branch}", repo.BranchesUrl);
            Assert.AreEqual("https://github.com/in2bits/IronGitHub.git", repo.CloneUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/collaborators{/collaborator}", repo.CollaboratorsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/comments{/number}", repo.CommentsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/commits{/sha}", repo.CommitsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/compare/{base}...{head}", repo.CompareUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/contents/{+path}", repo.ContentsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/contributors", repo.ContributorsUrl);
            Assert.AreEqual(new DateTime(2013, 5, 26, 2, 25, 58, DateTimeKind.Utc), repo.CreatedAt);
            Assert.AreEqual("master", repo.DefaultBranch);
            Assert.AreEqual("C# GitHub Api", repo.Description);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/downloads", repo.DownloadsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/events", repo.EventsUrl);
            Assert.AreEqual(false, repo.Fork);
            Assert.AreEqual(0, repo.Forks);
            Assert.AreEqual(0, repo.ForksCount);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/forks", repo.ForksUrl);
            Assert.AreEqual("in2bits/IronGitHub", repo.FullName);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/git/commits{/sha}", repo.GitCommitsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/git/refs{/sha}", repo.GitRefsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/git/tags{/sha}", repo.GitTagsUrl);
            Assert.AreEqual("git://github.com/in2bits/IronGitHub.git", repo.GitUrl);
            Assert.AreEqual(true, repo.HasDownloads);
            Assert.AreEqual(true, repo.HasIssues);
            Assert.AreEqual(true, repo.HasWiki);
            Assert.AreEqual(null, repo.Homepage);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/hooks", repo.HooksUrl);
            Assert.AreEqual("https://github.com/in2bits/IronGitHub", repo.HtmlUrl);
            Assert.AreEqual(10292608, repo.Id);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/issues/comments/{number}", repo.IssueCommentUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/issues/events{/number}", repo.IssueEventsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/issues{/number}", repo.IssuesUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/keys{/key_id}", repo.KeysUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/labels{/name}", repo.LabelsUrl);
            Assert.AreEqual("C#", repo.Language);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/languages", repo.LanguagesUrl);
            Assert.AreEqual("master", repo.MasterBranch);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/merges", repo.MergesUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/milestones{/number}", repo.MilestonesUrl);
            Assert.AreEqual(null, repo.MirrorUrl);
            Assert.AreEqual("IronGitHub", repo.Name);
            Assert.AreEqual(0, repo.NetworkCount);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/notifications{?since,all,participating}", repo.NotificationsUrl);
            Assert.AreEqual(2, repo.OpenIssues);
            Assert.AreEqual(2, repo.OpenIssuesCount);
            Assert.IsNotNull(repo.Permissions);
            var perms = repo.Permissions;

            Assert.AreEqual(false, perms.Admin);
            Assert.AreEqual(true, perms.Pull);
            Assert.AreEqual(false, perms.Push);
            Assert.AreEqual(false, repo.Private);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/pulls{/number}", repo.PullsUrl);
            Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 8, DateTimeKind.Utc) <= repo.PushedAt);
            Assert.IsTrue(260 <= repo.Size);
            Assert.AreEqual("[email protected]:in2bits/IronGitHub.git", repo.SshUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/stargazers", repo.StargazersUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/statuses/{sha}", repo.StatusesUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/subscribers", repo.SubscribersUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/subscription", repo.SubscriptionUrl);
            Assert.AreEqual("https://github.com/in2bits/IronGitHub", repo.SvnUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/tags", repo.TagsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/teams", repo.TeamsUrl);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub/git/trees{/sha}", repo.TreesUrl);
            Assert.IsTrue(new DateTime(2013, 6, 4, 0, 13, 11) <= repo.UpdatedAt);
            Assert.AreEqual("https://api.github.com/repos/in2bits/IronGitHub", repo.Url);
            Assert.IsTrue(1 <= repo.Watchers);
            Assert.IsTrue(1 <= repo.WatchersCount);
        }
示例#22
0
        public void GitHubApiCreate()
        {
            var api = GitHubApi.Create();

            api.Should().BeOfType <GitHubApi>();
        }