From 6c3df162f7a9724de3bb39f4759bdfea8e480a9b Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Mon, 13 Jun 2016 16:49:14 +0700 Subject: [PATCH] added integration tests --- .../Clients/WatchedClientTests.cs | 197 +++++++++++++++++- 1 file changed, 196 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/WatchedClientTests.cs b/Octokit.Tests.Integration/Clients/WatchedClientTests.cs index 4fbae6a8..e49f186a 100644 --- a/Octokit.Tests.Integration/Clients/WatchedClientTests.cs +++ b/Octokit.Tests.Integration/Clients/WatchedClientTests.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; +using Octokit.Tests.Integration.Helpers; using Xunit; namespace Octokit.Tests.Integration.Clients @@ -159,6 +161,16 @@ namespace Octokit.Tests.Integration.Clients Assert.NotEmpty(repositories); } + [IntegrationTest] + public async Task CanRetrieveResultsWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var repositories = await github.Activity.Watching.GetAllWatchers(7528679); + + Assert.NotEmpty(repositories); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfRepositoriesWithoutStart() { @@ -175,6 +187,22 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, repositories.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithoutStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1 + }; + + var repositories = await github.Activity.Watching.GetAllWatchers(7528679, options); + + Assert.Equal(3, repositories.Count); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfRepositoriesWithStart() { @@ -192,6 +220,23 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(3, repositories.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfRepositoriesWithStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageSize = 3, + PageCount = 1, + StartPage = 2 + }; + + var repositories = await github.Activity.Watching.GetAllWatchers(7528679, options); + + Assert.Equal(3, repositories.Count); + } + [IntegrationTest] public async Task ReturnsDistinctPullRequestsBasedOnStartPage() { @@ -216,6 +261,156 @@ namespace Octokit.Tests.Integration.Clients Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); } + + [IntegrationTest] + public async Task ReturnsDistinctPullRequestsBasedOnStartPageWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await github.Activity.Watching.GetAllWatchers(7528679, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await github.Activity.Watching.GetAllWatchers(7528679, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + } + } + + public class TheCheckWatchedMethod + { + readonly IWatchedClient _watchingClient; + readonly RepositoryContext _context; + + public TheCheckWatchedMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _watchingClient = github.Activity.Watching; + + _context = github.CreateRepositoryContext("public-repo").Result; + } + + [IntegrationTest] + public async Task CheckWatched() + { + var check = await _watchingClient.CheckWatched(_context.RepositoryOwner, _context.RepositoryName); + + Assert.True(check); + } + + [IntegrationTest] + public async Task CheckWatchedWithRepositoryId() + { + var check = await _watchingClient.CheckWatched(_context.Repository.Id); + + Assert.True(check); + } + } + + public class TheWatchRepoMethod + { + readonly IWatchedClient _watchingClient; + + public TheWatchRepoMethod() + { + var gitHubClient = Helper.GetAuthenticatedClient(); + + _watchingClient = gitHubClient.Activity.Watching; + } + + [IntegrationTest] + public async Task WatchRepo() + { + var newSubscription = new NewSubscription + { + Subscribed = true + }; + + await _watchingClient.UnwatchRepo("octocat", "hello-worId"); + + var subscription = await _watchingClient.WatchRepo("octocat", "hello-worId", newSubscription); + Assert.NotNull(subscription); + + var newWatchers = await _watchingClient.GetAllWatchers("octocat", "hello-worId"); + var @default = newWatchers.FirstOrDefault(user => user.Login == Helper.UserName); + Assert.NotNull(@default); + } + + [IntegrationTest] + public async Task WatchRepoWithRepositoryId() + { + var newSubscription = new NewSubscription(); + + await _watchingClient.UnwatchRepo(18221276); + + var subscription = await _watchingClient.WatchRepo(18221276, newSubscription); + Assert.NotNull(subscription); + + var newWatchers = await _watchingClient.GetAllWatchers(18221276); + var @default = newWatchers.FirstOrDefault(user => user.Login == Helper.UserName); + Assert.NotNull(@default); + } + } + + public class TheUnwatchRepoMethod + { + readonly IWatchedClient _watchingClient; + + public TheUnwatchRepoMethod() + { + var gitHubClient = Helper.GetAuthenticatedClient(); + + _watchingClient = gitHubClient.Activity.Watching; + } + + [IntegrationTest] + public async Task WatchRepo() + { + var newSubscription = new NewSubscription + { + Subscribed = true + }; + + await _watchingClient.UnwatchRepo("octocat", "hello-worId"); + + var subscription = await _watchingClient.WatchRepo("octocat", "hello-worId", newSubscription); + Assert.NotNull(subscription); + + await _watchingClient.UnwatchRepo("octocat", "hello-worId"); + + var newWatchers = await _watchingClient.GetAllWatchers("octocat", "hello-worId"); + var @default = newWatchers.FirstOrDefault(user => user.Login == Helper.UserName); + Assert.Null(@default); + } + + [IntegrationTest] + public async Task WatchRepoWithRepositoryId() + { + var newSubscription = new NewSubscription(); + + await _watchingClient.UnwatchRepo(18221276); + + var subscription = await _watchingClient.WatchRepo(18221276, newSubscription); + Assert.NotNull(subscription); + + await _watchingClient.UnwatchRepo(18221276); + + var newWatchers = await _watchingClient.GetAllWatchers(18221276); + var @default = newWatchers.FirstOrDefault(user => user.Login == Helper.UserName); + Assert.Null(@default); + } } } }