public async Task SendsAppropriateParameters()
            {
                var firstPageUrl   = new Uri("repos/fake/repo/milestones", UriKind.Relative);
                var secondPageUrl  = new Uri("https://example.com/page/2");
                var firstPageLinks = new Dictionary <string, Uri> {
                    { "next", secondPageUrl }
                };
                var firstPageResponse = new ApiResponse <List <Milestone> >
                                        (
                    CreateResponseWithApiInfo(firstPageLinks),
                    new List <Milestone>
                {
                    new Milestone(1),
                    new Milestone(2),
                    new Milestone(3)
                }
                                        );
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <Milestone> >
                                         (
                    CreateResponseWithApiInfo(secondPageLinks),
                    new List <Milestone>
                {
                    new Milestone(4),
                    new Milestone(5),
                    new Milestone(6)
                }
                                         );
                var lastPageResponse = new ApiResponse <List <Milestone> >
                                       (
                    new Response(),
                    new List <Milestone>
                {
                    new Milestone(7)
                }
                                       );
                var gitHubClient = Substitute.For <IGitHubClient>();

                gitHubClient.Connection.Get <List <Milestone> >(Arg.Is(firstPageUrl),
                                                                Arg.Is <Dictionary <string, string> >(d => d.Count == 3 &&
                                                                                                      d["direction"] == "desc" &&
                                                                                                      d["state"] == "open" &&
                                                                                                      d["sort"] == "due_date"), Arg.Any <string>())
                .Returns(Task.Factory.StartNew <IApiResponse <List <Milestone> > >(() => firstPageResponse));
                gitHubClient.Connection.Get <List <Milestone> >(secondPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IApiResponse <List <Milestone> > >(() => secondPageResponse));
                gitHubClient.Connection.Get <List <Milestone> >(thirdPageUrl, null, null)
                .Returns(Task.Factory.StartNew <IApiResponse <List <Milestone> > >(() => lastPageResponse));
                var client = new ObservableMilestonesClient(gitHubClient);

                var results = await client.GetAllForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }).ToArray();

                Assert.Equal(7, results.Length);
                Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
                Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number);
                Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

                client.GetAllForRepository(1);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository(1);
            }
            public async Task ReturnsEveryPageOfMilestones()
            {
                var firstPageUrl   = new Uri("repos/fake/repo/milestones", UriKind.Relative);
                var secondPageUrl  = new Uri("https://example.com/page/2");
                var firstPageLinks = new Dictionary <string, Uri> {
                    { "next", secondPageUrl }
                };
                var firstPageResponse = new ApiResponse <List <Milestone> >
                                        (
                    CreateResponseWithApiInfo(firstPageLinks),
                    new List <Milestone>
                {
                    new Milestone(1),
                    new Milestone(2),
                    new Milestone(3)
                }
                                        );
                var thirdPageUrl    = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary <string, Uri> {
                    { "next", thirdPageUrl }
                };
                var secondPageResponse = new ApiResponse <List <Milestone> >
                                         (
                    CreateResponseWithApiInfo(secondPageLinks),
                    new List <Milestone>
                {
                    new Milestone(4),
                    new Milestone(5),
                    new Milestone(6)
                }
                                         );
                var lastPageResponse = new ApiResponse <List <Milestone> >
                                       (
                    new Response(),
                    new List <Milestone>
                {
                    new Milestone(7)
                }
                                       );
                var gitHubClient = Substitute.For <IGitHubClient>();

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

                var results = await client.GetAllForRepository("fake", "repo").ToArray();

                Assert.Equal(7, results.Length);
                Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
                Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number);
                Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
            }
            public async Task ReturnsAllMilestones()
            {
                var github = Helper.GetAuthenticatedClient();

                var client     = new ObservableMilestonesClient(github);
                var milestones = await client.GetAllForRepository("libgit2", "libgit2sharp", new MilestoneRequest { State = ItemStateFilter.Closed }).ToList();

                Assert.NotEmpty(milestones);
                Assert.True(milestones.All(m => m.State == ItemState.Closed));
            }
            public void SendsAppropriateParametersWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

                var milestoneRequest = new MilestoneRequest {
                    SortDirection = SortDirection.Descending
                };

                client.GetAllForRepository(1, milestoneRequest);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, milestoneRequest, Args.ApiOptions);
            }
            public void RequestsCorrectUrlWithApiOptionsWithRepositoryId()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

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

                client.GetAllForRepository(1, options);

                gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, options);
            }
            public void SendsAppropriateParametersWithApiOptions()
            {
                var gitHubClient = Substitute.For <IGitHubClient>();
                var client       = new ObservableMilestonesClient(gitHubClient);

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

                var milestoneRequest = new MilestoneRequest {
                    SortDirection = SortDirection.Descending
                };

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

                gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, options);
            }
            public void EnsuresNonNullArguments()
            {
                var client = new ObservableMilestonesClient(Substitute.For <IGitHubClient>());

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

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

                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest()));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest()));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null));

                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null));

                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(1, (MilestoneRequest)null));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(1, null, ApiOptions.None));
                Assert.Throws <ArgumentNullException>(() => client.GetAllForRepository(1, new MilestoneRequest(), null));

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

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

                Assert.Throws <ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest()));
                Assert.Throws <ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest()));

                Assert.Throws <ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest(), ApiOptions.None));
                Assert.Throws <ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), ApiOptions.None));
            }