public void MatchingPermissionReturnsRight() { UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit); SecurityRight result = assertion.CheckPermission(null, SecurityPermission.ForceAbortBuild); Assert.AreEqual(SecurityRight.Allow, result); }
public void DifferentPermissionReturnsInherited() { UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit); SecurityRight result = assertion.CheckPermission(null, SecurityPermission.SendMessage); Assert.AreEqual(SecurityRight.Inherit, result); }
public void CorrectPermissionsReturnedStartProject() { UserPermission assertion = new UserPermission("johnDoe", SecurityRight.Deny, SecurityRight.Deny, SecurityRight.Deny, SecurityRight.Allow); SecurityRight right = assertion.CheckPermission(null, SecurityPermission.StartStopProject); Assert.AreEqual(SecurityRight.Allow, right); }
public void CorrectPermissionsReturnedForceBuild() { UserPermission assertion = new UserPermission("johnDoe", SecurityRight.Deny, SecurityRight.Deny, SecurityRight.Allow, SecurityRight.Deny); SecurityRight right = assertion.CheckPermission(null, SecurityPermission.ForceAbortBuild); Assert.AreEqual(SecurityRight.Allow, right); }
public void CorrectPermissionsReturnedSendMessage() { UserPermission assertion = new UserPermission("johnDoe", SecurityRight.Deny, SecurityRight.Allow, SecurityRight.Deny, SecurityRight.Deny); SecurityRight right = assertion.CheckPermission(null, SecurityPermission.SendMessage); Assert.AreEqual(SecurityRight.Allow, right); }
public void CheckPermissionWithInvalidReference() { SecurityPermission permission = SecurityPermission.ForceAbortBuild; string badReference = "doesNotExist"; ISecurityManager manager = mocks.Create <ISecurityManager>(MockBehavior.Strict).Object; Mock.Get(manager).Setup(_manager => _manager.RetrievePermission(badReference)).Returns((IPermission)null).Verifiable(); UserPermission assertion = new UserPermission(); assertion.RefId = badReference; Assert.That(delegate { assertion.CheckPermission(manager, permission); }, Throws.TypeOf <BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing.")); }
public void CheckPermissionWithInvalidReference() { SecurityPermission permission = SecurityPermission.ForceAbortBuild; string badReference = "doesNotExist"; ISecurityManager manager = mocks.StrictMock <ISecurityManager>(); Expect.Call(manager.RetrievePermission(badReference)).Return(null); mocks.ReplayAll(); UserPermission assertion = new UserPermission(); assertion.RefId = badReference; Assert.That(delegate { assertion.CheckPermission(manager, permission); }, Throws.TypeOf <BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing.")); }
public void CheckPermissionWithValidReference() { SecurityPermission permission = SecurityPermission.ForceAbortBuild; string goodReference = "doesExist"; IPermission goodAssertion = mocks.Create <IPermission>(MockBehavior.Strict).Object; ISecurityManager manager = mocks.Create <ISecurityManager>(MockBehavior.Strict).Object; Mock.Get(manager).Setup(_manager => _manager.RetrievePermission(goodReference)).Returns(goodAssertion).Verifiable(); Mock.Get(goodAssertion).Setup(_goodAssertion => _goodAssertion.CheckPermission(manager, permission)).Returns(SecurityRight.Allow).Verifiable(); UserPermission assertion = new UserPermission(); assertion.RefId = goodReference; SecurityRight result = assertion.CheckPermission(manager, permission); Assert.AreEqual(SecurityRight.Allow, result); mocks.VerifyAll(); }
public void CheckPermissionWithValidReference() { SecurityPermission permission = SecurityPermission.ForceAbortBuild; string goodReference = "doesExist"; IPermission goodAssertion = mocks.StrictMock <IPermission>(); ISecurityManager manager = mocks.StrictMock <ISecurityManager>(); Expect.Call(manager.RetrievePermission(goodReference)).Return(goodAssertion); Expect.Call(goodAssertion.CheckPermission(manager, permission)).Return(SecurityRight.Allow); mocks.ReplayAll(); UserPermission assertion = new UserPermission(); assertion.RefId = goodReference; SecurityRight result = assertion.CheckPermission(manager, permission); Assert.AreEqual(SecurityRight.Allow, result); mocks.VerifyAll(); }