コード例 #1
0
        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."));
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
 }