public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new CommitStatusClient(connection); client.GetCombined("fake", "repo", "sha"); connection.Received() .Get<CombinedCommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/status"), null); }
public async Task RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For<IApiConnection>(); var client = new CommitStatusClient(connection); await client.GetAll(1, "sha"); connection.Received() .GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits/sha/statuses"), Args.ApiOptions); }
public void PostsToTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new CommitStatusClient(connection); client.Create("owner", "repo", "sha", new NewCommitStatus { State = CommitState.Success }); connection.Received().Post<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/statuses/sha"), Arg.Is<NewCommitStatus>(s => s.State == CommitState.Success)); }
public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For<IApiConnection>()); await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("", "name", "sha")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("owner", "", "sha")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetCombined("owner", "name", "")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined(null, "name", "sha")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined("owner", null, "sha")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetCombined("owner", "name", null)); }
public void RequestsCorrectUrlWithApiOptions() { var connection = Substitute.For<IApiConnection>(); var client = new CommitStatusClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; client.GetAll("fake", "repo", "sha", options); connection.Received() .GetAll<CommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/statuses"), Args.ApiOptions); }
public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For<IApiConnection>()); await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "name", "", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, "sha", new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null, new NewCommitStatus())); await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", "sha", null)); }
public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For <IApiConnection>()); await Assert.ThrowsAsync <ArgumentException>(() => client.GetCombined("", "name", "sha")); await Assert.ThrowsAsync <ArgumentException>(() => client.GetCombined("owner", "", "sha")); await Assert.ThrowsAsync <ArgumentException>(() => client.GetCombined("owner", "name", "")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetCombined(null, "name", "sha")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetCombined("owner", null, "sha")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetCombined("owner", "name", null)); }
public static GitHubStatusResult GitHubStatus(this ICakeContext context, string userName, string apiToken, string owner, string repository, string reference, GitHubStatusSettings settings) { #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); } #endif settings = settings ?? new GitHubStatusSettings(); var connection = CreateApiConnection(userName, apiToken); try { var commitStatus = new NewCommitStatus { Description = settings.Description, Context = settings.Context, TargetUrl = settings.TargetUrl }; switch (settings.State) { case GitHubStatusState.Success: commitStatus.State = CommitState.Success; break; case GitHubStatusState.Pending: commitStatus.State = CommitState.Pending; break; case GitHubStatusState.Failure: commitStatus.State = CommitState.Failure; break; case GitHubStatusState.Error: commitStatus.State = CommitState.Error; break; } var commitStatusClient = new CommitStatusClient(connection); var createStatusTask = commitStatusClient.Create(owner, repository, reference, commitStatus); createStatusTask.Wait(); var taskResult = createStatusTask.Result; var result = new GitHubStatusResult { Id = taskResult.Id.ToString(), Url = taskResult.Url, State = taskResult.State.ToString() }; return(result); } catch (Exception ex) { do { context.Log.Error(ex.Message); } while ((ex = ex.InnerException) != null); throw new Exception("Failed to create status."); } }