public void Validate_WhenModelIsValid_ReturnsTrue()
        {
            AmendDirectDebitVm amendDirectDebitVm = new AmendDirectDebitVm()
            {
                OutstandingBalance      = 20.0m,
                DirectDebitAmount       = 10.0m,
                PlanFrequency           = "*freq",
                EarliestStartDate       = new DateTime(2018, 10, 4),
                LatestStartDate         = new DateTime(2018, 10, 6),
                PlanStartDate           = new DateTime(2018, 10, 5),
                SelectedPlanSetupOption = PlanSetupOptions.AverageSetupValue
            };

            Assert.IsTrue(_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm));
        }
        public async Task <bool> AmendDirectDebitPlan(IUserIdentity loggedInUser,
                                                      IApplicationSessionState applicationSessionState,
                                                      Guid lowellReferenceSurrogateKey,
                                                      AmendDirectDebitVm amendDirectDebitVmWithUserEntries,
                                                      string caseflowUserId)
        {
            // Must be a logged in user
            if (loggedInUser.IsLoggedInUser == false)
            {
                throw new ApplicationException("AmendDirectDebitPlan can only be used for a logged in user due to requiring email address.");
            }

            // Reload from CaseFlow
            AmendDirectDebitVm amendDirectDebitVm = await _buildAmendDirectDebitVmService.Build(applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId);

            // Populate user entries, giving a clean model to validate
            _buildAmendDirectDebitVmService.UpdateFieldsFromUserEntries(amendDirectDebitVm, amendDirectDebitVmWithUserEntries);

            if (!_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm))
            {
                return(false);
            }

            // Ensure we are not using this - must use clean, validated model (defensive coding)
            // ReSharper disable once RedundantAssignment
            amendDirectDebitVmWithUserEntries = null;

            var directDebitPaymentDto = new DirectDebitPaymentDto
            {
                Frequency        = _directDebitFrequencyTranslator.TranslateClientScriptCompatibleValueToDescription(amendDirectDebitVm.PlanFrequency),
                LowellReference  = amendDirectDebitVm.LowellReference,
                PaymentAmount    = amendDirectDebitVm.DirectDebitAmount.Value,
                StartDate        = amendDirectDebitVm.PlanStartDate.ToShortDateString(),
                PlanTotal        = amendDirectDebitVm.OutstandingBalance,
                DiscountAmount   = amendDirectDebitVm.DiscountAmount,
                DiscountAccepted = amendDirectDebitVm.DiscountedBalance < amendDirectDebitVm.OutstandingBalance,
                EmailAddress     = loggedInUser.EmailAddress,
                User             = loggedInUser.IsLoggedInUser ? "WebUser" : "WebAnon"
            };

            await _sendAmendDirectDebitPlanProcess.SendAmendDirectDebitPlanAsync(directDebitPaymentDto);

            return(true);
        }