Beispiel #1
0
        public void EXEC_usp_open_request_tab()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                var accessReq = new AccessRequest(req.pkId);
                accessReq.Ack();
            }

            using (var db = new SNAPDatabaseDataContext())
            {

                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                Assert.IsTrue(req.statusEnum == (byte)RequestState.Pending);
                var accessReq = new AccessRequest(req.pkId);
                accessReq.RequestToChange("TEST");
            }
            usp_open_request_tabResult t = new usp_open_request_tabResult();
            t.requestId = 0;
            t.userId = "test";
            t.userDisplayName = "test";
            t.userTitle = "test";
            t.submittedBy = "test";
            t.managerUserId = "test";
            t.managerDisplayName = "test";
            t.statusEnum = 0;
            t.isChanged = false;
            t.ticketNumber = "test";
            t.fieldId = 0;
            t.fieldLabel = "test";
            t.fieldText = "ttest";
            t.modifiedDate = DateTime.Now;
            t.createdDate = DateTime.Now;
            using (var db = new SNAPDatabaseDataContext())
            {

                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                Assert.IsTrue(req.statusEnum == (byte)RequestState.Change_Requested);

                var test = db.usp_open_request_tab(req.userId, req.pkId).First();
                Assert.IsTrue(test.requestId > 0);
                Console.WriteLine(test.requestId);
                Console.WriteLine(test.userId);
                Console.WriteLine(test.userDisplayName);
                Console.WriteLine(test.userTitle);
                Console.WriteLine(test.submittedBy);
                Console.WriteLine(test.managerUserId);
                Console.WriteLine(test.managerDisplayName);
                Console.WriteLine(test.statusEnum);
                Console.WriteLine(test.isChanged);
                Console.WriteLine(test.ticketNumber);
                Console.WriteLine(test.fieldId);
                Console.WriteLine(test.fieldLabel);
                Console.WriteLine(test.fieldText);
                Console.WriteLine(test.modifiedDate);
                Console.WriteLine(test.createdDate);
            }
        }
Beispiel #2
0
        public static WebMethodResponse AccessTeamActions(int requestId, WorkflowAction action, string comments)
        {
            //TODO: get actorId from current user
            var accessReq = new AccessRequest(requestId);
            comments = comments.FromJSONStringToObj<string>();
            switch (action)
            {
                case WorkflowAction.Ack:
                    return accessReq.Ack();
                case WorkflowAction.Change:
                    return accessReq.RequestToChange(comments);
                case WorkflowAction.Cancel:
                    return accessReq.NoAccess(action, comments);
                case WorkflowAction.Denied:
                    return accessReq.NoAccess(action, comments);

                default:
                    return new WebMethodResponse(false, "AIM", "Unknown operation");
            }
        }
Beispiel #3
0
        public void ShouldCreateWorkflowByAccessTeamUsingMgrUsrId()
        {
            var mgrUid = "pxlee";
            removeManagerActorByUserId(mgrUid);

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

                var accessReq = new AccessRequest(req.pkId);
                accessReq.Ack();

                accessReq.CreateWorkflow(mgrUid, new List<int>() { teamApprovalActorId });

                var mgrGroupId = db.SNAP_Actor_Groups.Single(g => g.actorGroupType == (byte) ActorGroupType.Manager).pkId;
                var newManagerActorId = db.SNAP_Actors.Single(a => a.userId == mgrUid && a.actor_groupId == mgrGroupId).pkId;

                var accessTeamWF = db.SNAP_Workflows.Single(x => x.requestId == req.pkId && x.actorId == accessTeamActorId);
                var accessTeamWFStates = db.SNAP_Workflow_States.Where(x => x.workflowId == accessTeamWF.pkId);
                foreach (var s in accessTeamWFStates)
                {
                    Console.WriteLine(s.workflowId + "," + s.workflowStatusEnum + "," + ((s.completedDate != null) ? s.completedDate.ToString() : "TBD"));
                }

                verifyWorkflowState(accessTeamWF, WorkflowState.Workflow_Created);

                var managerWF = db.SNAP_Workflows.Single(x => x.requestId == req.pkId && x.actorId == newManagerActorId);
                var managerWFStates = db.SNAP_Workflow_States.Where(x => x.workflowId == managerWF.pkId);
                foreach (var s in managerWFStates)
                {
                    Console.WriteLine(s.workflowId + "," + s.workflowStatusEnum + "," + ((s.completedDate != null) ? s.completedDate.ToString() : "TBD"));
                }
                verifyWorkflowStateComplete(managerWF, WorkflowState.Not_Active);
                verifyWorkflowState(managerWF, WorkflowState.Pending_Approval);

            }
        }
Beispiel #4
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 #5
0
        private AccessRequest createAndAckAccessReq(SNAPDatabaseDataContext db)
        {
            var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

            var accessReq = new AccessRequest(req.pkId);
            accessReq.Ack();

            return accessReq;
        }
Beispiel #6
0
        public void ShouldNotEnterToDifferentStateWhenNotReady()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

                var accessReq = new AccessRequest(req.pkId);
                Assert.IsFalse(accessReq.CreateServiceDeskTicket().Success);
                Assert.IsFalse(accessReq.CreateWorkflow(new List<int>() { 1, 2, 3 }).Success);
                Assert.IsFalse(accessReq.FinalizeRequest().Success);
                Assert.IsFalse(accessReq.RequestChanged().Success);
                accessReq.Ack();
                Assert.IsFalse(accessReq.CreateServiceDeskTicket().Success);
                Assert.IsFalse(accessReq.Ack().Success);
                Assert.IsFalse(accessReq.FinalizeRequest().Success);
                Assert.IsFalse(accessReq.RequestChanged().Success);
            }
        }
Beispiel #7
0
        public void ShouldHandleUpdateCreateWorkFlowByRemovingTechApproval()
        {
            int goneWFid = 0;
            // 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);
                goneWFid = wfs[0].pkId;

                // 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[0].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[0], WorkflowState.Change_Requested);

                verifyWorkflowComment(wfs[0], 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);

            }

            // recreate wf
            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
                                         });

                // get technical approval, but the last one request to change
                var wfs = accessReq.FindApprovalTypeWF(db, (byte)ActorApprovalType.Technical_Approver);
                Assert.IsTrue(wfs.Count == 1);

                /*
                var noSuchWorkflow = db.SNAP_Workflows.Where(w => w.actorId == teamApprovalActorId);
                Assert.IsTrue(noSuchWorkflow.Count() == 0);
                */

                var noSuchWorkflow = req.SNAP_Workflows.Where(w => w.actorId == teamApprovalActorId);
                Assert.IsTrue(noSuchWorkflow.Count() == 0);

                var noSuchWorkflowState = db.SNAP_Workflow_States.Where(s => s.workflowId == goneWFid);
                //var noSuchWorkflowState = reNAP_Workflow_States.Where(s => s.workflowId == goneWFid);
                Assert.IsTrue(noSuchWorkflowState.Count() == 0);

                var noSuchWorkflowComment = db.SNAP_Workflow_Comments.Where(c => c.workflowId == goneWFid);
                Assert.IsTrue(noSuchWorkflowComment.Count() == 0);

            }
        }
Beispiel #8
0
        public void ShouldCreateWorkflowByAccessTeam()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

                var accessReq = new AccessRequest(req.pkId);
                accessReq.Ack();

                accessReq.CreateWorkflow(new List<int>() { managerActorId });

                var accessTeamWF = db.SNAP_Workflows.Single(x => x.requestId == req.pkId && x.actorId == accessTeamActorId);
                var accessTeamWFStates = db.SNAP_Workflow_States.Where(x => x.workflowId == accessTeamWF.pkId);
                foreach (var s in accessTeamWFStates)
                {
                    Console.WriteLine(s.workflowId + "," + s.workflowStatusEnum + "," + ((s.completedDate != null) ? s.completedDate.ToString() : "TBD"));
                }

                verifyWorkflowState(accessTeamWF, WorkflowState.Workflow_Created);
                var managerWF = db.SNAP_Workflows.Single(x => x.requestId == req.pkId && x.actorId == managerActorId);
                var managerWFStates = db.SNAP_Workflow_States.Where(x => x.workflowId == managerWF.pkId);
                foreach (var s in managerWFStates)
                {
                    Console.WriteLine(s.workflowId + "," + s.workflowStatusEnum + "," + ((s.completedDate != null) ? s.completedDate.ToString() : "TBD"));
                }
                verifyWorkflowStateComplete(managerWF, WorkflowState.Not_Active);
                verifyWorkflowState(managerWF, WorkflowState.Pending_Approval);
            }
        }
Beispiel #9
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);
                     */

                }
        }
Beispiel #10
0
        public void ShouldAckByAccessTeam()
        {
            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");

                var accessReq = new AccessRequest(req.pkId);
                accessReq.Ack();

                var wf = db.SNAP_Workflows.Single(x => x.requestId == req.pkId && x.actorId == accessTeamActorId);
                var states = db.SNAP_Workflow_States.Where(x => x.workflowId == wf.pkId);
                foreach (var s in states)
                {
                    Console.WriteLine(s.workflowId + "," + s.workflowStatusEnum + "," + ((s.completedDate != null) ? s.completedDate.ToString() : string.Empty));
                }

                // access team wf pending ack -> pending workflow
                Assert.IsTrue(states.Count(x => x.workflowStatusEnum == (byte) WorkflowState.Pending_Acknowledgement) == states.Count(x => x.workflowStatusEnum == (byte) WorkflowState.Pending_Workflow));

            }

            using (var db = new SNAPDatabaseDataContext())
            {
                var req = db.SNAP_Requests.Single(x => x.submittedBy == "UnitTester");
                Assert.IsTrue(req.statusEnum == (byte)RequestState.Pending);
            }
        }