public async Task EnsuresArgumentsNotNull()
            {
                var client = new ObservablePullRequestReviewCommentsClient(Substitute.For <IGitHubClient>());

                var request = new PullRequestReviewCommentRequest();

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

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

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

                await AssertEx.Throws <ArgumentException>(async() => await client.GetForRepository("owner", "", request));

                await AssertEx.Throws <ArgumentNullException>(async() => await client.GetForRepository("owner", "name", null));
            }
            public async Task RequestsCorrectUrlWithoutSelectedSortingArguments()
            {
                var firstPageUrl   = new Uri("repos/fakeOwner/fakeRepoName/pulls/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> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 1
                        },
                        new PullRequestReviewComment {
                            Id = 2
                        },
                        new PullRequestReviewComment {
                            Id = 3
                        }
                    },
                    ApiInfo = CreateApiInfo(firstPageLinks)
                };
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 4
                        },
                        new PullRequestReviewComment {
                            Id = 5
                        },
                        new PullRequestReviewComment {
                            Id = 6
                        }
                    },
                    ApiInfo = CreateApiInfo(secondPageLinks)
                };
                var lastPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 7
                        },
                        new PullRequestReviewComment {
                            Id = 8
                        },
                    },
                    ApiInfo = CreateApiInfo(new Dictionary <string, Uri>())
                };

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

                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(firstPageUrl,
                                                                               Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                                                                                     d["direction"] == "asc" &&
                                                                                                                     d["sort"] == "created"), null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => firstPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(secondPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => secondPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(thirdPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => lastPageResponse));

                var client = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                var results = await client.GetForRepository("fakeOwner", "fakeRepoName").ToArray();

                Assert.Equal(8, results.Length);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(firstPageUrl,
                                                                                           Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                                                                                                 d["direction"] == "asc" &&
                                                                                                                                 d["sort"] == "created"), null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(secondPageUrl, null, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(thirdPageUrl, null, null);
            }
            public async Task RequestsCorrectUrl()
            {
                var firstPageUrl   = new Uri("repos/fakeOwner/fakeRepoName/pulls/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> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 1
                        },
                        new PullRequestReviewComment {
                            Id = 2
                        },
                        new PullRequestReviewComment {
                            Id = 3
                        }
                    },
                    ApiInfo = CreateApiInfo(firstPageLinks)
                };
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 4
                        },
                        new PullRequestReviewComment {
                            Id = 5
                        },
                        new PullRequestReviewComment {
                            Id = 6
                        }
                    },
                    ApiInfo = CreateApiInfo(secondPageLinks)
                };
                var lastPageResponse = new ApiResponse <List <PullRequestReviewComment> >
                {
                    BodyAsObject = new List <PullRequestReviewComment>
                    {
                        new PullRequestReviewComment {
                            Id = 7
                        },
                        new PullRequestReviewComment {
                            Id = 8
                        },
                    },
                    ApiInfo = CreateApiInfo(new Dictionary <string, Uri>())
                };

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

                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(firstPageUrl,
                                                                               Arg.Is <Dictionary <string, string> >(d => d.Count == 3 &&
                                                                                                                     d["direction"] == "desc" &&
                                                                                                                     d["since"] == "2013-11-15T11:43:01Z" &&
                                                                                                                     d["sort"] == "updated"), null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => firstPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(secondPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => secondPageResponse));
                gitHubClient.Connection.Get <List <PullRequestReviewComment> >(thirdPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IResponse <List <PullRequestReviewComment> > >(() => lastPageResponse));

                var client = new ObservablePullRequestReviewCommentsClient(gitHubClient);

                var request = new PullRequestReviewCommentRequest
                {
                    Direction = SortDirection.Descending,
                    Since     = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()),
                    Sort      = PullRequestReviewCommentSort.Updated,
                };

                var results = await client.GetForRepository("fakeOwner", "fakeRepoName", request).ToArray();

                Assert.Equal(8, results.Length);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(firstPageUrl,
                                                                                           Arg.Is <Dictionary <string, string> >(d => d.Count == 3 &&
                                                                                                                                 d["direction"] == "desc" &&
                                                                                                                                 d["since"] == "2013-11-15T11:43:01Z" &&
                                                                                                                                 d["sort"] == "updated"), null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(secondPageUrl, null, null);
                gitHubClient.Connection.Received(1).Get <List <PullRequestReviewComment> >(thirdPageUrl, null, null);
            }