private void SetupWithNonReactiveClient() { var collaboratorsClient = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); _githubClient.Repository.Collaborator.Returns(collaboratorsClient); _client = new ObservableRepoCollaboratorsClient(_githubClient); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators")); }
public async Task <IEnumerable <User> > GetCollaboratorsForRepository(long repositoryId, GitHubClient gitHubClient) { if (_repoCollaboratorsClient == null) { _repoCollaboratorsClient = new RepoCollaboratorsClient(new ApiConnection(gitHubClient.Connection)); } return(await _repoCollaboratorsClient.GetAll(repositoryId)); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.Delete(1, "user1"); connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators/user1")); }
public void RequestsCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); connection.Received().GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators")); }
public void RequestsCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); connection.Received().GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators"), null, "application/vnd.github.ironman-preview+json", Args.ApiOptions); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators"), null, "application/vnd.github.ironman-preview+json", Args.ApiOptions); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll(1); connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"), Args.ApiOptions); }
public void EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>()); Assert.Throws<ArgumentNullException>(() => client.GetAll(null,"test")); Assert.Throws<ArgumentException>(() => client.GetAll("", "test")); Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null)); Assert.Throws<ArgumentException>(() => client.GetAll("owner", "")); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll(1); connection.Received().GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), Args.ApiOptions); }
public void EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); Assert.Throws <ArgumentNullException>(() => client.GetAll(null, "test")); Assert.Throws <ArgumentException>(() => client.GetAll("", "test")); Assert.Throws <ArgumentNullException>(() => client.GetAll("owner", null)); Assert.Throws <ArgumentException>(() => client.GetAll("owner", "")); }
public void RequestsCorrectUrl() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var permission = new CollaboratorRequest(Permission.Push); client.Invite("owner", "test", "user1", permission); connection.Received().Put <RepositoryInvitation>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is <CollaboratorRequest>(permission), Arg.Any <string>(), Arg.Is <string>("application/vnd.github.swamp-thing-preview+json")); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.ReviewPermission(1L, "user1"); connection.Received().Get <CollaboratorPermission>( Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators/user1/permission"), Arg.Any <Dictionary <string, string> >(), "application/vnd.github.korra-preview+json"); }
public async Task SurfacesAuthorizationException() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); connection.Put(Arg.Any <Uri>()).Returns(x => { throw new AuthorizationException(); }); await Assert.ThrowsAsync <AuthorizationException>(() => client.Add("owner", "test", "user1")); await Assert.ThrowsAsync <AuthorizationException>(() => client.Add(1, "user1")); }
public async Task SurfacesAuthorizationExceptionWhenSpecifyingCollaboratorRequest() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); connection.Connection.Put <object>(Arg.Any <Uri>(), Arg.Any <object>()).ThrowsAsync(new AuthorizationException()); await Assert.ThrowsAsync <AuthorizationException>(() => client.Add("owner", "test", "user1", new CollaboratorRequest(Permission.Pull))); await Assert.ThrowsAsync <AuthorizationException>(() => client.Add(1, "user1", new CollaboratorRequest(Permission.Pull))); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator(null, "test", "user1")); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator("", "test", "user1")); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator("owner", null, "user1")); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator("owner", "", "user1")); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator("owner", "test", "")); AssertEx.Throws <ArgumentNullException>(async() => await client.IsCollaborator("owner", "test", null)); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "test")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "test")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "test", ApiOptions.None)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "test", null)); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.GetAll(1); connection.Received().GetAll <User>( Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), Arg.Any <Dictionary <string, string> >(), "application/vnd.github.hellcat-preview+json", Args.ApiOptions); }
public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew<IResponse<object>>(() => new ApiResponse<object> { StatusCode = status }); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); var result = await client.IsCollaborator("owner", "test", "user1"); Assert.Equal(expected, result); }
public async Task ThrowsExceptionForInvalidStatusCodeWithRepositoryId() { var response = Task.Factory.StartNew <IApiResponse <object> >(() => new ApiResponse <object>(new Response(HttpStatusCode.Conflict, null, new Dictionary <string, string>(), "application/json"))); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/assignees/cody"), null, null).Returns(response); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); await Assert.ThrowsAsync <ApiException>(() => client.IsCollaborator(1, "cody")); }
public async Task ThrowsExceptionForInvalidStatusCodeWithRepositoryId() { var responseTask = TestSetup.GetApiResponse(HttpStatusCode.Conflict); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/assignees/cody"), null, null) .Returns(responseTask); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); await Assert.ThrowsAsync <ApiException>(() => client.IsCollaborator(1, "cody")); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete(null, "test", "user1")); await Assert.ThrowsAsync <ArgumentException>(() => client.Delete("", "test", "user1")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete("owner", null, "user1")); await Assert.ThrowsAsync <ArgumentException>(() => client.Delete("owner", "", "user1")); await Assert.ThrowsAsync <ArgumentException>(() => client.Delete("owner", "test", "")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete("owner", "test", null)); }
public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; client.GetAll(1, options); connection.Received() .GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), options); }
public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew <IApiResponse <object> >(() => new ApiResponse <object>(new Response(status, null, new Dictionary <string, string>(), "application/json"))); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators/user1"), null, null).Returns(response); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); var result = await client.IsCollaborator(1, "user1"); Assert.Equal(expected, result); }
public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; client.GetAll(1, options); connection.Received() .GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators"), options); }
public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCode status, bool expected) { var responseTask = TestSetup.GetApiResponse(status); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators/user1"), null, null) .Returns(responseTask); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); var result = await client.IsCollaborator(1, "user1"); Assert.Equal(expected, result); }
public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var request = new RepositoryCollaboratorListRequest(); client.GetAll(1, request); connection.Received() .GetAll <User>( Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "all"), "application/vnd.github.hellcat-preview+json", Args.ApiOptions); request = new RepositoryCollaboratorListRequest { Affiliation = CollaboratorAffiliation.Direct }; client.GetAll(1, request); connection.Received() .GetAll <User>( Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "direct"), "application/vnd.github.hellcat-preview+json", Args.ApiOptions); request = new RepositoryCollaboratorListRequest { Affiliation = CollaboratorAffiliation.Outside }; client.GetAll(1, request); connection.Received() .GetAll <User>( Arg.Is <Uri>(u => u.ToString() == "repositories/1/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "outside"), "application/vnd.github.hellcat-preview+json", Args.ApiOptions); }
public void RequestsCorrectUrlWithApiOptions() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; client.GetAll("owner", "test", options); connection.Received() .GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Any <Dictionary <string, string> >(), options); }
public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew <IResponse <object> >(() => new ApiResponse <object> { StatusCode = status }); var connection = Substitute.For <IConnection>(); connection.GetAsync <object>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), null, null).Returns(response); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); var result = await client.IsCollaborator("owner", "test", "user1"); Assert.Equal(expected, result); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); var permission = new CollaboratorRequest(Permission.Push); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite(null, "test", "user1", permission)); await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("", "test", "user1", permission)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", null, "user1", permission)); await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("owner", "", "user1", permission)); await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("owner", "test", "", permission)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", "test", null, permission)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", "test", "user1", null)); }
public void RequestsCorrectUrlWithCollaboratorFilter() { var connection = Substitute.For <IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var request = new RepositoryCollaboratorListRequest(); client.GetAll("owner", "test", request); connection.Received() .GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "all"), Args.ApiOptions); request = new RepositoryCollaboratorListRequest { Affiliation = CollaboratorAffiliation.Direct }; client.GetAll("owner", "test", request); connection.Received() .GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "direct"), Args.ApiOptions); request = new RepositoryCollaboratorListRequest { Affiliation = CollaboratorAffiliation.Outside }; client.GetAll("owner", "test", request); connection.Received() .GetAll <User>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is <Dictionary <string, string> >(d => d["affiliation"] == "outside"), Args.ApiOptions); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll(null, "test")); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAll("", "test")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll("owner", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAll("owner", "")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll(null, "test", ApiOptions.None)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll("owner", "test", options: null)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll("owner", "test", request: null)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll(1, options: null)); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAll(1, request: null)); }
private void SetupWithNonReactiveClient() { var deploymentsClient = new RepoCollaboratorsClient(Substitute.For<IApiConnection>()); _githubClient.Repository.Collaborator.Returns(deploymentsClient); _client = new ObservableRepoCollaboratorsClient(_githubClient); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); var permission = new CollaboratorRequest(Permission.Push); client.Invite("owner", "test", "user1", permission); connection.Received().Put<RepositoryInvitation>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is<CollaboratorRequest>(permission), Arg.Any<string>(), Arg.Is<string>("application/vnd.github.swamp-thing-preview+json")); }
public async Task RequestsCorrectValueForStatusCodeWithRepositoryId(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew<IApiResponse<object>>(() => new ApiResponse<object>(new Response(status, null, new Dictionary<string, string>(), "application/json"))); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators/user1"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); var result = await client.IsCollaborator(1, "user1"); Assert.Equal(expected, result); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>()); await AssertEx.Throws<ArgumentNullException>(() => client.IsCollaborator(null, "test", "user1")); await AssertEx.Throws<ArgumentException>(() => client.IsCollaborator("", "test", "user1")); await AssertEx.Throws<ArgumentNullException>(() => client.IsCollaborator("owner", null, "user1")); await AssertEx.Throws<ArgumentException>(() => client.IsCollaborator("owner", "", "user1")); await AssertEx.Throws<ArgumentException>(() => client.IsCollaborator("owner", "test", "")); await AssertEx.Throws<ArgumentNullException>(() => client.IsCollaborator("owner", "test", null)); }
public async Task ThrowsExceptionForInvalidStatusCodeWithRepositoryId() { var response = Task.Factory.StartNew<IApiResponse<object>>(() => new ApiResponse<object>(new Response(HttpStatusCode.Conflict, null, new Dictionary<string, string>(), "application/json"))); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/assignees/cody"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new RepoCollaboratorsClient(apiConnection); await Assert.ThrowsAsync<ApiException>(() => client.IsCollaborator(1, "cody")); }
public void RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For<IApiConnection>(); var client = new RepoCollaboratorsClient(connection); client.Delete(1, "user1"); connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/collaborators/user1")); }
public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>()); var permission = new CollaboratorRequest(Permission.Push); await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite(null, "test", "user1", permission)); await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("", "test", "user1", permission)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", null, "user1", permission)); await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "", "user1", permission)); await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "test", "", permission)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", "test", null, permission)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", "test", "user1", null)); }