Skip to content

Commit

Permalink
Response objects need protected setters and ctors with parameters
Browse files Browse the repository at this point in the history
Rework integration test examples
  • Loading branch information
ryangribble committed Dec 14, 2015
1 parent a729ab7 commit 37df149
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
41 changes: 23 additions & 18 deletions Octokit.Tests.Integration/Clients/BranchesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ public TheEditBranchesMethod()
public async Task CreateTheWorld()
{
// Set master branch to be protected, with some status checks
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, null);
requiredStatusChecks.AddContext("check1");
requiredStatusChecks.AddContext("check2");

var update = new BranchUpdate();
update.Protection.Enabled = true;
update.Protection.RequiredStatusChecks.EnforcementLevel = EnforcementLevel.Everyone;
update.Protection.RequiredStatusChecks.AddContext("check1");
update.Protection.RequiredStatusChecks.AddContext("check2");
update.Protection = new BranchProtection(true, requiredStatusChecks);

var newBranch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);
}
Expand All @@ -55,12 +56,13 @@ public async Task CreateTheWorld()
public async Task ProtectsBranch()
{
// Set master branch to be protected, with some status checks
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, null);
requiredStatusChecks.AddContext("check1");
requiredStatusChecks.AddContext("check2");
requiredStatusChecks.AddContext("check3");

var update = new BranchUpdate();
update.Protection.Enabled = true;
update.Protection.RequiredStatusChecks.EnforcementLevel = EnforcementLevel.Everyone;
update.Protection.RequiredStatusChecks.AddContext("check1");
update.Protection.RequiredStatusChecks.AddContext("check2");
update.Protection.RequiredStatusChecks.AddContext("check3");
update.Protection = new BranchProtection(true, requiredStatusChecks);

var branch = await _fixture.EditBranch(_context.Repository.Owner.Login, _context.Repository.Name, "master", update);

Expand All @@ -81,11 +83,13 @@ public async Task RemoveStatusCheckEnforcement()
{
await CreateTheWorld();

// Clear status checks
// Remove status check enforcement
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Off, null);
requiredStatusChecks.AddContext("check1");

var update = new BranchUpdate();
update.Protection.Enabled = true;
update.Protection.RequiredStatusChecks.EnforcementLevel = EnforcementLevel.Off;
update.Protection.RequiredStatusChecks.AddContext("check1");
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
Expand All @@ -106,12 +110,13 @@ public async Task UnprotectsBranch()
await CreateTheWorld();

// Unprotect branch
var update = new BranchUpdate();
update.Protection.Enabled = false;

// Deliberately set Enforcement and Contexts to some values (these should be ignored)
update.Protection.RequiredStatusChecks.EnforcementLevel = EnforcementLevel.Everyone;
update.Protection.RequiredStatusChecks.AddContext("check1");
var requiredStatusChecks = new RequiredStatusChecks(EnforcementLevel.Everyone, null);
requiredStatusChecks.AddContext("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
Expand Down
15 changes: 11 additions & 4 deletions Octokit/Models/Response/BranchProtection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ public class BranchProtection
/// <summary>
/// Should this branch be protected or not
/// </summary>
public bool Enabled { get; set; }
public bool Enabled { get; protected set; }

/// <summary>
/// The <see cref="RequiredStatusChecks"/> information for this <see cref="Branch"/>.
/// </summary>
public RequiredStatusChecks RequiredStatusChecks { get; private set; }

public BranchProtection()
public BranchProtection(bool enabled, RequiredStatusChecks requiredStatusChecks)
{
RequiredStatusChecks = new RequiredStatusChecks();
Enabled = enabled;
RequiredStatusChecks = requiredStatusChecks;
}

internal string DebuggerDisplay
Expand All @@ -42,13 +43,19 @@ public class RequiredStatusChecks
/// <summary>
/// Who required status checks apply to
/// </summary>
public EnforcementLevel EnforcementLevel { get; set; }
public EnforcementLevel EnforcementLevel { get; protected set; }

/// <summary>
/// The list of status checks to require in order to merge into this <see cref="Branch"/>
/// </summary>
public ICollection<string> Contexts { get; private set; }

public RequiredStatusChecks(EnforcementLevel enforcementLevel, ICollection<string> contexts)
{
EnforcementLevel = enforcementLevel;
Contexts = contexts;
}

/// <summary>
/// Adds the specified context to the required status checks.
/// </summary>
Expand Down

0 comments on commit 37df149

Please sign in to comment.