Example #1
0
        public void CanMoveTest()
        {
            #region Init

            var identityMock = Mock.Create<IMQ1Identity>();
            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);
            Csla.ApplicationContext.User = principalMock;

            var state = new StateTest("Default", "Default process state.", 1, Guid.Parse("11111111-1111-1111-1111-111111111111"), true, 0, 0, 0, 0);

            var supportStatesMock = Mock.Create<SupportStatesStub>();
            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(state.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(state.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(state.Name);

            var securityConfigurations = new List<IStateConnectorSecurityConfiguration>
                {
                    new StateConnectorSecurityConfiguration(1, 1, Constants.AllPersonFieldsSystemName, true),
                };
            var connector = new StateConnector(state, securityConfigurations);

            #endregion Init

            // Find exact match in security configurations.
            // not implemented
            // todo: Add test as soon as will be implemented

            #region Find config with 2 matches

            // verification by specific person isn't implemented
            // todo: Add other tests as soon as will be implemented verification by person
            Mock.Arrange(() => identityMock.IsAdmin).Returns(false);
            Mock.Arrange(() => identityMock.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identityMock.BusinessUnitId).Returns(1);
            Mock.Arrange(() => identityMock.BusinessUnit).Returns("IT");
            Mock.Arrange(() => identityMock.RolesId).Returns(new List<int> { 1 });
            Mock.Arrange(() => identityMock.UserRoles).Returns("Developer");
            Assert.IsTrue(StateManagerTest.CanMove(supportStatesMock, connector));

            securityConfigurations = new List<IStateConnectorSecurityConfiguration> { new StateConnectorSecurityConfiguration(1, 1, Constants.AllPersonFieldsSystemName, false), };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsFalse(StateManagerTest.CanMove(supportStatesMock, connector));

            #endregion Find config with 2 matches

            #region Find config with 1 match

            // 1 match by Role
            Mock.Arrange(() => identityMock.BusinessUnitId).Returns(111);
            securityConfigurations = new List<IStateConnectorSecurityConfiguration>
                {
                    new StateConnectorSecurityConfiguration(Constants.AllBusinessUnitsId, 1, Constants.AllPersonFieldsSystemName, true),
                };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsTrue(StateManagerTest.CanMove(supportStatesMock, connector));

            securityConfigurations = new List<IStateConnectorSecurityConfiguration>
                {
                    new StateConnectorSecurityConfiguration(Constants.AllBusinessUnitsId, 1, Constants.AllPersonFieldsSystemName, false),
                };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsFalse(StateManagerTest.CanMove(supportStatesMock, connector));

            // 1 match by BusinessUnit
            Mock.Arrange(() => identityMock.BusinessUnitId).Returns(1);
            Mock.Arrange(() => identityMock.RolesId).Returns(new List<int> { 111 });
            securityConfigurations = new List<IStateConnectorSecurityConfiguration> { new StateConnectorSecurityConfiguration(1, Constants.AllRolesId, Constants.AllPersonFieldsSystemName, true), };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsTrue(StateManagerTest.CanMove(supportStatesMock, connector));

            #endregion Find config with 1 match

            #region Find config with any match

            Mock.Arrange(() => identityMock.BusinessUnitId).Returns(222);
            Mock.Arrange(() => identityMock.RolesId).Returns(new List<int>{222});
            securityConfigurations = new List<IStateConnectorSecurityConfiguration>
                                         {
                                             new StateConnectorSecurityConfiguration(
                                                 Constants.AllBusinessUnitsId,
                                                 Constants.AllRolesId,
                                                 Constants.AllPersonFieldsSystemName,
                                                 true),
                                         };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsTrue(StateManagerTest.CanMove(supportStatesMock, connector));

            securityConfigurations = new List<IStateConnectorSecurityConfiguration>
                                         {
                                             new StateConnectorSecurityConfiguration(
                                                 Constants.AllBusinessUnitsId,
                                                 Constants.AllRolesId,
                                                 Constants.AllPersonFieldsSystemName,
                                                 false),
                                         };
            connector = new StateConnector(state, securityConfigurations);
            Assert.IsFalse(StateManagerTest.CanMove(supportStatesMock, connector));

            #endregion Find config with any match

            #region identity dependent

            // if not authenticated
            Mock.Arrange(() => identityMock.IsAuthenticated).Returns(false);
            Mock.Arrange(() => identityMock.IsAdmin).Returns(true);
            Assert.IsFalse(StateManagerTest.CanMove(supportStatesMock, connector));


            // if admin
            Mock.Arrange(() => identityMock.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identityMock.IsAdmin).Returns(true);
            Assert.IsTrue(StateManagerTest.CanMove(supportStatesMock, connector));

            // identity is null
            Csla.ApplicationContext.User = null;
            Assert.IsFalse(StateManagerTest.CanMove(supportStatesMock, connector));

            #endregion identity dependent
        }
Example #2
0
        public void GetNextAvailableStatesWithMultipleApprovalsShouldNotDublicateItems()
        {
            #region Init

            const int PersonId = 1;
            var identityMock = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identityMock.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identityMock.IsAdmin).Returns(true);
            Mock.Arrange(() => identityMock.PersonId).Returns(PersonId);

            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);

            Csla.ApplicationContext.User = principalMock;

            var defaultState = new StateTest("Default", "Default process state.", 1, Guid.Parse("11111111-1111-1111-1111-111111111111"), true, 0, 0, 0, 0);
            var readyToApproveState = new StateTest("ReadyToApprove", "doc 1", 2, Guid.Parse("22222222-2222-2222-2222-222222222222"), false, 0, 0, 0, 0);
            var approvedState = new StateTest("Approved", "doc 2", 3, Guid.Parse("33333333-3333-3333-3333-333333333333"), false, 0, 0, 0, 0);
            var rejectedState = new StateTest("Rejected", "doc 3", 4, Guid.Parse("44444444-4444-4444-4444-444444444444"), false, 0, 0, 0, 0);
            var states = new List<IState> { defaultState, readyToApproveState, approvedState, rejectedState };

            defaultState.Connectors = new List<IStateConnector> { new StateConnector(readyToApproveState), };

            readyToApproveState.Connectors = new List<IStateConnector>
                                                 {
                                                     new StateConnector(defaultState),
                                                     new StateConnector(approvedState),
                                                     new StateConnector(rejectedState),
                                                     new StateConnector(rejectedState), // second connection for approval1
                                                     new StateConnector(rejectedState), // third connection for approval2
                                                 };
            approvedState.Connectors = new List<IStateConnector> { new StateConnector(rejectedState), };

            rejectedState.Connectors = new List<IStateConnector> { new StateConnector(readyToApproveState), new StateConnector(defaultState), };

            var stateManagerMock = Mock.Create<StateManager>(Behavior.CallOriginal);
            Mock.Arrange(() => stateManagerMock.States).Returns(states);

            #endregion Init

            var supportStatesMock = Mock.Create<SupportStatesStub>();
            Mock.Arrange(() => supportStatesMock.StateManager).Returns(stateManagerMock);
            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(readyToApproveState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(readyToApproveState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(readyToApproveState.Name);

            var personMock = Mock.Create<IPerson>();
            Mock.Arrange(() => personMock.Id).Returns(PersonId);

            supportStatesMock.OwnerMember = personMock;
            supportStatesMock.Owner = PersonId;

            var nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(3, nextStates.Count());
            Assert.IsTrue(nextStates.Contains(approvedState));
            Assert.IsTrue(nextStates.Contains(rejectedState));
            Assert.IsTrue(nextStates.Contains(defaultState));
        }
Example #3
0
        public void GetNextAvailableStates()
        {
            #region Init

            var identityMock = Mock.Create<IMQ1Identity>();
            Mock.Arrange(() => identityMock.IsAuthenticated).Returns(true);
            Mock.Arrange(() => identityMock.IsAdmin).Returns(true);

            var principalMock = Mock.Create<IPrincipal>();
            Mock.Arrange(() => principalMock.Identity).Returns(identityMock);

            Csla.ApplicationContext.User = principalMock;

            var defaultState = new StateTest("Default", "Default process state.", 1, Guid.Parse("11111111-1111-1111-1111-111111111111"), true, 0, 0, 0, 0);
            var readyToApproveState = new StateTest("ReadyToApprove", "doc 1", 2, Guid.Parse("22222222-2222-2222-2222-222222222222"), false, 0, 0, 0, 0);
            var approvedState = new StateTest("Approved", "doc 2", 3, Guid.Parse("33333333-3333-3333-3333-333333333333"), false, 0, 0, 0, 0);
            var rejectedState = new StateTest("Rejected", "doc 3", 4, Guid.Parse("44444444-4444-4444-4444-444444444444"), false, 0, 0, 0, 0);
            var notConnectedState = new StateTest("NotConnected", "doc 4", 5, Guid.Parse("55555555-5555-5555-5555-555555555555"), false, 0, 0, 0, 0);
            var states = new List<IState> { defaultState, readyToApproveState, approvedState, rejectedState, notConnectedState };

            defaultState.Connectors = new List<IStateConnector> { new StateConnector(readyToApproveState), };
            readyToApproveState.Connectors = new List<IStateConnector> { new StateConnector(defaultState), new StateConnector(approvedState), new StateConnector(rejectedState), };
            approvedState.Connectors = new List<IStateConnector> { new StateConnector(rejectedState), };
            rejectedState.Connectors = new List<IStateConnector> { new StateConnector(readyToApproveState), new StateConnector(defaultState), };

            var stateManagerMock = Mock.Create<StateManager>(Behavior.CallOriginal);
            Mock.Arrange(() => stateManagerMock.States).Returns(states);

            #endregion Init

            var supportStatesMock = Mock.Create<SupportStatesStub>();
            Mock.Arrange(() => supportStatesMock.StateManager).Returns(stateManagerMock);
            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(defaultState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(defaultState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(defaultState.Name);

            var nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(nextStates.Count(), 1);
            Assert.IsTrue(nextStates.Contains(readyToApproveState));

            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(readyToApproveState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(readyToApproveState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(readyToApproveState.Name);
            nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(nextStates.Count(), 3);
            Assert.IsTrue(nextStates.Contains(defaultState));
            Assert.IsTrue(nextStates.Contains(approvedState));
            Assert.IsTrue(nextStates.Contains(rejectedState));

            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(approvedState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(approvedState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(approvedState.Name);
            nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(nextStates.Count(), 1);
            Assert.IsTrue(nextStates.Contains(rejectedState));

            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(rejectedState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(rejectedState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(rejectedState.Name);
            nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(nextStates.Count(), 2);
            Assert.IsTrue(nextStates.Contains(defaultState));
            Assert.IsTrue(nextStates.Contains(readyToApproveState));

            Mock.Arrange(() => supportStatesMock.CurrentState).Returns(notConnectedState.Id);
            Mock.Arrange(() => supportStatesMock.CurrentStateGuid).Returns(notConnectedState.Guid);
            Mock.Arrange(() => supportStatesMock.CurrentStateName).Returns(notConnectedState.Name);
            nextStates = stateManagerMock.GetNextAvailableStates(supportStatesMock);
            Assert.AreEqual(nextStates.Count(), 0);
        }