Пример #1
0
        public VirtualApprenticeship AddVirtualApprenticeship(string courseId, string courseTitle, int level, int startMonth, int startYear, int numberOfApprentices, int numberOfMonths, decimal totalCost, FundingSource fundingSource)
        {
            var virtualApprenticeship = new VirtualApprenticeship
            {
                CourseId          = courseId,
                CourseTitle       = courseTitle,
                Level             = level,
                ApprenticesCount  = numberOfApprentices,
                StartDate         = new DateTime(startYear, startMonth, 1),
                TotalCost         = totalCost,
                TotalInstallments = (short)numberOfMonths,
                FundingSource     = fundingSource
            };
            var validationResults = _validator.Validate(virtualApprenticeship);

            if (!validationResults.All(result => result.IsValid))
            {
                throw new InvalidOperationException($"The virtual apprenticeship is invalid.  Failures: {validationResults.Aggregate(string.Empty, (currText, failure) => $"{currText}{failure}, ")}");
            }
            virtualApprenticeship.Id = Guid.NewGuid().ToString("N");
            virtualApprenticeship.TotalCompletionAmount  = (totalCost / 100) * 20;
            virtualApprenticeship.TotalInstallmentAmount = ((totalCost / 100) * 80) / numberOfMonths;
            Model.Apprenticeships.Add(virtualApprenticeship);
            return(virtualApprenticeship);
        }
Пример #2
0
        public void Should_Update_Apprenticeship()
        {
            var a = new VirtualApprenticeship
            {
                Id                = Guid.NewGuid().ToString("N"),
                CourseId          = "ABBA12",
                CourseTitle       = "ABBA 12",
                Level             = 1,
                ApprenticesCount  = 10,
                StartDate         = new DateTime(DateTime.Today.Year + 1, 5, 1),
                TotalInstallments = 24,
                TotalCost         = 2000,
            };

            _model.Apprenticeships.Add(a);

            var estimation = ResolveEstimation();

            estimation.UpdateApprenticeship(a.Id, 10, DateTime.Today.Year + 2, 6, 12, 1000);

            estimation.Apprenticeships.Count().Should().Be(1);

            var apprenticeship = estimation.Apprenticeships.First();

            apprenticeship.CourseId.Should().Be("ABBA12");
            apprenticeship.CourseTitle.Should().Be("ABBA 12");
            apprenticeship.Level.Should().Be(1);
            apprenticeship.ApprenticesCount.Should().Be(6);
            apprenticeship.StartDate.Year.Should().Be(DateTime.Today.Year + 2);
            apprenticeship.StartDate.Month.Should().Be(10);
            apprenticeship.TotalCost.Should().Be(1000);
            apprenticeship.TotalInstallments.Should().Be(12);

            apprenticeship.TotalCompletionAmount.Should().Be(200);
            Decimal.Round(apprenticeship.TotalInstallmentAmount, 1).Should().Be(66.7M);
        }