public void NewAppNeedInitialToInReviewNeedUwDecision()
        {
            LoanApplicationCoreStateObject loanApplicationInfo         = TransitionToReviewingState(borrowerRegistration);
            ResponseObject <GetLoanApplicationStatusResponse> response = coreLoanApplicationStatusClient
                                                                         .GetStatusByLoanApplication(loanApplicationInfo.LoanApplicationGuid.ToString());

            if (response.content == null ||
                response.content.LoanApplicationState != LoanApplicationState.Reviewing ||
                response.content.LoanApplicationStatus != LoanApplicationStatus.NewAppNeedInitialReview)
            {
                var message = response.content == null ? "No response was returned, null content object." : $"State = {response.content.LoanApplicationState.ToString()}, Status = {response.content.LoanApplicationStatus.ToString()}";
                log.Error("Failing test due to invalid setup state for our loan application...");
                Assert.Fail($"Loan Application State or Status not in the valid state or status; unable to continue - {message}");
            }

            AssignAgentToLoanApplication((Guid)loanApplicationInfo.LoanApplicationGuid, AgentRole.UW, "clpuw");
            var coreLoanAppClient = new LoanApplicationClient();
            var workflowResponse  = coreLoanAppClient.WorkflowAction(loanApplicationInfo.LoanApplicationGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);

            Assert.That(workflowResponse.statusCode == HttpStatusCode.OK, $"Invalid status code returned when attempting workflow transition:  {workflowResponse.statusCode}");
            log.Info("Checking the actual status of our loan application after transitioning to SendToUW");

            var statusResponse = coreLoanApplicationStatusClient.GetStatusByLoanApplication(loanApplicationInfo.LoanApplicationGuid.ToString());

            log.Info("transitioning the status...");

            coreLoanApplicationStatusClient
            .UpdateStatusByLoanApplication(loanApplicationInfo.LoanApplicationGuid.ToString());
            Assert.That(statusResponse.statusCode == HttpStatusCode.OK, $"We received an invalid status code from our core loanapplication status request:  {statusResponse.statusCode}.");
            Assert.NotNull(statusResponse.content, "We have a response but the response content is null for our status request");
            ValidateApplicationState(statusResponse.content, LoanApplicationState.Reviewing, LoanApplicationStatus.InReviewNeedDecision);
            log.Info("We have successfully transitioned our loan application into the Reviewing/InReviewNeedDecision.  Now we must check to see if we have an Agent assigned.");
        }
        public void ReviewingTransitionStatuses(string testcaseName, LoanApplicationStatus startingStatus, LoanApplicationWorkflowAction action, LoanApplicationState expectedState, LoanApplicationStatus expectedStatus, string agentName, AgentRole agentRole)
        {
            var loanApplicationInfo = TransitionToReviewingState(borrowerRegistration);

            // If we're already are at InReviewNeedDecision, then we don't need to do any further transitioning for our stating status.
            if (startingStatus != LoanApplicationStatus.NewAppNeedInitialReview)
            {
                if (!ReviewStatusTransitions(loanApplicationInfo.LoanApplicationGuid, startingStatus))
                {
                    Assert.Fail($"Unable to transition to the desired loan status of {startingStatus.ToString()}...stopping test.");
                }
            }
            log.Info($"We're in the expected status of {startingStatus.ToString()}.  Transitioning to {expectedStatus.ToString()}.");

            //If we provide an agentname, that means we need to add a new agent with the given role to the BCD
            if (!String.IsNullOrEmpty(agentName))
            {
                AssignAgentToLoanApplication((Guid)loanApplicationInfo.LoanApplicationGuid, AgentRole.UWM, "clpuwm");
            }

            var workflowResponse = loanApplicationClient.WorkflowAction(loanApplicationInfo.LoanApplicationGuid.ToString(), action);

            Assert.That(workflowResponse.statusCode == HttpStatusCode.OK, $"We weren't able to successfully run the workflow transition request successfully.  Status code {workflowResponse.statusCode}");
            log.Info($"Checking to see that our loan application in the expected {expectedState}/{expectedStatus} state/status.");

            coreLoanApplicationStatusClient
            .UpdateStatusByLoanApplication(loanApplicationInfo.LoanApplicationGuid.ToString());

            var statusResponse = coreLoanApplicationStatusClient
                                 .GetStatusByLoanApplication(loanApplicationInfo
                                                             .LoanApplicationGuid.ToString());

            Assert.That(statusResponse.statusCode == HttpStatusCode.OK, $"We weren't able to get the status of our loanapplication successfully.  Status Code {statusResponse.statusCode.ToString()}");
            Assert.NotNull(statusResponse.content, "We received no content for our status request.");
            ValidateApplicationState(statusResponse.content, expectedState, expectedStatus);
            log.Info($"Validated the successful transition from {startingStatus} to {expectedStatus} loan application guid:  {loanApplicationInfo.LoanApplicationGuid}");
        }
        public void PipelineLoanStateTransitionToAccepting()
        {
            LoanApplicationCoreStateObject borrowerState = TransitionToReviewingState(borrowerRegistration);
            int emailCount  = GetEmails(emailAddress).Count;
            var stateClient = new LoanApplicationStateClient();
            var noContent   = new ResponseObject <EmptyResult>();

            noContent = loanApplicationClient
                        .WorkflowAction(borrowerState.LoanApplicationGuid.ToString(), LoanApplicationWorkflowAction.Counter);
            noContent = loanApplicationClient
                        .SetLoanAppToAccept(borrowerState.LoanApplicationGuid.ToString());
            Assert.That(noContent.statusCode == HttpStatusCode.OK);

            var stateResult = loanApplicationClient.Status(borrowerState.LoanApplicationGuid.ToString());

            Assert.That(stateResult.content.LoanApplicationState == LoanApplicationState.Accepting);

            List <string> emails = GetEmails(emailAddress);

            Assert.That(emails.Count > emailCount);
        }
        public static bool ReviewStatusTransitions(Guid?loanAppInfoGuid, LoanApplicationStatus targetStatus)
        {
            var client = new LoanApplicationClient();

            switch (targetStatus)
            {
            case (LoanApplicationStatus.InReviewNeedDecision):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                break;

            case (LoanApplicationStatus.EscalatedNeedFAReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.EscalateToFA);
                break;

            case (LoanApplicationStatus.EscalatedNeedFAManagerReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.EscalateToFA);
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FAM, "clpfam");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.EscalateToManager);
                break;

            case (LoanApplicationStatus.EscalatedNeedUWManagerReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UWM, "clpuwm");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.EscalateToManager);
                break;

            case (LoanApplicationStatus.EditRequestNeedUWReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString(), "Approve");
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Counter);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Approve);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                break;

            case (LoanApplicationStatus.ReturnedfromVerbalNeedUWReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString());
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Counter);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Approve);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Escalate);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                break;

            case (LoanApplicationStatus.ReturnedfromFundingNeedUWManagerReview):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UWM, "clpuwm");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString());
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Counter);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Approve);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.VerbalQueue);
                VerbalVerification(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.PassVerbal);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.ReturnToUW);
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.EscalateToManager);
                break;

            case (LoanApplicationStatus.ApprovedPendingNote):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString());
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Approve);
                break;

            case (LoanApplicationStatus.NoteSignedNeedVerbal):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString());
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Counter);
                SignLoanPacket(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.VerbalQueue);
                break;

            case (LoanApplicationStatus.VerbalVerifiedNeedFunding):
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.UW, "clpuw");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FA, "clpfa");
                AssignAgentToLoanApplication((Guid)loanAppInfoGuid, AgentRole.FAM, "clpfam");
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.SendToUW);
                UpdateLoanApplicationPassStips(loanAppInfoGuid.ToString());
                DispositionOfUploadedFiles(loanAppInfoGuid.ToString());
                SignPromissoryAndFTIL(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.Counter);
                SignLoanPacket(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.VerbalQueue);
                VerbalVerification(loanAppInfoGuid.ToString());
                client.WorkflowAction(loanAppInfoGuid.ToString(), LoanApplicationWorkflowAction.PassVerbal);
                break;

            default:
                log.Error($"Functionality for LoanApplicationStatus {targetStatus.ToString()} is Not Available for this method");
                return(false);
            }

            var statusClient = new LoanApplicationStatusClient();

            statusClient.UpdateStatusByLoanApplication(loanAppInfoGuid.ToString());
            var statusResponse = statusClient.GetStatusByLoanApplication(loanAppInfoGuid.ToString());

            if (statusResponse.statusCode != HttpStatusCode.OK || statusResponse.content == null)
            {
                log.Error($"Error in checking the response of our status request (null content or invalid statuscode).");
                return(false);
            }
            else
            {
                if (statusResponse.content.LoanApplicationStatus == targetStatus)
                {
                    return(true);
                }
                else
                {
                    log.Error($"Wrong status generated for our request to transition to {targetStatus.ToString()} we received {statusResponse.content.LoanApplicationStatus.ToString()}.");
                    return(false);
                }
            }
        }