public void CheckUserWithInvalidReference() { string userName = "******"; string badReference = "doesNotExist"; ISecurityManager manager = mocks.CreateMock<ISecurityManager>(); Expect.Call(manager.RetrievePermission(badReference)).Return(null); mocks.ReplayAll(); UserPermission assertion = new UserPermission(); assertion.RefId = badReference; Assert.That(delegate { assertion.CheckUser(manager, userName); }, Throws.TypeOf<BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing.")); }
public void CheckUserWithValidReference() { string userName = "******"; string goodReference = "doesExist"; IPermission goodAssertion = mocks.CreateMock<IPermission>(); ISecurityManager manager = mocks.CreateMock<ISecurityManager>(); Expect.Call(manager.RetrievePermission(goodReference)).Return(goodAssertion); Expect.Call(goodAssertion.CheckUser(manager, userName)).Return(true); mocks.ReplayAll(); UserPermission assertion = new UserPermission(); assertion.RefId = goodReference; bool result = assertion.CheckUser(manager, userName); Assert.IsTrue(result); mocks.VerifyAll(); }
public void DifferentUserNameReturnsFalse() { UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit); bool result = assertion.CheckUser(null, "janedoe"); Assert.IsFalse(result); }
public void MatchingUserNameReturnsTrue() { UserPermission assertion = new UserPermission("johndoe", SecurityRight.Inherit, SecurityRight.Inherit, SecurityRight.Allow, SecurityRight.Inherit); bool result = assertion.CheckUser(null, "johndoe"); Assert.IsTrue(result); }