public void Then_days_in_learning_is_created_with_the_expected_number_of_days_when_the_collection_period_census_date_is_before_the_last_LearningPeriod_end_date()
        {
            // arrange
            _learningPeriod3 = new LearningPeriod(_learningPeriod3.StartDate, _censusDate.AddDays(1));
            _learningPeriods = new List <LearningPeriod>()
            {
                new LearningPeriod(_startDate.AddDays(-60), _startDate.AddDays(-60 + 15)),
                new LearningPeriod(_startDate.AddDays(-30), _startDate.AddDays(-30 + 12)),
                _learningPeriod3
            };
            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .With(l => l.LearningPeriods, _learningPeriods)
                        .With(l => l.DaysInLearnings, new List <DaysInLearning>())
                        .Create();

            int expectedDays = 18 + 16 + 13;

            _sut = Sut(_sutModel);

            // act
            _sut.SetDaysInLearning(_collectionPeriod);

            // assert
            var daysInLearning = _sut.GetModel().DaysInLearnings.Single();

            daysInLearning.CollectionYear.Should().Be(_collectionPeriod.AcademicYear);
            daysInLearning.CollectionPeriodNumber.Should().Be(_collectionPeriod.PeriodNumber);
            daysInLearning.NumberOfDays.Should().Be(expectedDays);
        }
示例#2
0
        public void LearnerDTOtoLearnerModel_ShouldMapLearnerDTOtoLearnerModel()
        {
            //Arrange
            LearnerDTO dto = new LearnerDTO {
                LearnerId = 123, LearnerCode = "TestCode", Forename = "Jon", Surname = "Armstrong"
            };
            LearnerModel model = new LearnerModel();

            var services = new ServiceCollection();

            services.AddAutoMapper(typeof(AutoMapping));
            services.AddTransient <IMappers, Mappers>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IMappers         mappers         = serviceProvider.GetRequiredService <IMappers>();

            //Act
            model = mappers.LearnerDTOtoLearnerModel(dto);

            //Assert
            Assert.NotNull(model);
            Assert.Equal(dto.LearnerId, model.LearnerId);
            Assert.Equal(dto.LearnerCode, model.LearnerCode);
            Assert.Equal(dto.Forename, model.Forename);
            Assert.Equal(dto.Surname, model.Surname);
        }
        public LearnerModel UpdateLearner(Guid id, LearnerModel model)
        {
            try
            {
                var learnerModel = GetById(id);
                if (learnerModel != null)
                {
                    // TODO: refactor this in extensions

                    learnerModel.FirstName    = model.FirstName;
                    learnerModel.LastName     = model.LastName;
                    learnerModel.IDNumber     = model.IDNumber;
                    learnerModel.Gender       = model.Gender;
                    learnerModel.Race         = model.Race;
                    learnerModel.SchoolName   = model.SchoolName;
                    learnerModel.Grade        = model.Grade;
                    learnerModel.Section      = model.Section;
                    learnerModel.ModifyUserId = model.ModifyUserId;
                    learnerModel.ModifyDate   = model.ModifyDate;
                    learnerModel.StatusId     = model.StatusId;
                    _repo.Learner.Update(learnerModel.ToEntity());
                    _repo.Save();
                    return(learnerModel);
                }

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        internal static Learner Map(this LearnerModel model)
        {
            var learner = new Learner
            {
                Id = model.Id,
                ApprenticeshipIncentiveId = model.ApprenticeshipIncentiveId,
                ApprenticeshipId          = model.ApprenticeshipId,
                Ukprn           = model.Ukprn,
                ULN             = model.UniqueLearnerNumber,
                LearningPeriods = model.LearningPeriods.Map(model.Id),
                DaysInLearnings = model.DaysInLearnings.Map(model.Id)
            };

            learner.SubmissionFound        = model.SubmissionData.SubmissionFound;
            learner.LearningFound          = model.SubmissionData.LearningData.LearningFound;
            learner.SubmissionDate         = model.SubmissionData.SubmissionDate;
            learner.StartDate              = model.SubmissionData.LearningData.StartDate;
            learner.HasDataLock            = model.SubmissionData.LearningData.HasDataLock;
            learner.InLearning             = model.SubmissionData.LearningData.IsInlearning;
            learner.RawJSON                = model.SubmissionData.RawJson;
            learner.LearningStoppedDate    = model.SubmissionData.LearningData?.StoppedStatus?.DateStopped;
            learner.LearningResumedDate    = model.SubmissionData.LearningData?.StoppedStatus?.DateResumed;
            learner.SuccessfulLearnerMatch = model.SuccessfulLearnerMatch;
            return(learner);
        }
        internal static LearnerModel Map(this Learner model)
        {
            var learner = new LearnerModel
            {
                Id = model.Id,
                ApprenticeshipIncentiveId = model.ApprenticeshipIncentiveId,
                ApprenticeshipId          = model.ApprenticeshipId,
                Ukprn = model.Ukprn,
                UniqueLearnerNumber = model.ULN,
                CreatedDate         = model.CreatedDate,
                LearningPeriods     = model.LearningPeriods.Map(),
                DaysInLearnings     = model.DaysInLearnings.Map(),
                SubmissionData      = new Domain.ApprenticeshipIncentives.ValueTypes.SubmissionData()
            };

            learner.SubmissionData.SetSubmissionDate(model.SubmissionDate);
            if (learner.SubmissionData.SubmissionFound)
            {
                learner.SubmissionData.SetLearningData(
                    new Domain.ApprenticeshipIncentives.ValueTypes.LearningData(model.LearningFound.Value));
                learner.SubmissionData.LearningData.SetStartDate(model.StartDate);

                if (model.HasDataLock.HasValue)
                {
                    learner.SubmissionData.LearningData.SetHasDataLock(model.HasDataLock.Value);
                }

                learner.SubmissionData.LearningData.SetIsInLearning(model.InLearning);

                learner.SubmissionData.SetRawJson(model.RawJSON);
            }

            return(learner);
        }
        public async Task Add(LearnerModel learnerModel)
        {
            var learner = learnerModel.Map();

            learner.CreatedDate = DateTime.Now;
            learner.LearningPeriods.ToList().ForEach(l => l.CreatedDate = learner.CreatedDate);
            learner.DaysInLearnings.ToList().ForEach(l => l.CreatedDate = learner.CreatedDate);
            await _dbContext.AddAsync(learner);
        }
示例#7
0
        /// <summary>
        /// Gets Json from Resources and Transforms it into the Output format
        /// </summary>
        /// <returns>string</returns>
        public string GetLearner()
        {
            LearnerDTO   learnerDTO   = JsonFactory.LoadJson();
            LearnerModel learnerModel = mappers.LearnerDTOtoLearnerModel(learnerDTO);
            OutputModel  outputModel  = mappers.LearnerModeltoOutputModel(learnerModel);
            OutputDTO    outputDTO    = mappers.OutputModeltoOutputDTO(outputModel);

            return(JsonFactory.JsonSerialize(outputDTO));
        }
        public async Task Update(LearnerModel learnerModel)
        {
            var updatedLearner = learnerModel.Map();

            var existingLearner = await _dbContext.Learners.FirstOrDefaultAsync(x => x.Id == updatedLearner.Id);

            if (existingLearner != null)
            {
                UpdateLearner(updatedLearner, existingLearner);
            }
        }
示例#9
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .Create();

            _sutModel.LearningPeriods = new List <LearningPeriod>();

            _sut = Sut(_sutModel);
        }
        public LearnerModel CreateLearner(LearnerModel model)
        {
            try
            {
                model.LearnerId = Guid.NewGuid();

                model.StatusId = 1;
                _repo.Learner.Create(model.ToEntity());
                _repo.Save();
                return(model);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        internal static LearnerModel Map(this Learner model)
        {
            var learner = new LearnerModel
            {
                Id = model.Id,
                ApprenticeshipIncentiveId = model.ApprenticeshipIncentiveId,
                ApprenticeshipId          = model.ApprenticeshipId,
                Ukprn = model.Ukprn,
                UniqueLearnerNumber    = model.ULN,
                CreatedDate            = model.CreatedDate,
                SuccessfulLearnerMatch = model.SuccessfulLearnerMatch,
                LearningPeriods        = model.LearningPeriods.Map(),
                DaysInLearnings        = model.DaysInLearnings.Map(),
                SubmissionData         = new SubmissionData()
            };

            learner.SubmissionData.SetSubmissionDate(model.SubmissionDate);
            if (learner.SubmissionData.SubmissionFound)
            {
                learner.SubmissionData.SetLearningData(
                    new LearningData(model.LearningFound.Value));
                learner.SubmissionData.LearningData.SetStartDate(model.StartDate);

                if (model.HasDataLock.HasValue)
                {
                    learner.SubmissionData.LearningData.SetHasDataLock(model.HasDataLock.Value);
                }

                learner.SubmissionData.LearningData.SetIsInLearning(model.InLearning);

                if (model.LearningStoppedDate.HasValue)
                {
                    learner.SubmissionData.LearningData.SetIsStopped(new LearningStoppedStatus(true, model.LearningStoppedDate.Value));
                }

                if (model.LearningResumedDate.HasValue)
                {
                    learner.SubmissionData.LearningData.SetIsStopped(new LearningStoppedStatus(false, model.LearningResumedDate.Value));
                }

                learner.SubmissionData.SetRawJson(model.RawJSON);
            }

            return(learner);
        }
示例#12
0
 public async Task <IActionResult> Post([FromBody] LearnerModel model)
 {
     try
     {
         var userId = User.Identity.Name;
         if (userId != null)
         {
             model.CreateUserId = Guid.Parse(userId);
             model.CreateDate   = DateTime.Now;
             model.ModifyUserId = Guid.Parse(userId);
             model.ModifyDate   = DateTime.Now;
             return(Ok(_learnerService.CreateLearner(model)));
         }
         return(BadRequest("An error has occurred, please contact system administrator!"));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
示例#13
0
        public void LearnerModeltoOutputModel_ShouldMapLearnerModeltoOutputModel()
        {
            //Arrange
            LearnerModel learner = new LearnerModel
            {
                LearnerId      = 456,
                Forename       = "Rosie",
                Surname        = "Toll",
                DateOfEntry    = "01/01/2021",
                AddressDetails = new List <AddressDetailModel>()
                {
                    new AddressDetailModel
                    {
                        Number = "456", Street = "Test Street", PostCode = "LL34 6NG"
                    }
                },
                Year = "9"
            };
            OutputModel output = new OutputModel();

            var services = new ServiceCollection();

            services.AddAutoMapper(typeof(AutoMapping));
            services.AddTransient <IMappers, Mappers>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IMappers         mappers         = serviceProvider.GetRequiredService <IMappers>();

            //Act
            output = mappers.LearnerModeltoOutputModel(learner);

            //Assert
            Assert.NotNull(output);
            Assert.Equal(learner.LearnerId.ToString(), output.source_id);
            Assert.Equal(learner.Forename, output.first_name);
            Assert.Equal(learner.Surname, output.last_name);
            Assert.Equal(learner.DateOfEntry, output.start_date);
            Assert.Equal(learner.AddressDetails[0].Number + " " + learner.AddressDetails[0].Street, output.address_line_1);
            Assert.Equal(learner.AddressDetails[0].PostCode, output.postcode);
            Assert.Equal(learner.Year, output.year_code);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .Create();

            _collectionPeriod = _fixture.Create <CollectionPeriod>();

            _daysInLearning = new DaysInLearning(_collectionPeriod.PeriodNumber, _collectionPeriod.AcademicYear, _fixture.Create <int>());

            _sutModel.DaysInLearnings = new List <DaysInLearning>()
            {
                new DaysInLearning((byte)(_collectionPeriod.PeriodNumber - 1), (short)(_collectionPeriod.AcademicYear - 1), _fixture.Create <int>()),
                _daysInLearning,
                new DaysInLearning((byte)(_collectionPeriod.PeriodNumber + 1), (short)(_collectionPeriod.AcademicYear + 1), _fixture.Create <int>()),
            };

            _sut = Sut(_sutModel);
        }
示例#15
0
 public async Task <IActionResult> Put(Guid id, [FromBody] LearnerModel model)
 {
     try
     {
         var userId = User.Identity.Name;
         if (userId != null)
         {
             model.ModifyUserId = Guid.Parse(userId);
             var result = _learnerService.UpdateLearner(id, model);
             if (result != null)
             {
                 return(Ok(result));
             }
         }
         return(BadRequest("An error has occurred, please contact system administrator!"));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
 public static Learner ToEntity(this LearnerModel model)
 {
     return(new Learner
     {
         LearnerId = model.LearnerId,
         FirstName = model.FirstName,
         LastName = model.LastName,
         DateOfBirth = model.DateOfBirth,
         Gender = model.Gender,
         IDNumber = model.IDNumber,
         Grade = model.Grade,
         Race = model.Race,
         SchoolName = model.SchoolName,
         Section = model.Section,
         CreateUserId = model.CreateUserId,
         CreateDate = model.CreateDate,
         ModifyUserId = model.ModifyUserId,
         ModifyDate = model.ModifyDate,
         StatusId = model.StatusId
     });
 }
示例#17
0
        public void Then_days_in_learning_is_zero_if_there_are_no_LearningPeriods()
        {
            // arrange
            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .With(l => l.LearningPeriods, new List <LearningPeriod>())
                        .With(l => l.DaysInLearnings, new List <DaysInLearning>())
                        .Create();

            int expectedDays = 0;

            _sut = Sut(_sutModel);

            // act
            _sut.SetDaysInLearning(_collectionCalendarPeriod);

            // assert
            var daysInLearning = _sut.GetModel().DaysInLearnings.Single();

            daysInLearning.CollectionPeriod.Should().Be(_collectionCalendarPeriod.CollectionPeriod);
            daysInLearning.NumberOfDays.Should().Be(expectedDays);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _collectionYear  = _fixture.Create <short>();
            _collectionMonth = _fixture.Create <byte>();

            _collectionPeriod = new CollectionPeriod(1, _collectionMonth, _collectionYear, DateTime.Now, DateTime.Now, _collectionYear, true);

            var startDate = DateTime.Now.Date;
            var dueDate   = startDate.AddDays(90).Date;

            _sutModel = _fixture
                        .Build <ApprenticeshipIncentiveModel>()
                        .With(a => a.StartDate, startDate)
                        .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>()
                .With(p => p.DueDate, dueDate)
                .With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create()
            })
                        .Create();

            _sutModel.Apprenticeship.SetProvider(_fixture.Create <Provider>());

            _learnerModel = _fixture
                            .Build <LearnerModel>()
                            .With(l => l.DaysInLearnings, new List <DaysInLearning>()
            {
                new DaysInLearning(_collectionPeriod.PeriodNumber, _collectionPeriod.AcademicYear, 90)
            })
                            .Create();

            _learner = Learner.Get(_learnerModel);

            _sut = Sut(_sutModel);
        }
        public void Arrange()
        {
            _fixture    = new Fixture();
            _startDate  = DateTime.Now.Date;
            _censusDate = _startDate.AddDays(17);

            _collectionPeriod = new CollectionPeriod(1, (byte)DateTime.Now.Month, (short)DateTime.Now.Year, DateTime.Now.AddMonths(-2), _censusDate, (short)DateTime.Now.Year, true);

            _learningPeriod3 = new LearningPeriod(_startDate, null);
            _learningPeriods = new List <LearningPeriod>()
            {
                new LearningPeriod(_startDate.AddDays(-60), _startDate.AddDays(-60 + 15)),
                new LearningPeriod(_startDate.AddDays(-30), _startDate.AddDays(-30 + 12)),
                _learningPeriod3
            };

            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .With(l => l.LearningPeriods, _learningPeriods)
                        .With(l => l.DaysInLearnings, new List <DaysInLearning>())
                        .Create();

            _sut = Sut(_sutModel);
        }
示例#20
0
        /// <summary>
        /// Takes a LearnerDTO object and maps the data to a LearnerModel object
        /// </summary>
        /// <param name="learnerDto"></param>
        /// <returns>LearnerModel</returns>
        public LearnerModel LearnerDTOtoLearnerModel(LearnerDTO learnerDto)
        {
            LearnerModel model = _mapper.Map <LearnerModel>(learnerDto);

            return(model);
        }
 public Learner GetExisting(LearnerModel model)
 {
     return(Learner.Get(model));
 }
示例#22
0
        /// <summary>
        /// Takes a LearnerModel object and maps the data to a OutputModel object
        /// </summary>
        /// <param name="learnerModel"></param>
        /// <returns>OutputModel</returns>
        public OutputModel LearnerModeltoOutputModel(LearnerModel learnerModel)
        {
            OutputModel model = _mapper.Map <OutputModel>(learnerModel);

            return(model);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _mockIncentiveDomainRespository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockCollectionCalendarService  = new Mock <ICollectionCalendarService>();
            _mockAccountDomainRepository    = new Mock <IAccountDomainRepository>();
            _mockLearnerDomainRepository    = new Mock <ILearnerDomainRepository>();

            _startDate       = DateTime.Today;
            _payment1DueDate = _startDate.AddDays(10);

            _collectionCalendarPeriods = new List <Domain.ValueObjects.CollectionCalendarPeriod>()
            {
                new Domain.ValueObjects.CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year),
                    (byte)DateTime.Now.Month,
                    (short)DateTime.Now.Year,
                    DateTime.Now.AddDays(-1),
                    DateTime.Now,
                    true,
                    false)
            };

            _mockCollectionCalendarService
            .Setup(m => m.Get())
            .ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(_collectionCalendarPeriods));

            _vrfVendorId = Guid.NewGuid().ToString();
            var legalEntity = _fixture.Build <LegalEntityModel>()
                              .With(l => l.VrfVendorId, _vrfVendorId)
                              .With(l => l.SignedAgreementVersion, 5)
                              .Create();

            var accountModel = _fixture.Build <AccountModel>()
                               .With(a => a.LegalEntityModels, new List <LegalEntityModel>()
            {
                legalEntity
            })
                               .Create();

            var domainAccount = Domain.Accounts.Account.Create(accountModel);

            _account = new Account(accountModel.Id, legalEntity.AccountLegalEntityId);

            var pendingPayment1 = _fixture.Build <PendingPaymentModel>()
                                  .With(m => m.Account, _account)
                                  .With(m => m.DueDate, _payment1DueDate)
                                  .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            var pendingPayment2 = _fixture.Build <PendingPaymentModel>()
                                  .With(m => m.Account, _account)
                                  .With(m => m.DueDate, _payment1DueDate.AddDays(2))
                                  .With(m => m.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            var pendingPayments = new List <PendingPaymentModel>()
            {
                pendingPayment1, pendingPayment2
            };

            var model = _fixture.Build <ApprenticeshipIncentiveModel>()
                        .With(m => m.Account, _account)
                        .With(m => m.StartDate, _startDate)
                        .With(m => m.PendingPaymentModels, pendingPayments)
                        .With(m => m.PausePayments, false)
                        .With(m => m.MinimumAgreementVersion, new AgreementVersion(4))
                        .Create();

            var incentive = new ApprenticeshipIncentiveFactory().GetExisting(model.Id, model);

            _fixture.Register(() => incentive);

            _mockIncentiveDomainRespository
            .Setup(m => m.Find(incentive.Id))
            .ReturnsAsync(incentive);

            _mockAccountDomainRepository
            .Setup(m => m.Find(incentive.Account.Id))
            .ReturnsAsync(domainAccount);

            var submissionData = new SubmissionData();

            submissionData.SetSubmissionDate(DateTime.UtcNow);
            submissionData.SetLearningData(new LearningData(true));
            submissionData.LearningData.SetIsInLearning(true);

            _daysInLearning = new DaysInLearning(new Domain.ValueObjects.CollectionPeriod(1, (short)DateTime.Now.Year), 90);

            _learnerModel = _fixture.Build <LearnerModel>()
                            .With(m => m.ApprenticeshipId, incentive.Apprenticeship.Id)
                            .With(m => m.ApprenticeshipIncentiveId, incentive.Id)
                            .With(m => m.UniqueLearnerNumber, incentive.Apprenticeship.UniqueLearnerNumber)
                            .With(m => m.SubmissionData, submissionData)
                            .With(m => m.DaysInLearnings, new List <DaysInLearning>()
            {
                _daysInLearning
            })
                            .Create();

            _learner = new LearnerFactory().GetExisting(_learnerModel);

            _mockLearnerDomainRepository
            .Setup(m => m.GetOrCreate(incentive))
            .ReturnsAsync(_learner);

            _sut = new ValidatePendingPaymentCommandHandler(
                _mockIncentiveDomainRespository.Object,
                _mockAccountDomainRepository.Object,
                _mockCollectionCalendarService.Object,
                _mockLearnerDomainRepository.Object);
        }
 private Learner Sut(LearnerModel model)
 {
     return(Learner.Get(model));
 }