public async Task RequestsCorrectUrlMulti() { var firstPageUrl = new Uri("repos/owner/name/pulls/7/reviews", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary <string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse <List <PullRequestReview> > ( CreateResponseWithApiInfo(firstPageLinks), new List <PullRequestReview> { new PullRequestReview(1), new PullRequestReview(2), new PullRequestReview(3) }); var thirdPageUrl = new Uri("https://example.com/page/3"); var secondPageLinks = new Dictionary <string, Uri> { { "next", thirdPageUrl } }; var secondPageResponse = new ApiResponse <List <PullRequestReview> > ( CreateResponseWithApiInfo(secondPageLinks), new List <PullRequestReview> { new PullRequestReview(4), new PullRequestReview(5), new PullRequestReview(6) } ); var lastPageResponse = new ApiResponse <List <PullRequestReview> > ( new Response(), new List <PullRequestReview> { new PullRequestReview(7) } ); var gitHubClient = Substitute.For <IGitHubClient>(); gitHubClient.Connection.Get <List <PullRequestReview> >(firstPageUrl, Args.EmptyDictionary, null) .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => firstPageResponse)); gitHubClient.Connection.Get <List <PullRequestReview> >(secondPageUrl, Args.EmptyDictionary, null) .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => secondPageResponse)); gitHubClient.Connection.Get <List <PullRequestReview> >(thirdPageUrl, Args.EmptyDictionary, null) .Returns(Task.Factory.StartNew <IApiResponse <List <PullRequestReview> > >(() => lastPageResponse)); var client = new ObservablePullRequestReviewsClient(gitHubClient); var results = await client.GetAll("owner", "name", 7).ToArray(); Assert.Equal(7, results.Length); gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(firstPageUrl, Args.EmptyDictionary, null); gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(secondPageUrl, Args.EmptyDictionary, null); gitHubClient.Connection.Received(1).Get <List <PullRequestReview> >(thirdPageUrl, Args.EmptyDictionary, null); }
public void RequestsCorrectUrl() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservablePullRequestReviewsClient(gitHubClient); client.GetAll("fake", "repo", 1); gitHubClient.Received().PullRequest.Review.GetAll("fake", "repo", 1); }
public void RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservablePullRequestReviewsClient(gitHubClient); client.GetAll(1, 1); gitHubClient.Received().PullRequest.Review.GetAll(1, 1); }
public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservablePullRequestReviewsClient(gitHubClient); Assert.Throws <ArgumentNullException>(() => client.GetAll(null, "name", 1)); Assert.Throws <ArgumentNullException>(() => client.GetAll("owner", null, 1)); Assert.Throws <ArgumentNullException>(() => client.GetAll(null, "name", 1, ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAll("owner", null, 1, ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAll("owner", "name", 1, null)); Assert.Throws <ArgumentNullException>(() => client.GetAll(1, 1, null)); Assert.Throws <ArgumentException>(() => client.GetAll("", "name", 1)); Assert.Throws <ArgumentException>(() => client.GetAll("owner", "", 1)); Assert.Throws <ArgumentException>(() => client.GetAll("", "name", 1, ApiOptions.None)); Assert.Throws <ArgumentException>(() => client.GetAll("owner", "", 1, ApiOptions.None)); }
public void RequestsCorrectUrlWithApiOptionsWithRepositoryId() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservablePullRequestReviewsClient(gitHubClient); var options = new ApiOptions { PageCount = 1, PageSize = 1, StartPage = 1 }; client.GetAll(1, 1, options); gitHubClient.Received().PullRequest.Review.GetAll(1, 1, options); }