Create RepositoryBranchesClient (#1437)

* Tidy up location of existing EditBranch tests

* Create RepositoryBranchesClient and move the GetBranch GetAllBranches and EditBranch methods to it, obsoleting the old ones

* Add tests for the new RepositoryBranchesClient (keeping old tests for RepositoriesClient around for now)

* Disable obsolete warning on reactive client temporarily

* Create observable repository branches client and move GetBranch, GetAllBranches, EditBranch methods to it, obsoleting the old ones

* Add tests for observable repository branches client, leave old tests in place for now

* Fix projects...

* Fix whitespace
This commit is contained in:
Ryan Gribble
2016-08-08 22:00:37 +10:00
committed by GitHub
parent 23d9310133
commit ef0da2f84d
26 changed files with 1424 additions and 173 deletions
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
@@ -1370,6 +1371,12 @@ public class RepositoriesClientTests
var branches = await github.Repository.GetAllBranches(7528679);
Assert.NotEmpty(branches);
// Ensure Protection attribute is deserialized
foreach (var branch in branches)
{
Assert.NotNull(branch.Protection);
}
}
[IntegrationTest]
@@ -1684,4 +1691,102 @@ public class RepositoriesClientTests
Assert.NotEqual(firstPage[4].Name, secondPage[4].Name);
}
}
public class TheEditBranchMethod
{
private readonly IRepositoriesClient _fixture;
private readonly RepositoryContext _context;
public TheEditBranchMethod()
{
var github = Helper.GetAuthenticatedClient();
_context = github.CreateRepositoryContext("source-repo").Result;
_fixture = github.Repository;
}
public async Task CreateTheWorld()
{
// Set master branch to be protected, with some status checks
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2" });
var update = new BranchUpdate();
update.Protection = new BranchProtection(true, requiredStatusChecks);
var newBranch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
}
[IntegrationTest]
public async Task ProtectsBranch()
{
// Set master branch to be protected, with some status checks
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1", "check2", "check3" });
var update = new BranchUpdate();
update.Protection = new BranchProtection(true, requiredStatusChecks);
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
// Ensure a branch object was returned
Assert.NotNull(branch);
// Retrieve master branch
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
// Assert the changes were made
Assert.Equal(branch.Protection.Enabled, true);
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Everyone);
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 3);
}
[IntegrationTest]
public async Task RemoveStatusCheckEnforcement()
{
await CreateTheWorld();
// Remove status check enforcement
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, new List<string> { "check1" });
var update = new BranchUpdate();
update.Protection = new BranchProtection(true, requiredStatusChecks);
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
// Ensure a branch object was returned
Assert.NotNull(branch);
// Retrieve master branch
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
// Assert the changes were made
Assert.Equal(branch.Protection.Enabled, true);
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 1);
}
[IntegrationTest]
public async Task UnprotectsBranch()
{
await CreateTheWorld();
// Unprotect branch
// Deliberately set Enforcement and Contexts to some values (these should be ignored)
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, new List<string> { "check1" });
var update = new BranchUpdate();
update.Protection = new BranchProtection(false, requiredStatusChecks);
var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
// Ensure a branch object was returned
Assert.NotNull(branch);
// Retrieve master branch
branch = await _fixture.GetBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master");
// Assert the branch is unprotected, and enforcement/contexts are cleared
Assert.Equal(branch.Protection.Enabled, false);
Assert.Equal(branch.Protection.RequiredStatusChecks.EnforcementLevel, EnforcementLevel.Off);
Assert.Equal(branch.Protection.RequiredStatusChecks.Contexts.Count, 0);
}
}
}