public async Task ReturnsAllMilestones()
            {
                var github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
                {
                    Credentials = Helper.Credentials
                };
                var client = new ObservableMilestonesClient(github);
                var milestones = await client.GetForRepository("libgit2", "libgit2sharp", new MilestoneRequest { State = ItemState.Closed }).ToList();

                Assert.NotEmpty(milestones);
                Assert.True(milestones.All(m => m.State == ItemState.Closed));
            }
            public void 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>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 1},
                        new Milestone {Number = 2},
                        new Milestone {Number = 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<Milestone>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 4},
                        new Milestone {Number = 5},
                        new Milestone {Number = 6},
                    },
                    ApiInfo = CreateApiInfo(secondPageLinks)
                };
                var lastPageResponse = new ApiResponse<List<Milestone>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 7},
                    },
                    ApiInfo = CreateApiInfo(new Dictionary<string, Uri>())
                };
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.GetAsync<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<IResponse<List<Milestone>>>(() => firstPageResponse));
                gitHubClient.Connection.GetAsync<List<Milestone>>(secondPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => secondPageResponse));
                gitHubClient.Connection.GetAsync<List<Milestone>>(thirdPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => lastPageResponse));
                var client = new ObservableMilestonesClient(gitHubClient);

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

                Assert.Equal(7, results.Length);
                Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
                Assert.Equal(secondPageResponse.BodyAsObject[1].Number, results[4].Number);
                Assert.Equal(lastPageResponse.BodyAsObject[0].Number, results[6].Number);
            }
            public void 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>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 1},
                        new Milestone {Number = 2},
                        new Milestone {Number = 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<Milestone>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 4},
                        new Milestone {Number = 5},
                        new Milestone {Number = 6},
                    },
                    ApiInfo = CreateApiInfo(secondPageLinks)
                };
                var lastPageResponse = new ApiResponse<List<Milestone>>
                {
                    BodyAsObject = new List<Milestone>
                    {
                        new Milestone {Number = 7},
                    },
                    ApiInfo = CreateApiInfo(new Dictionary<string, Uri>())
                };
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.GetAsync<List<Milestone>>(firstPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => firstPageResponse));
                gitHubClient.Connection.GetAsync<List<Milestone>>(secondPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => secondPageResponse));
                gitHubClient.Connection.GetAsync<List<Milestone>>(thirdPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Milestone>>>(() => lastPageResponse));
                var client = new ObservableMilestonesClient(gitHubClient);

                var results = client.GetForRepository("fake", "repo").ToArray().Wait();

                Assert.Equal(7, results.Length);
                Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
                Assert.Equal(secondPageResponse.BodyAsObject[1].Number, results[4].Number);
                Assert.Equal(lastPageResponse.BodyAsObject[0].Number, results[6].Number);
            }