From 37df149b3ec70b38dfcef858171a239551fa07e1 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Mon, 14 Dec 2015 11:43:56 +1000 Subject: [PATCH] Response objects need protected setters and ctors with parameters Rework integration test examples --- .../Clients/BranchesClientTests.cs | 41 +++++++++++-------- Octokit/Models/Response/BranchProtection.cs | 15 +++++-- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/BranchesClientTests.cs b/Octokit.Tests.Integration/Clients/BranchesClientTests.cs index 00b18bebe0..944ff64fd9 100644 --- a/Octokit.Tests.Integration/Clients/BranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/BranchesClientTests.cs @@ -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); } @@ -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); @@ -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 @@ -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 diff --git a/Octokit/Models/Response/BranchProtection.cs b/Octokit/Models/Response/BranchProtection.cs index 5c0857c62d..4414de8faa 100644 --- a/Octokit/Models/Response/BranchProtection.cs +++ b/Octokit/Models/Response/BranchProtection.cs @@ -15,16 +15,17 @@ public class BranchProtection /// /// Should this branch be protected or not /// - public bool Enabled { get; set; } + public bool Enabled { get; protected set; } /// /// The information for this . /// public RequiredStatusChecks RequiredStatusChecks { get; private set; } - public BranchProtection() + public BranchProtection(bool enabled, RequiredStatusChecks requiredStatusChecks) { - RequiredStatusChecks = new RequiredStatusChecks(); + Enabled = enabled; + RequiredStatusChecks = requiredStatusChecks; } internal string DebuggerDisplay @@ -42,13 +43,19 @@ public class RequiredStatusChecks /// /// Who required status checks apply to /// - public EnforcementLevel EnforcementLevel { get; set; } + public EnforcementLevel EnforcementLevel { get; protected set; } /// /// The list of status checks to require in order to merge into this /// public ICollection Contexts { get; private set; } + public RequiredStatusChecks(EnforcementLevel enforcementLevel, ICollection contexts) + { + EnforcementLevel = enforcementLevel; + Contexts = contexts; + } + /// /// Adds the specified context to the required status checks. ///