mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 12:42:32 +00:00
Implement Get Update and Delete BranchProtection methods in ObservableRepositoryBranchesClient
Add unit tests for Observable methods
This commit is contained in:
@@ -152,7 +152,7 @@ namespace Octokit.Tests.Reactive
|
||||
public class TheEditMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PatchsTheCorrectUrl()
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(github);
|
||||
@@ -164,7 +164,7 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PatchsTheCorrectUrlWithRepositoryId()
|
||||
public void RequestsTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(github);
|
||||
@@ -196,5 +196,148 @@ namespace Octokit.Tests.Reactive
|
||||
Assert.Throws<ArgumentException>(() => client.Edit(1, "", update));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetBranchProtectectionMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
|
||||
client.GetBranchProtection("owner", "repo", "branch");
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.GetBranchProtection("owner", "repo", "branch");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
|
||||
client.GetBranchProtection(1, "branch");
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.GetBranchProtection(1, "branch");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranchProtection(null, "repo", "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranchProtection("owner", null, "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranchProtection("owner", "repo", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetBranchProtection(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranchProtection("", "repo", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranchProtection("owner", "", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranchProtection("owner", "repo", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetBranchProtection(1, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateBranchProtectionMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
var update = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
|
||||
|
||||
client.UpdateBranchProtection("owner", "repo", "branch", update);
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.UpdateBranchProtection("owner", "repo", "branch", update);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
var update = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
|
||||
|
||||
client.UpdateBranchProtection(1, "branch", update);
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.UpdateBranchProtection(1, "branch", update);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
|
||||
var update = new BranchProtectionSettingsUpdate(
|
||||
new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection(null, "repo", "branch", update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection("owner", null, "branch", update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection("owner", "repo", null, update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection("owner", "repo", "branch", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection(1, null, update));
|
||||
Assert.Throws<ArgumentNullException>(() => client.UpdateBranchProtection(1, "branch", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.UpdateBranchProtection("", "repo", "branch", update));
|
||||
Assert.Throws<ArgumentException>(() => client.UpdateBranchProtection("owner", "", "branch", update));
|
||||
Assert.Throws<ArgumentException>(() => client.UpdateBranchProtection("owner", "repo", "", update));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.UpdateBranchProtection(1, "", update));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteBranchProtectectionMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
|
||||
client.DeleteBranchProtection("owner", "repo", "branch");
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.DeleteBranchProtection("owner", "repo", "branch");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryBranchesClient(gitHubClient);
|
||||
|
||||
client.DeleteBranchProtection(1, "branch");
|
||||
|
||||
gitHubClient.Repository.Branch.Received()
|
||||
.DeleteBranchProtection(1, "branch");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.DeleteBranchProtection(null, "repo", "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.DeleteBranchProtection("owner", null, "branch"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.DeleteBranchProtection("owner", "repo", null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.DeleteBranchProtection(1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.DeleteBranchProtection("", "repo", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.DeleteBranchProtection("owner", "", "branch"));
|
||||
Assert.Throws<ArgumentException>(() => client.DeleteBranchProtection("owner", "repo", ""));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.DeleteBranchProtection(1, ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user