Beispiel #1
0
        public static WebMethodResponse ApproverActions(int requestId, WorkflowAction action, string comments)
        {
            var currentUsrId = SnapSession.CurrentUser.DistributionGroup != null ? SnapSession.CurrentUser.DistributionGroup : SnapSession.CurrentUser.LoginId;
            int wfId = 0;

            using (var db = new SNAPDatabaseDataContext())
            {
                wfId = db.GetActiveWorkflowId(requestId, currentUsrId);
                if (wfId == 0)
                    return new WebMethodResponse(false, "Approver Action Failed", "Approver has nothing to approve");
            }

            var accessReq = new AccessRequest(requestId);
            comments = comments.FromJSONStringToObj<string>();
            return accessReq.WorkflowAck(wfId, action, comments);
        }
Beispiel #2
0
        public void ShouldReturnWorkflowIdByFromRequestIDAndUsrId()
        {
            SNAP_Request req;
            SNAP_Workflow wf;
            AccessRequest accessReq;

            using (var db = new SNAPDatabaseDataContext())
            {
                req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

                accessReq = new AccessRequest(req.pkId);
                accessReq.Ack();
                accessReq.CreateWorkflow(new List<int>() {managerActorId, teamApprovalActorId, windowsServerActorId,databaseActorId,networkShareActorId});

                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, managerUserId) == managerActorId);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, managerUserId) != 0);
                // they are not active approver yet

                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, teamApprovalUserId) == 0);
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, WindowsServerUserId) == 0);

                wf = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Manager)[0];
                accessReq.WorkflowAck(wf.pkId, WorkflowAction.Approved);
            }

            using (var db = new SNAPDatabaseDataContext())
            {
                req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                // this is the only active approver
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, teamApprovalUserId) == teamApprovalActorId);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, teamApprovalUserId) != 0);
                // this are not active approver
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, managerUserId) == 0);
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, WindowsServerUserId) == 0);
            }

            using (var db = new SNAPDatabaseDataContext())
            {
                req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                wf = accessReq.FindApprovalTypeWF(db, (byte) ActorApprovalType.Team_Approver)[0];
                accessReq.WorkflowAck(wf.pkId, WorkflowAction.Approved);
            }

            using (var db = new SNAPDatabaseDataContext()) {
                // these are active approvers
                /*
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, WindowsServerUserId) == windowsServerActorId);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, networkShareUserId) == networkShareActorId);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, databaseUserId) == databaseActorId);
                */
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, WindowsServerUserId) != 0);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, networkShareUserId) != 0);
                Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, databaseUserId) != 0);

                // there are not active approvers
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, managerUserId) == 0);
                //Assert.IsTrue(db.GetActiveWorkflowId(req.pkId, teamApprovalUserId) == 0);
            }
        }
Beispiel #3
0
        public void ShouldHandleFromManagerToTeamToLastTechicalRequestToChangeLoop()
        {
            // set up for first request to change
            using (var db = new SNAPDatabaseDataContext())
            {
                var accessReq = createTestWorkflow(db, new List<int>()
                                             {
                                                 managerActorId,
                                                 teamApprovalActorId,
                                                 windowsServerActorId,
                                                 databaseActorId,
                                                 networkShareActorId
                                             });

                // get manager approal
                var wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Manager);
                Assert.IsTrue(
                    wfs[0].SNAP_Workflow_States.Single(
                        s => s.workflowStatusEnum == (byte)WorkflowState.Pending_Approval).completedDate == null);

                accessReq.WorkflowAck(wfs[0].pkId, WorkflowAction.Approved);

                // get team approval
                wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Team_Approver);
                accessReq.WorkflowAck(wfs[0].pkId, WorkflowAction.Approved);

                // get technical approval, but the last one request to change
                wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Technical_Approver);
                accessReq.WorkflowAck(wfs[0].pkId, WorkflowAction.Approved);
                accessReq.WorkflowAck(wfs[1].pkId, WorkflowAction.Approved);
                accessReq.WorkflowAck(wfs[2].pkId, WorkflowAction.Change, "change it");

            }

            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                var accessReq = new AccessRequest(req.pkId);

                Assert.IsTrue(req.statusEnum == (byte)RequestState.Change_Requested);
                var wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Technical_Approver);
                verifyWorkflowStateComplete(wfs[0], WorkflowState.Approved);
                verifyWorkflowStateComplete(wfs[1], WorkflowState.Approved);
                verifyWorkflowStateComplete(wfs[2], WorkflowState.Change_Requested);

                verifyWorkflowComment(wfs[2], CommentsType.Requested_Change);
                wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Workflow_Admin);
                Assert.IsTrue(wfs[0].SNAP_Workflow_States.Single(s => s.workflowStatusEnum == (byte)WorkflowState.Change_Requested).completedDate == null);

            }

            for (int i = 0; i < 5; i++)
                using (var db = new SNAPDatabaseDataContext())
                {
                    var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

                    var accessReq = new AccessRequest(req.pkId);

                    accessReq.RequestChanged();
                    accessReq.Ack();
                    accessReq.CreateWorkflow(new List<int>()
                                             {
                                                 managerActorId,
                                                 teamApprovalActorId,
                                                 windowsServerActorId,
                                                 //databaseActorId,
                                                 networkShareActorId
                                             });

                    var accessWF = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Workflow_Admin);
                    var state = accessWF[0].SNAP_Workflow_States.Single(s => s.workflowStatusEnum == (byte)WorkflowState.Workflow_Created
                        && s.completedDate == null); // get lastest 'pending approval' for the workflowadmin state

                    // get manager approal
                    var wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Manager);
                    //Assert.IsTrue(wfs[0].SNAP_Workflow_States.Single(s => s.workflowStatusEnum == (byte)WorkflowState.Pending_Approval).completedDate == null);

                    accessReq.WorkflowAck(wfs[0].pkId, WorkflowAction.Approved);

                    Assert.IsTrue(
                        wfs[0].SNAP_Workflow_States.Count(
                            s => s.completedDate != null
                                && s.workflowStatusEnum == (byte)WorkflowState.Approved
                                && s.pkId > state.pkId) == 1);

                    // get team approval
                    wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Team_Approver);

                    accessReq.WorkflowAck(wfs[0].pkId, WorkflowAction.Approved);

                    Assert.IsTrue(
                            wfs[0].SNAP_Workflow_States.Count(
                                s => s.completedDate != null
                                    && s.workflowStatusEnum == (byte)WorkflowState.Approved
                                    && s.pkId > state.pkId) == 1);

                    var r = new Random();
                    //var last = r.Next(2);
                    var last = r.Next(1);
                    //var last = 0;
                    // get only one technical request to change
                    wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Technical_Approver);
                    for (int x = 0; x <= last; x++)
                    {
                        accessReq.WorkflowAck(wfs[x].pkId, WorkflowAction.Approved);
                        Assert.IsTrue(
                            wfs[0].SNAP_Workflow_States.Count(
                                s => s.completedDate != null
                                    && s.workflowStatusEnum == (byte)WorkflowState.Approved
                                    && s.pkId > state.pkId) == 1);
                    }

                    accessReq.WorkflowAck(wfs[++last].pkId, WorkflowAction.Change, "change it");
                    Assert.IsTrue(
                            wfs[last].SNAP_Workflow_States.Count(
                                s => s.completedDate != null
                                    && s.workflowStatusEnum == (byte)WorkflowState.Change_Requested
                                    && s.pkId > state.pkId) == 1);

                    /*
                    Assert.IsTrue(accessWF[0].SNAP_Workflow_States.Single(
                                s => s.completedDate == null
                                    && s.workflowStatusEnum == (byte)WorkflowState.Change_Requested)
                                   == 1);
                     */

                }
        }