diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
index f266b453..7f23dbb6 100644
--- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
+++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs
@@ -314,6 +314,69 @@ namespace Octokit.Reactive
/// The contexts to remove
IObservable DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts);
+ ///
+ /// Get admin enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable GetAdminEnforcement(string owner, string name, string branch);
+
+ ///
+ /// Get admin enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable GetAdminEnforcement(long repositoryId, string branch);
+
+ ///
+ /// Add admin enforcement to protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable AddAdminEnforcement(string owner, string name, string branch);
+
+ ///
+ /// Add admin enforcement to protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable AddAdminEnforcement(long repositoryId, string branch);
+
+ ///
+ /// Remove admin enforcement on protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ IObservable RemoveAdminEnforcement(string owner, string name, string branch);
+
+ ///
+ /// Remove admin enforcement on protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ IObservable RemoveAdminEnforcement(long repositoryId, string branch);
+
///
/// Get the restrictions for the specified branch (applies only to Organization owned repositories)
///
diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
index e6cc4978..3973cda5 100644
--- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
+++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs
@@ -499,6 +499,97 @@ namespace Octokit.Reactive
return _client.DeleteRequiredStatusChecksContexts(repositoryId, branch, contexts).ToObservable().SelectMany(x => x);
}
+ ///
+ /// Get admin enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable GetAdminEnforcement(string owner, string name, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.GetAdminEnforcement(owner, name, branch).ToObservable();
+ }
+
+ ///
+ /// Get admin enforcement of protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ public IObservable GetAdminEnforcement(long repositoryId, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.GetAdminEnforcement(repositoryId, branch).ToObservable();
+ }
+
+ ///
+ /// Add admin enforcement to protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable AddAdminEnforcement(string owner, string name, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.AddAdminEnforcement(owner, name, branch).ToObservable();
+ }
+
+ public IObservable AddAdminEnforcement(long repositoryId, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.AddAdminEnforcement(repositoryId, branch).ToObservable();
+ }
+
+ ///
+ /// Remove admin enforcement on protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The owner of the repository
+ /// The name of the repository
+ /// The name of the branch
+ public IObservable RemoveAdminEnforcement(string owner, string name, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.RemoveAdminEnforcement(owner, name, branch).ToObservable();
+ }
+
+ ///
+ /// Remove admin enforcement on protected branch
+ ///
+ ///
+ /// See the API documentation for more details
+ ///
+ /// The Id of the repository
+ /// The name of the branch
+ public IObservable RemoveAdminEnforcement(long repositoryId, string branch)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
+
+ return _client.RemoveAdminEnforcement(repositoryId, branch).ToObservable();
+ }
+
///
/// Get the restrictions for the specified branch (applies only to Organization owned repositories)
///
diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
index 5e300efe..70846d6f 100644
--- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs
@@ -329,7 +329,7 @@ public class RepositoryBranchesClientTests
var repoName = _userRepoContext.RepositoryName;
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
- Assert.True(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
@@ -342,7 +342,7 @@ public class RepositoryBranchesClientTests
var repoId = _userRepoContext.RepositoryId;
var protection = await _client.GetBranchProtection(repoId, "master");
- Assert.True(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
@@ -356,7 +356,7 @@ public class RepositoryBranchesClientTests
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
var protection = await _client.GetBranchProtection(repoOwner, repoName, "master");
- Assert.True(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
@@ -370,7 +370,7 @@ public class RepositoryBranchesClientTests
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var protection = await _client.GetBranchProtection(repoId, "master");
- Assert.True(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.True(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredStatusChecks.Strict);
Assert.Equal(2, protection.RequiredStatusChecks.Contexts.Count);
@@ -409,11 +409,11 @@ public class RepositoryBranchesClientTests
var repoOwner = _userRepoContext.RepositoryOwner;
var repoName = _userRepoContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }));
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }));
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
- Assert.False(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
@@ -425,11 +425,11 @@ public class RepositoryBranchesClientTests
{
var repoId = _userRepoContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }));
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }));
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
- Assert.False(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
@@ -442,12 +442,13 @@ public class RepositoryBranchesClientTests
var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner;
var repoName = _orgRepoContext.RepositoryContext.RepositoryName;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }),
- new BranchProtectionPushRestrictionsUpdate());
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionPushRestrictionsUpdate(),
+ false);
var protection = await _client.UpdateBranchProtection(repoOwner, repoName, "master", update);
- Assert.False(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
@@ -460,12 +461,13 @@ public class RepositoryBranchesClientTests
{
var repoId = _orgRepoContext.RepositoryContext.RepositoryId;
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(false, false, new[] { "new" }),
- new BranchProtectionPushRestrictionsUpdate());
+ new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
+ new BranchProtectionPushRestrictionsUpdate(),
+ false);
var protection = await _client.UpdateBranchProtection(repoId, "master", update);
- Assert.False(protection.RequiredStatusChecks.IncludeAdmins);
+ Assert.False(protection.EnforceAdmins.Enabled);
Assert.False(protection.RequiredStatusChecks.Strict);
Assert.Equal(1, protection.RequiredStatusChecks.Contexts.Count);
@@ -567,7 +569,6 @@ public class RepositoryBranchesClientTests
Assert.NotNull(requiredStatusChecks);
Assert.NotNull(requiredStatusChecks.Contexts);
- Assert.True(requiredStatusChecks.IncludeAdmins);
Assert.True(requiredStatusChecks.Strict);
Assert.Equal(2, requiredStatusChecks.Contexts.Count);
}
@@ -580,7 +581,6 @@ public class RepositoryBranchesClientTests
Assert.NotNull(requiredStatusChecks);
Assert.NotNull(requiredStatusChecks.Contexts);
- Assert.True(requiredStatusChecks.IncludeAdmins);
Assert.True(requiredStatusChecks.Strict);
Assert.Equal(2, requiredStatusChecks.Contexts.Count);
}
@@ -610,13 +610,12 @@ public class RepositoryBranchesClientTests
{
var repoOwner = _userRepoContext.RepositoryOwner;
var repoName = _userRepoContext.RepositoryName;
- var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "new" });
+ var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" });
var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoOwner, repoName, "master", update);
Assert.NotNull(requiredStatusChecks);
Assert.NotNull(requiredStatusChecks.Contexts);
Assert.True(requiredStatusChecks.Contexts.Contains("new"));
- Assert.True(requiredStatusChecks.IncludeAdmins);
Assert.True(requiredStatusChecks.Strict);
Assert.Equal(1, requiredStatusChecks.Contexts.Count);
}
@@ -625,13 +624,12 @@ public class RepositoryBranchesClientTests
public async Task UpdatesRequiredStatusChecksWithRepositoryId()
{
var repoId = _userRepoContext.RepositoryId;
- var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "new" });
+ var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "new" });
var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoId, "master", update);
Assert.NotNull(requiredStatusChecks);
Assert.NotNull(requiredStatusChecks.Contexts);
Assert.True(requiredStatusChecks.Contexts.Contains("new"));
- Assert.True(requiredStatusChecks.IncludeAdmins);
Assert.True(requiredStatusChecks.Strict);
Assert.Equal(1, requiredStatusChecks.Contexts.Count);
}
@@ -848,6 +846,143 @@ public class RepositoryBranchesClientTests
}
}
+ public class TheGetAdminEnforcementMethod : IDisposable
+ {
+ private readonly IRepositoryBranchesClient _client;
+ private readonly RepositoryContext _userRepoContext;
+
+ public TheGetAdminEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = github.Repository.Branch;
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task GetsAdminEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+ var enforceAdmins = await _client.GetAdminEnforcement(repoOwner, repoName, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.True(enforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task GetsAdminEnforcementWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+ var enforceAdmins = await _client.GetAdminEnforcement(repoId, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.True(enforceAdmins.Enabled);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ {
+ _userRepoContext.Dispose();
+ }
+ }
+ }
+
+ public class TheAddAdminEnforcementMethod : IDisposable
+ {
+ private readonly IRepositoryBranchesClient _client;
+ private readonly RepositoryContext _userRepoContext;
+
+ public TheAddAdminEnforcementMethod()
+ {
+ var github = Helper.GetAuthenticatedClient();
+ _client = github.Repository.Branch;
+
+ _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result;
+ }
+
+ [IntegrationTest]
+ public async Task AddsAdminEnforcement()
+ {
+ var repoOwner = _userRepoContext.RepositoryOwner;
+ var repoName = _userRepoContext.RepositoryName;
+
+ await _client.RemoveAdminEnforcement(repoOwner, repoName, "master");
+ var enforceAdmins = await _client.AddAdminEnforcement(repoOwner, repoName, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.True(enforceAdmins.Enabled);
+ }
+
+ [IntegrationTest]
+ public async Task AddsAdminEnforcementoWithRepositoryId()
+ {
+ var repoId = _userRepoContext.RepositoryId;
+
+ await _client.RemoveAdminEnforcement(repoId, "master");
+ var enforceAdmins = await _client.AddAdminEnforcement(repoId, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.True(enforceAdmins.Enabled);
+ }
+
+ public void Dispose()
+ {
+ if (_userRepoContext != null)
+ {
+ _userRepoContext.Dispose();
+ }
+ }
+ }
+
+ public class TheRemoveAdminEnforcementMethod
+ {
+ private readonly IRepositoryBranchesClient _client;
+ private readonly IGitHubClient _github;
+
+ public TheRemoveAdminEnforcementMethod()
+ {
+ _github = Helper.GetAuthenticatedClient();
+ _client = _github.Repository.Branch;
+ }
+
+ [IntegrationTest]
+ public async Task RemovesAdminEnforcement()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoOwner = context.RepositoryOwner;
+ var repoName = context.RepositoryName;
+ var deleted = await _client.RemoveAdminEnforcement(repoOwner, repoName, "master");
+
+ Assert.True(deleted);
+
+ var enforceAdmins = await _client.GetAdminEnforcement(repoOwner, repoName, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.False(enforceAdmins.Enabled);
+ }
+ }
+
+ [IntegrationTest]
+ public async Task RemovesAdminEnforcementWithRepositoryId()
+ {
+ using (var context = await _github.CreateRepositoryWithProtectedBranch())
+ {
+ var repoId = context.RepositoryId;
+ var deleted = await _client.RemoveAdminEnforcement(repoId, "master");
+
+ Assert.True(deleted);
+
+ var enforceAdmins = await _client.GetAdminEnforcement(repoId, "master");
+
+ Assert.NotNull(enforceAdmins);
+ Assert.False(enforceAdmins.Enabled);
+ }
+ }
+ }
+
public class TheGetProtectedBranchRestrictionsMethod : IDisposable
{
IRepositoryBranchesClient _client;
diff --git a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
index 67600606..4211ef93 100644
--- a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
+++ b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs
@@ -30,8 +30,7 @@ namespace Octokit.Tests.Integration.Helpers
var contextUserRepo = await client.CreateRepositoryContext(userRepo);
// Protect master branch
- var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }));
+ var update = new BranchProtectionSettingsUpdate(new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), null, true);
await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update);
@@ -56,8 +55,9 @@ namespace Octokit.Tests.Integration.Helpers
// Protect master branch
var protection = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "build", "test" }),
- new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }));
+ new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
+ new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection { contextOrgTeam.TeamName }),
+ true);
await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection);
return new OrganizationRepositoryWithTeamContext
diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
index 846a77bc..bcec09a2 100644
--- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
+++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs
@@ -257,7 +257,7 @@ namespace Octokit.Tests.Clients
var connection = Substitute.For();
var client = new RepositoryBranchesClient(connection);
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
+ new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" }));
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
client.UpdateBranchProtection("owner", "repo", "branch", update);
@@ -272,7 +272,7 @@ namespace Octokit.Tests.Clients
var connection = Substitute.For();
var client = new RepositoryBranchesClient(connection);
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
+ new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" }));
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
client.UpdateBranchProtection(1, "branch", update);
@@ -286,7 +286,7 @@ namespace Octokit.Tests.Clients
{
var client = new RepositoryBranchesClient(Substitute.For());
var update = new BranchProtectionSettingsUpdate(
- new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }));
+ new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" }));
await Assert.ThrowsAsync(() => client.UpdateBranchProtection(null, "repo", "branch", update));
await Assert.ThrowsAsync(() => client.UpdateBranchProtection("owner", null, "branch", update));
@@ -405,7 +405,7 @@ namespace Octokit.Tests.Clients
{
var connection = Substitute.For();
var client = new RepositoryBranchesClient(connection);
- var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" });
+ var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" });
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
client.UpdateRequiredStatusChecks("owner", "repo", "branch", update);
@@ -419,7 +419,7 @@ namespace Octokit.Tests.Clients
{
var connection = Substitute.For();
var client = new RepositoryBranchesClient(connection);
- var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" });
+ var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" });
const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
client.UpdateRequiredStatusChecks(1, "branch", update);
@@ -432,7 +432,7 @@ namespace Octokit.Tests.Clients
public async Task EnsuresNonNullArguments()
{
var client = new RepositoryBranchesClient(Substitute.For());
- var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" });
+ var update = new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "test" });
await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks(null, "repo", "branch", update));
await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", null, "branch", update));
@@ -700,6 +700,147 @@ namespace Octokit.Tests.Clients
}
}
+ public class TheGetAdminEnforcementMethod
+ {
+ [Fact]
+ public void RequestsTheCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.GetAdminEnforcement("owner", "repo", "branch");
+
+ connection.Received()
+ .Get(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/enforce_admins"), null, previewAcceptsHeader);
+ }
+
+ [Fact]
+ public void RequestsTheCorrectUrlWithRepositoryId()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.GetAdminEnforcement(1, "branch");
+
+ connection.Received()
+ .Get(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/enforce_admins"), null, previewAcceptsHeader);
+ }
+
+ [Fact]
+ public async Task EnsuresNonNullArguments()
+ {
+ var client = new RepositoryBranchesClient(Substitute.For());
+
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement(null, "repo", "branch"));
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement("owner", null, "branch"));
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement("owner", "repo", null));
+
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement(1, null));
+
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement("", "repo", "branch"));
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement("owner", "", "branch"));
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement("owner", "repo", ""));
+
+ await Assert.ThrowsAsync(() => client.GetAdminEnforcement(1, ""));
+ }
+ }
+
+ public class TheAddAdminEnforcement
+ {
+ [Fact]
+ public void RequestsTheCorrectUrl()
+ {
+ var connection = Substitute.For();
+ var client = new RepositoryBranchesClient(connection);
+ const string previewAcceptsHeader = "application/vnd.github.loki-preview+json";
+
+ client.AddAdminEnforcement("owner", "repo", "branch");
+
+ connection.Received()
+ .Post(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/enforce_admins"), Arg.Any