public async Task EnsuresNonNullArguments() { var client = new ObservableMilestonesClient(Substitute.For<IGitHubClient>()); await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", 1)); await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, 1)); await AssertEx.Throws<ArgumentException>(async () => await client.Get(null, "", 1)); await AssertEx.Throws<ArgumentException>(async () => await client.Get("", null, 1)); }
public void GetsFromClientIssueMilestone() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableMilestonesClient(gitHubClient); client.Get("fake", "repo", 42); gitHubClient.Issue.Milestone.Received().Get("fake", "repo", 42); }
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 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); }
public async Task ReturnsSpecifiedMilestone() { var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; var client = new ObservableMilestonesClient(github); var observable = client.Get("libgit2", "libgit2sharp", 1); var milestone = await observable; Assert.Equal(1, milestone.Number); Assert.Equal("v0.4.0", milestone.Title); Assert.Equal(7, milestone.ClosedIssues); }
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 async Task EnsuresArgumentsNotNull() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableMilestonesClient(gitHubClient); AssertEx.Throws<ArgumentNullException>(async () => await client.Delete(null, "name", 42)); AssertEx.Throws<ArgumentException>(async () => await client.Delete("", "name", 42)); AssertEx.Throws<ArgumentNullException>(async () => await client.Delete("owner", null, 42)); AssertEx.Throws<ArgumentException>(async () => await client.Delete("owner", "", 42)); }
public void UpdatesClientIssueMilestone() { var milestoneUpdate = new MilestoneUpdate(); var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableMilestonesClient(gitHubClient); client.Update("fake", "repo", 42, milestoneUpdate); gitHubClient.Issue.Milestone.Received().Update("fake", "repo", 42, milestoneUpdate); }
public void CreatesFromClientIssueMilestone() { var newMilestone = new NewMilestone("some title"); var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableMilestonesClient(gitHubClient); client.Create("fake", "repo", newMilestone); gitHubClient.Issue.Milestone.Received().Create("fake", "repo", newMilestone); }