/// <summary> /// Instantiate a new GitHub Activities API client. /// </summary> /// <param name="apiConnection">An API connection</param> public ActivitiesClient(IApiConnection apiConnection) : base(apiConnection) { Events = new EventsClient(apiConnection); Starring = new StarredClient(apiConnection); Watching = new WatchedClient(apiConnection); }
public async Task <bool> UnWatchRepository(long repositoryId, GitHubClient authorizedGitHubClient) { if (_watchedClient == null) { _watchedClient = new WatchedClient(new ApiConnection(authorizedGitHubClient.Connection)); } return(await _watchedClient.UnwatchRepo(repositoryId)); }
public async Task <Subscription> WatchRepository(long repositoryId, NewSubscription subscription, GitHubClient authorizedGitHubClient) { if (_watchedClient == null) { _watchedClient = new WatchedClient(new ApiConnection(authorizedGitHubClient.Connection)); } return(await _watchedClient.WatchRepo(repositoryId, subscription)); }
/// <summary> /// Instantiate a new GitHub Activities API client. /// </summary> /// <param name="apiConnection">An API connection</param> public ActivitiesClient(IApiConnection apiConnection) : base(apiConnection) { Events = new EventsClient(apiConnection); Starring = new StarredClient(apiConnection); Watching = new WatchedClient(apiConnection); Feeds = new FeedsClient(apiConnection); Notifications = new NotificationsClient(apiConnection); }
public async Task RequestsCorrectUrl() { var endpoint = new Uri("user/subscriptions", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); await client.GetAllForCurrent(); connection.Received().GetAll <Repository>(endpoint, Args.ApiOptions); }
public async Task RequestsCorrectUrl() { var endpoint = new Uri("user/subscriptions", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); await client.GetAllForCurrent(); connection.Received().GetAll<Repository>(endpoint, Args.ApiOptions); }
public void RequestsCorrectUrl() { var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); client.GetAllForUser("banana"); connection.Received().GetAll<Repository>(endpoint); }
public async Task RequestsCorrectUrlWithRepositoryId() { var endpoint = new Uri("repositories/1/subscribers", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); await client.GetAllWatchers(1); connection.Received().GetAll <User>(endpoint, Args.ApiOptions); }
public void RequestsCorrectUrl() { var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); client.GetAllWatchers("fight", "club"); connection.Received().GetAll<User>(endpoint); }
public void RequestsCorrectUrl() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); var newSubscription = new NewSubscription(); client.WatchRepo("fight", "club", newSubscription); connection.Received().Put<Subscription>(endpoint, newSubscription); }
public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.UnwatchRepo(null, "name")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.UnwatchRepo("owner", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.UnwatchRepo("", "name")); await Assert.ThrowsAsync <ArgumentException>(() => client.UnwatchRepo("owner", "")); }
public void RequestsCorrectUrlWithRepositoryId() { var endpoint = new Uri("repositories/1/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); var newSubscription = new NewSubscription(); client.WatchRepo(1, newSubscription); connection.Received().Put <Subscription>(endpoint, newSubscription); }
public async Task ReturnsTrueOnValidResult() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); connection.Get<Subscription>(endpoint).Returns(Task.FromResult(new Subscription())); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.True(watched); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var response = new ApiResponse<Subscription> { StatusCode = HttpStatusCode.NotFound }; connection.Get<Subscription>(endpoint).Returns(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }
public async Task ReturnsTrueOnValidResultWithRepositoryId() { var endpoint = new Uri("repositories/1/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); connection.Get <Subscription>(endpoint).Returns(Task.FromResult(new Subscription(false, false, null, default(DateTimeOffset), null, null))); var client = new WatchedClient(connection); var watched = await client.CheckWatched(1); Assert.True(watched); }
public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForUser("user", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser("")); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForUser("", ApiOptions.None)); }
public async Task ReturnsCorrectResultBasedOnStatus(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew<HttpStatusCode>(() => status); var connection = Substitute.For<IConnection>(); connection.DeleteAsync(Arg.Is<Uri>(u => u.ToString() == "repos/yes/no/subscription")) .Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new WatchedClient(apiConnection); var result = await client.UnwatchRepo("yes", "no"); Assert.Equal(expected, result); }
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() { var endpoint = new Uri("repositories/1/subscribers", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; await client.GetAllWatchers(1, options); connection.Received().GetAll <User>(endpoint, options); }
public void RequestsCorrectUrlWithApiOptions() { var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; client.GetAllWatchers("fight", "club", options); connection.Received().GetAll <User>(endpoint, options); }
public void RequestsCorrectUrlWithApiOptions() { var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; client.GetAllForUser("banana", options); connection.Received().GetAll<Repository>(endpoint, options); }
public async Task RequestsCorrectUrlWithApiOptions() { var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var client = new WatchedClient(connection); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; await client.GetAllForUser("banana", options); connection.Received().GetAll <Repository>(endpoint, options); }
public async Task ReturnsFalseOnNotFoundExceptionWithRepositoryId() { var endpoint = new Uri("repositories/1/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var response = CreateResponse(HttpStatusCode.NotFound); connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched(1); Assert.False(watched); }
public async Task ReturnsCorrectResultBasedOnStatusWithRepositoryId(HttpStatusCode status, bool expected) { var response = Task.FromResult(status); var connection = Substitute.For <IConnection>(); connection.Delete(Arg.Is <Uri>(u => u.ToString() == "repositories/1/subscription")) .Returns(response); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new WatchedClient(apiConnection); var result = await client.UnwatchRepo(1); Assert.Equal(expected, result); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For <IApiConnection>(); var response = new Response(HttpStatusCode.NotFound, null, new Dictionary <string, string>(), "application/json"); connection.Get <Subscription>(endpoint).Returns <Task <Subscription> >(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }
public async Task ReturnsFalseOnNotFoundException() { var endpoint = new Uri("repos/fight/club/subscription", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var response = new Response(HttpStatusCode.NotFound, null, new Dictionary<string, string>(), "application/json"); connection.Get<Subscription>(endpoint).Returns<Task<Subscription>>(x => { throw new NotFoundException(response); }); var client = new WatchedClient(connection); var watched = await client.CheckWatched("fight", "club"); Assert.False(watched); }
public void RequestsCorrectUrlWithApiOptions() { var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative); var connection = Substitute.For<IApiConnection>(); var client = new WatchedClient(connection); var options = new ApiOptions { StartPage = 1, PageCount = 1, PageSize = 1 }; client.GetAllWatchers("fight", "club", options); connection.Received().GetAll<User>(endpoint, options); }
public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null)); }
public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("user", null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", ApiOptions.None)); }
public async Task EnsuresNonNullArguments() { var client = new WatchedClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent(null)); }