public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>()); Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((ApiOptions)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((IssueRequest)null)); Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(null, new ApiOptions())); Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(new IssueRequest(), null)); }
public async Task ReturnsEveryPageOfIssues() { var firstPageUrl = new Uri("issues", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse<List<Issue>> ( CreateResponseWithApiInfo(firstPageLinks), new List<Issue> { CreateIssue(1), CreateIssue(2), CreateIssue(3) } ); var thirdPageUrl = new Uri("https://example.com/page/3"); var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } }; var secondPageResponse = new ApiResponse<List<Issue>> ( CreateResponseWithApiInfo(secondPageLinks), new List<Issue> { CreateIssue(4), CreateIssue(5), CreateIssue(6) } ); var lastPageResponse = new ApiResponse<List<Issue>> ( new Response(), new List<Issue> { CreateIssue(7) } ); var gitHubClient = Substitute.For<IGitHubClient>(); gitHubClient.Connection.Get<List<Issue>>(Arg.Is(firstPageUrl), Arg.Is<Dictionary<string, string>>(d => d.Count == 4 && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => firstPageResponse)); gitHubClient.Connection.Get<List<Issue>>(secondPageUrl, Arg.Any<Dictionary<string, string>>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => secondPageResponse)); gitHubClient.Connection.Get<List<Issue>>(thirdPageUrl, Arg.Any<Dictionary<string, string>>(), "application/vnd.github.squirrel-girl-preview") .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = await client.GetAllForCurrent().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 ReturnsEveryPageOfIssues() { var firstPageUrl = new Uri("issues", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse<List<Issue>> { BodyAsObject = new List<Issue> { new Issue {Number = 1}, new Issue {Number = 2}, new Issue {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<Issue>> { BodyAsObject = new List<Issue> { new Issue {Number = 4}, new Issue {Number = 5}, new Issue {Number = 6}, }, ApiInfo = CreateApiInfo(secondPageLinks) }; var lastPageResponse = new ApiResponse<List<Issue>> { BodyAsObject = new List<Issue> { new Issue {Number = 7}, }, ApiInfo = CreateApiInfo(new Dictionary<string, Uri>()) }; var gitHubClient = Substitute.For<IGitHubClient>(); gitHubClient.Connection.GetAsync<List<Issue>>(Arg.Is(firstPageUrl), Arg.Is<Dictionary<string, string>>(d => d.Count == 4 && d["direction"] == "desc" && d["state"] == "open" && d["sort"] == "created" && d["filter"] == "assigned"), Arg.Any<string>()) .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => firstPageResponse)); gitHubClient.Connection.GetAsync<List<Issue>>(secondPageUrl, null, null) .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => secondPageResponse)); gitHubClient.Connection.GetAsync<List<Issue>>(thirdPageUrl, null, null) .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse)); var client = new ObservableIssuesClient(gitHubClient); var results = client.GetAllForCurrent().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); }