public void CheckPermissionWithInvalidReference()
        {
            SecurityPermission permission = SecurityPermission.ForceAbortBuild;
            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.CheckPermission(manager, permission); },
                        Throws.TypeOf<BadReferenceException>().With.Message.EqualTo("Reference 'doesNotExist' is either incorrect or missing."));
        }
        public void CheckUserWithInvalidReference()
        {
            string userName = "******";
            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.CheckUser(manager, userName); },
                        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.CreateMock<IPermission>();
            ISecurityManager manager = mocks.CreateMock<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();
        }
        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 GetSetAllProperties()
        {
            string userName = "******";
            UserPermission assertion = new UserPermission();
            assertion.UserName = userName;
            Assert.AreEqual(userName, assertion.UserName, "UserName not correctly set");
            Assert.AreEqual(userName, assertion.Identifier, "Identifier not correctly set");

            assertion.DefaultRight = SecurityRight.Deny;
            Assert.AreEqual(SecurityRight.Deny, assertion.DefaultRight, "DefaultRight not correctly set");
            assertion.ForceBuildRight = SecurityRight.Deny;
            Assert.AreEqual(SecurityRight.Deny, assertion.ForceBuildRight, "ForceBuildRight not correctly set");
            assertion.SendMessageRight = SecurityRight.Deny;
            Assert.AreEqual(SecurityRight.Deny, assertion.SendMessageRight, "SendMessageRight not correctly set");
            assertion.StartProjectRight = SecurityRight.Deny;
            Assert.AreEqual(SecurityRight.Deny, assertion.StartProjectRight, "StartProjectRight not correctly set");

            assertion.RefId = "A reference";
            Assert.AreEqual("A reference", assertion.RefId, "RefId not correctly set");
        }
 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 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 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);
 }
 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 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 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);
 }