예제 #1
0
            public async Task EnsuresNonNullArguments()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssueCommentsClient(connection);

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(null, "name"));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForRepository(1, null));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("", "name"));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("owner", ""));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));

                await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));
            }
        public async Task EnsuresArgumentsNotNull()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new IssueCommentsClient(connection);

            await AssertEx.Throws <ArgumentNullException>(async() => await client.GetAllForRepository(null, "name"));

            await AssertEx.Throws <ArgumentException>(async() => await client.GetAllForRepository("", "name"));

            await AssertEx.Throws <ArgumentNullException>(async() => await client.GetAllForRepository("owner", null));

            await AssertEx.Throws <ArgumentException>(async() => await client.GetAllForRepository("owner", ""));
        }
            public async Task EnsuresArgumentsNotNull()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssueCommentsClient(connection);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", ApiOptions.None));
                await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", ApiOptions.None));
            }
        public void RequestsCorrectUrl()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new IssueCommentsClient(connection);

            client.GetAllForRepository("fake", "repo");

            connection.Received().GetAll <IssueComment>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"));
        }
예제 #5
0
        private static async Task GetComments(GitHubClient client, StringBuilder content, DateTime fromDate, DateTime toDate, bool isSortByCreated, HashSet <int> commentsAdded)
        {
            IssueCommentsClient issueCommentsClient = new IssueCommentsClient(new ApiConnection(client.Connection));
            IssueCommentRequest commentRequest      = new IssueCommentRequest()
            {
                Since     = fromDate,
                Direction = SortDirection.Ascending,
                Sort      = isSortByCreated ? IssueCommentSort.Created : IssueCommentSort.Updated
            };

            ApiOptions commentOptions = new ApiOptions()
            {
                PageSize  = MaxPerPage,
                PageCount = 1,
                StartPage = 1
            };

            bool hasMoreComments = true;

            while (hasMoreComments)
            {
                var comments = await issueCommentsClient.GetAllForRepository(RepoOwner, RepoName, commentRequest, commentOptions);

                foreach (var comment in comments)
                {
                    bool isInDateRange = isSortByCreated ? (comment.CreatedAt >= fromDate && comment.CreatedAt <= toDate) : (comment.UpdatedAt >= fromDate && comment.UpdatedAt <= toDate);
                    if (isInDateRange)
                    {
                        if (!commentsAdded.Contains(comment.Id))
                        {
                            commentsAdded.Add(comment.Id);

                            bool   isInternal = KnownInternalContributors.Contains(comment.User.Login);
                            string issueType  = "Comment";
                            string relation   = StoreAndGetIssueRelation(isInternal, issueType);

                            content.AppendLine(comment.User.Login + "\t" + comment.HtmlUrl + "\t" + "NA" + "\t" + comment.AuthorAssociation + "\t" + issueType + "\t" + relation + "\t" + comment.CreatedAt + "\t" + comment.UpdatedAt);
                            contributors.Add(comment.User.Login);
                        }
                    }
                    else
                    {
                        // Outside date range
                        hasMoreComments = false;
                        break; // from inner loop
                    }
                }
                if (hasMoreComments && comments.Count == MaxPerPage)
                {
                    commentOptions.StartPage++;
                }
                else
                {
                    hasMoreComments = false;
                }
            }
        }
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssueCommentsClient(connection);

                await client.GetAllForRepository(1);

                connection.Received().GetAll<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues/comments"),
                    Arg.Any<Dictionary<string, string>>(),
                    "application/vnd.github.squirrel-girl-preview",
                    Args.ApiOptions);
            }
            public async Task RequestsCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssueCommentsClient(connection);

                await client.GetAllForRepository(1);

                connection.Received().GetAll <IssueComment>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/issues/comments"),
                                                            Arg.Any <Dictionary <string, string> >(),
                                                            "application/vnd.github.squirrel-girl-preview+json",
                                                            Args.ApiOptions);
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssueCommentsClient(connection);

                client.GetAllForRepository("fake", "repo");

                connection.Received().GetAll <IssueComment>(
                    Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"),
                    Arg.Any <Dictionary <string, string> >(),
                    Arg.Is <string>(s => s == "application/vnd.github.squirrel-girl-preview"),
                    Args.ApiOptions);
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssueCommentsClient(connection);

                client.GetAllForRepository("fake", "repo");

                connection.Received().GetAll<IssueComment>(
                    Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"),
                    Arg.Any<Dictionary<string, string>>(),
                    Arg.Is<string>(s => s == "application/vnd.github.squirrel-girl-preview"),
                    Args.ApiOptions);
            }
예제 #10
0
            public void RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssueCommentsClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize  = 1,
                    StartPage = 1
                };

                client.GetAllForRepository("fake", "repo", options);

                connection.Received().GetAll <IssueComment>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"), options);
            }
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new IssueCommentsClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize  = 1,
                    StartPage = 1
                };

                await client.GetAllForRepository("fake", "repo", options);

                connection.Received().GetAll <IssueComment>(
                    Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"),
                    Arg.Any <Dictionary <string, string> >(),
                    "application/vnd.github.squirrel-girl-preview+json",
                    options);
            }
            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new IssueCommentsClient(connection);

                var options = new ApiOptions
                {
                    PageCount = 1,
                    PageSize = 1,
                    StartPage = 1
                };

                await client.GetAllForRepository("fake", "repo", options);

                connection.Received().GetAll<IssueComment>(
                    Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"),
                    Arg.Any<Dictionary<string, string>>(),
                    "application/vnd.github.squirrel-girl-preview",
                    options);
            }