예제 #1
0
 public void SetUp()
 {
     _validViewModel = new AddEditApprenticeshipsViewModel
     {
         NumberOfApprentices = 2,
         TotalInstallments   = 24,
         StartDateMonth      = DateTime.Today.Month,
         StartDateYear       = DateTime.Today.Year,
         TotalCostAsString   = "12000",
         IsTransferFunded    = "",
         Course = new Models.Estimation.ApprenticeshipCourse
         {
             CourseType     = Models.Estimation.ApprenticeshipCourseType.Standard,
             Duration       = 12,
             FundingCap     = 2,
             Id             = "hello",
             Level          = 2,
             Title          = "Test Standard",
             FundingPeriods = new List <Models.Estimation.FundingPeriod>
             {
                 new Models.Estimation.FundingPeriod
                 {
                     EffectiveFrom = DateTime.Today.AddMonths(-1),
                     EffectiveTo   = DateTime.Today.AddMonths(11),
                     FundingCap    = 6000
                 }
             }
         }
     };
     _validator = new AddEditApprenticeshipViewModelValidator();
 }
예제 #2
0
        public async Task Apprenticeship_Must_Have_Total_Cost(string costAsString, bool shouldError)
        {
            var fundingPeriods = new List <FundingPeriod>
            {
                new FundingPeriod {
                    EffectiveFrom = DateTime.MinValue, EffectiveTo = DateTime.MaxValue, FundingCap = 20 * 1000
                }
            };

            var vm = new AddEditApprenticeshipsViewModel
            {
                Course = new ApprenticeshipCourse {
                    Id = "123", FundingPeriods = fundingPeriods
                },
                TotalCostAsString   = costAsString,
                NumberOfApprentices = 2,
                StartDateYear       = DateTime.Now.Year,
                StartDateMonth      = DateTime.Now.Month
            };

            _moqer.GetMock <IAddApprenticeshipOrchestrator>()
            .Setup(x => x.UpdateAddApprenticeship(vm))
            .Returns(Task.FromResult(vm));

            _moqer.GetMock <IAddApprenticeshipOrchestrator>()
            .Setup(x => x.GetApprenticeshipAddSetup(false))
            .Returns(new AddEditApprenticeshipsViewModel {
                Courses = new List <ApprenticeshipCourse>()
            });

            await _controller.Save(vm, "ABBA12", "default");

            _controller.ViewData.ModelState.Count
            .Should().Be(shouldError ? 1 : 0);
        }
예제 #3
0
        public async Task Apprenticeship_Must_Have_Course()
        {
            var vm = new AddEditApprenticeshipsViewModel
            {
                Course            = null,
                TotalCostAsString = "10",
                StartDateYear     = DateTime.Now.Year,
                StartDateMonth    = DateTime.Now.Month
            };

            _moqer.GetMock <IAddApprenticeshipOrchestrator>()
            .Setup(x => x.UpdateAddApprenticeship(vm))
            .Returns(Task.FromResult(vm));

            _moqer.GetMock <IAddApprenticeshipOrchestrator>()
            .Setup(x => x.GetApprenticeshipAddSetup(false))
            .Returns(new AddEditApprenticeshipsViewModel {
                Courses = new List <ApprenticeshipCourse>()
            });

            await _controller.Save(vm, "ABBA12", "default");

            _controller.ViewData.ModelState.Count
            .Should().Be(1);
        }
 public void SetUp()
 {
     _validViewModel = new AddEditApprenticeshipsViewModel
     {
         NumberOfApprentices = 2,
         TotalInstallments   = 24,
         StartDateMonth      = DateTime.Today.Month,
         StartDateYear       = DateTime.Today.Year,
         TotalCostAsString   = "12000"
     };
     _validator = new AddEditApprenticeshipViewModelValidator();
 }
예제 #5
0
        public async Task TestingCommasAddedToTotalCostAsStringSetsExcpectedTotalCostValues(string totalCostAsStringInput, string totalCostAsStringOutput)
        {
            var orchestrator = _moqer.Resolve <AddApprenticeshipOrchestrator>();
            var vm           = new AddEditApprenticeshipsViewModel()
            {
                NumberOfApprentices = 1,
                TotalCostAsString   = totalCostAsStringInput,
                Course = new ApprenticeshipCourse()
            };

            // Act
            var res = await orchestrator.UpdateAddApprenticeship(vm);

            // Assert
            AssertionExtensions.Should((string)res.TotalCostAsString).Be(totalCostAsStringOutput);
        }
예제 #6
0
        public async Task <AddEditApprenticeshipsViewModel> UpdateAddApprenticeship(AddEditApprenticeshipsViewModel viewModel)
        {
            var course =
                viewModel.Course.Id != null
                    ? await _apprenticeshipCourseService.GetApprenticeshipCourse(viewModel.Course.Id)
                    : null;

            var totalCostAsString = (decimal.TryParse(viewModel.TotalCostAsString, out decimal result))
                ? result.FormatValue()
                : viewModel.TotalCostAsString = string.Empty;

            viewModel.Course            = course;
            viewModel.TotalCostAsString = totalCostAsString;

            return(viewModel);
        }
예제 #7
0
        public async Task <ActionResult> Save(AddEditApprenticeshipsViewModel vm, string hashedAccountId, string estimationName)
        {
            var viewModel = await _addApprenticeshipOrchestrator.UpdateAddApprenticeship(vm);

            var result = _validator.ValidateAdd(vm);

            foreach (var r in result)
            {
                ModelState.AddModelError(r.Key, r.Value);
            }


            if (!ModelState.IsValid)
            {
                viewModel.Courses = _addApprenticeshipOrchestrator.GetApprenticeshipAddSetup(false).Courses;

                return(View("AddApprenticeships", viewModel));
            }

            await _addApprenticeshipOrchestrator.StoreApprenticeship(viewModel, hashedAccountId, estimationName);

            return(RedirectToAction(nameof(CostEstimation), new { hashedaccountId = hashedAccountId, estimateName = estimationName }));
        }
예제 #8
0
        public async Task StoreApprenticeship(AddEditApprenticeshipsViewModel vm, string hashedAccountId, string estimationName)
        {
            var accountEstimation = await GetAccountEstimation(hashedAccountId);

            var fundingSource = vm.IsTransferFunded == "on"
               ? Models.Payments.FundingSource.Transfer
               : Models.Payments.FundingSource.Levy;

            if (vm.ApprenticeshipsId == null)
            {
                accountEstimation.AddVirtualApprenticeship(vm.Course.Id, vm.Course.Title, vm.Course.Level,
                                                           vm.StartDateMonth, vm.StartDateYear,
                                                           vm.NumberOfApprentices, vm.TotalInstallments,
                                                           vm.TotalCostAsString.ToDecimal(), fundingSource);
            }
            else
            {
                accountEstimation.UpdateApprenticeship(vm.ApprenticeshipsId, vm.StartDateMonth, vm.StartDateYear, vm.NumberOfApprentices, vm.TotalInstallments, vm.TotalCostAsString.ToDecimal());
            }


            _logger.Debug($"Storing Apprenticeship for account {hashedAccountId}, estimation name: {estimationName}, Course: {vm.Course}");
            await _accountEstimationRepository.Store(accountEstimation);
        }