public void EnsuresNonNullArguments()
            {
                var client = new ObservablePullRequestReviewsClient(Substitute.For <IGitHubClient>());

                string body     = "Comment content";
                string path     = "file.css";
                int    position = 7;

                var comment = new DraftPullRequestReviewComment(body, path, position);

                var review = new PullRequestReviewCreate()
                {
                    CommitId = "commit",
                    Body     = "body",
                    Event    = PullRequestReviewEvent.Approve
                };

                review.Comments.Add(comment);

                Assert.Throws <ArgumentNullException>(() => client.Create(null, "fakeRepoName", 1, review));
                Assert.Throws <ArgumentNullException>(() => client.Create("fakeOwner", null, 1, review));
                Assert.Throws <ArgumentNullException>(() => client.Create("fakeOwner", "fakeRepoName", 1, null));

                Assert.Throws <ArgumentException>(() => client.Create("", "fakeRepoName", 1, review));
                Assert.Throws <ArgumentException>(() => client.Create("fakeOwner", "", 1, review));
            }
            public async Task RequestsCorrectUrlMulti()
            {
                var firstPageUrl   = new Uri("repos/owner/name/pulls/7/reviews", UriKind.Relative);
                var secondPageUrl  = new Uri("https://example.com/page/2");
                var firstPageLinks = new Dictionary <string, Uri> {
                    { "next", secondPageUrl }
                };
                var firstPageResponse = new ApiResponse <List <PullRequestReview> >
                                        (
                    CreateResponseWithApiInfo(firstPageLinks),
                    new List <PullRequestReview>
                {
                    new PullRequestReview(1),
                    new PullRequestReview(2),
                    new PullRequestReview(3)
                });
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <PullRequestReview> >
                                         (
                    CreateResponseWithApiInfo(secondPageLinks),
                    new List <PullRequestReview>
                {
                    new PullRequestReview(4),
                    new PullRequestReview(5),
                    new PullRequestReview(6)
                }
                                         );
                var lastPageResponse = new ApiResponse <List <PullRequestReview> >
                                       (
                    new Response(),
                    new List <PullRequestReview>
                {
                    new PullRequestReview(7)
                }
                                       );

                var gitHubClient = Substitute.For <IGitHubClient>();

                gitHubClient.Connection.Get <List <PullRequestReview> >(firstPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => firstPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReview> >(secondPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => secondPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReview> >(thirdPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => lastPageResponse));

                var client = new ObservablePullRequestReviewsClient(gitHubClient);

                var results = await client.GetAll("owner", "name", 7).ToArray();

                Assert.Equal(7, results.Length);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(firstPageUrl, Args.EmptyDictionary, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(secondPageUrl, Args.EmptyDictionary, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(thirdPageUrl, Args.EmptyDictionary, null);
            }
            public async Task RequestsCorrectUrlMultiWithRepositoryId()
            {
                var firstPageUrl   = new Uri("repositories/1/pulls/7/reviews/1/comments", UriKind.Relative);
                var secondPageUrl  = new Uri("https://example.com/page/2");
                var firstPageLinks = new Dictionary <string, Uri> {
                    { "next", secondPageUrl }
                };
                var firstPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                                        (
                    CreateResponseWithApiInfo(firstPageLinks),
                    new List <PullRequestReviewComment>
                {
                    new PullRequestReviewComment(1),
                    new PullRequestReviewComment(2),
                    new PullRequestReviewComment(3)
                });
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                                         (
                    CreateResponseWithApiInfo(secondPageLinks),
                    new List <PullRequestReviewComment>
                {
                    new PullRequestReviewComment(4),
                    new PullRequestReviewComment(5),
                    new PullRequestReviewComment(6)
                }
                                         );
                var lastPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                                       (
                    new Response(),
                    new List <PullRequestReviewComment>
                {
                    new PullRequestReviewComment(7)
                }
                                       );

                var gitHubClient = Substitute.For <IGitHubClient>();

                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(firstPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.FromResult <IApiResponse <List <PullRequestReviewComment> > >(firstPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(secondPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.FromResult <IApiResponse <List <PullRequestReviewComment> > >(secondPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(thirdPageUrl, Args.EmptyDictionary, null)
                .Returns(Task.FromResult <IApiResponse <List <PullRequestReviewComment> > >(lastPageResponse));

                var client = new ObservablePullRequestReviewsClient(gitHubClient);

                var results = await client.GetAllComments(1, 7, 1).ToArray();

                Assert.Equal(7, results.Length);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(firstPageUrl, Args.EmptyDictionary, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(secondPageUrl, Args.EmptyDictionary, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(thirdPageUrl, Args.EmptyDictionary, null);
            }
            public void RequestsCorrectUrl()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                client.GetAllComments("fake", "repo", 1, 1);

                gitHubClient.Received().PullRequest.Review.GetAllComments("fake", "repo", 1, 1);
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                client.GetAll(1, 1);

                gitHubClient.Received().PullRequest.Review.GetAll(1, 1);
            }
            public void RequestsCorrectUrl()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                client.Get("owner", "name", 53, 2);

                gitHubClient.Received().PullRequest.Review.Get("owner", "name", 53, 2);
            }
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                client.Delete(1, 13, 13);

                gitHubClient.Received().PullRequest.Review.Delete(1, 13, 13);
            }
            public void PostsToCorrectUrl()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                client.Delete("owner", "name", 13, 13);

                gitHubClient.Received().PullRequest.Review.Delete("owner", "name", 13, 13);
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new ObservablePullRequestReviewsClient(Substitute.For <IGitHubClient>());

                Assert.Throws <ArgumentNullException>(() => client.Get(null, "name", 1, 1));
                Assert.Throws <ArgumentNullException>(() => client.Get("owner", null, 1, 1));

                Assert.Throws <ArgumentException>(() => client.Get("", "name", 1, 1));
                Assert.Throws <ArgumentException>(() => client.Get("owner", "", 1, 1));
            }
            public void EnsuresNonNullArguments()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                Assert.Throws <ArgumentNullException>(() => client.Delete(null, "name", 1, 1));
                Assert.Throws <ArgumentNullException>(() => client.Delete("owner", null, 1, 1));

                Assert.Throws <ArgumentException>(() => client.Delete("", "name", 1, 1));
                Assert.Throws <ArgumentException>(() => client.Delete("owner", "", 1, 1));
            }
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                var dismissMessage = new PullRequestReviewDismiss()
                {
                    Message = "test message"
                };

                client.Dismiss(1, 13, 13, dismissMessage);

                gitHubClient.Received().PullRequest.Review.Dismiss(1, 13, 13, dismissMessage);
            }
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                var submitMessage = new PullRequestReviewSubmit()
                {
                    Body  = "string",
                    Event = PullRequestReviewEvent.Approve
                };

                client.Submit(1, 13, 13, submitMessage);

                gitHubClient.Received().PullRequest.Review.Submit(1, 13, 13, submitMessage);
            }
            public void RequestsCorrectUrlWithApiOptionsWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

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

                client.GetAll(1, 1, options);

                gitHubClient.Received().PullRequest.Review.GetAll(1, 1, options);
            }
            public void EnsuresNonNullArguments()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                var dismissMessage = new PullRequestReviewDismiss()
                {
                    Message = "test message"
                };

                Assert.Throws <ArgumentNullException>(() => client.Dismiss(null, "name", 1, 1, dismissMessage));
                Assert.Throws <ArgumentNullException>(() => client.Dismiss("owner", null, 1, 1, dismissMessage));
                Assert.Throws <ArgumentNullException>(() => client.Dismiss("owner", "name", 1, 1, null));

                Assert.Throws <ArgumentException>(() => client.Dismiss("", "name", 1, 1, dismissMessage));
                Assert.Throws <ArgumentException>(() => client.Dismiss("owner", "", 1, 1, dismissMessage));
            }
            public void EnsuresNonNullArguments()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                var submitMessage = new PullRequestReviewSubmit()
                {
                    Body  = "string",
                    Event = PullRequestReviewEvent.Approve
                };

                Assert.Throws <ArgumentNullException>(() => client.Submit(null, "name", 1, 1, submitMessage));
                Assert.Throws <ArgumentNullException>(() => client.Submit("owner", null, 1, 1, submitMessage));
                Assert.Throws <ArgumentNullException>(() => client.Submit("owner", "name", 1, 1, null));

                Assert.Throws <ArgumentException>(() => client.Submit("", "name", 1, 1, submitMessage));
                Assert.Throws <ArgumentException>(() => client.Submit("owner", "", 1, 1, submitMessage));
            }
            public void PostsToCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                var comment = new DraftPullRequestReviewComment("Comment content", "file.css", 7);
                var review  = new PullRequestReviewCreate()
                {
                    CommitId = "commit",
                    Body     = "body",
                    Event    = PullRequestReviewEvent.Approve
                };

                review.Comments.Add(comment);

                client.Create(1, 13, review);

                gitHubClient.Received().PullRequest.Review.Create(1, 53, review);
            }
            public async Task EnsuresNonNullArguments()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservablePullRequestReviewsClient(gitHubClient);

                Assert.Throws <ArgumentNullException>(() => client.GetAllComments(null, "name", 1, 1));
                Assert.Throws <ArgumentNullException>(() => client.GetAllComments("owner", null, 1, 1));

                Assert.Throws <ArgumentNullException>(() => client.GetAllComments(null, "name", 1, 1, ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllComments("owner", null, 1, 1, ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllComments("owner", "name", 1, 1, null));

                Assert.Throws <ArgumentNullException>(() => client.GetAllComments(1, 1, 1, null));

                Assert.Throws <ArgumentException>(() => client.GetAllComments("", "name", 1, 1));
                Assert.Throws <ArgumentException>(() => client.GetAllComments("owner", "", 1, 1));

                Assert.Throws <ArgumentException>(() => client.GetAllComments("", "name", 1, 1, ApiOptions.None));
                Assert.Throws <ArgumentException>(() => client.GetAllComments("owner", "", 1, 1, ApiOptions.None));
            }