public void Arrange()
        {
            _fixture = new Fixture();

            _sut          = _fixture.Create <LearnerSubmissionDto>();
            _startDate    = DateTime.Now.AddMonths(-1);
            _endDate      = DateTime.Today.AddDays(-1);
            _periodNumber = 3;

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .Create();
            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startDate;
            _testPriceEpisodeDto.EndDate   = _endDate;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testPeriodDto.Period           = _periodNumber;
            _testPeriodDto.IsPayable        = true;
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _sut = _fixture.Create <LearnerSubmissionDto>();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .Create();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testTrainingDto.PriceEpisodes.Clear();

            _testPriceEpisode1Dto = _fixture.Create <PriceEpisodeDto>();
            _testPriceEpisode1Dto.Periods.First().ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode1Dto);

            _testPriceEpisode2Dto         = _fixture.Create <PriceEpisodeDto>();
            _testPriceEpisode2Dto.EndDate = null;
            // probbaly not valid data but add multiple apprenticeship periods by price episode just in case
            _testPriceEpisode2Dto.Periods.ToList().ForEach(p => p.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id);
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode2Dto);

            _testTrainingDto.PriceEpisodes.Add(_fixture.Create <PriceEpisodeDto>()); // non matching

            _testPriceEpisode3Dto           = _fixture.Create <PriceEpisodeDto>();   // duplicate
            _testPriceEpisode3Dto.StartDate = _testPriceEpisode1Dto.StartDate;
            _testPriceEpisode3Dto.EndDate   = _testPriceEpisode1Dto.EndDate;
            _testPriceEpisode3Dto.Periods.First().ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testTrainingDto.PriceEpisodes.Add(_testPriceEpisode3Dto);
        }
 public async Task Execute(TrainingDto training)
 {
     await TrainingRepositoryPort.CreateTraining(
         new Training(
             training.name,
             training.description,
             training.datetime,
             training.createdBy)
         );
 }
Beispiel #4
0
 public async Task create_a_training()
 {
     var trainingDto = new TrainingDto {
         createdBy   = "1234",
         datetime    = new DateTime(2020, 1, 1),
         description = "ADescription",
         name        = "AName"
     };
     await CreateTraining.Execute(trainingDto).Received();
 }
Beispiel #5
0
        public async Task <TrainingResponse> Execute(TrainingDto training, int trainingId)
        {
            var trainingUpdated = await TrainingRepositoryPort.UpdateTraining(new Training(training.name, training.description, training.datetime, training.createdBy), trainingId);

            return(new TrainingResponse {
                Id = trainingUpdated.Id,
                Name = trainingUpdated.Name,
                Description = trainingUpdated.Description,
                Date = trainingUpdated.DateTime,
                CreatedBy = trainingUpdated.CreatedBy
            });
        }
Beispiel #6
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _dueDate = DateTime.Now.AddMonths(-1);
            short paymentYear = (short)DateTime.Now.Year;

            _periodNumber = _fixture.Create <byte>();

            _nextPendingPaymentDue = _fixture.Build <PendingPaymentModel>()
                                     .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                                     .With(pp => pp.PaymentYear, paymentYear)
                                     .With(pp => pp.PeriodNumber, _periodNumber)
                                     .With(pp => pp.DueDate, _dueDate)// earliest
                                     .Create();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, _dueDate.AddMonths(1))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, _dueDate.AddMonths(2))
                .With(pp => pp.PaymentYear, (short?)null)
                .Create(),
                _nextPendingPaymentDue
            })
                                            .Create();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);

            _sut       = _fixture.Create <LearnerSubmissionDto>();
            _startTime = _dueDate.AddDays(-10);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startTime;
            _testPriceEpisodeDto.EndDate   = _dueDate.AddDays(10);

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _incentive.Apprenticeship.Id;
            _testPeriodDto.IsPayable        = false;
            _testPeriodDto.Period           = _periodNumber;
        }
Beispiel #7
0
        public int AddTraining(TrainingDto trainingDto)
        {
            Training training = new Training()
            {
                Id        = 0,
                Name      = trainingDto.Name,
                StartDate = trainingDto.StartDate,
                EndDate   = trainingDto.EndDate
            };

            _trainingRepository.Add(training);

            return((int)(trainingDto.EndDate - trainingDto.StartDate).TotalDays);
        }
Beispiel #8
0
        public async Task <ActionResult <Training> > Post(TrainingDto trainingVM)
        {
            if (trainingVM == null)
            {
                return(BadRequest());
            }

            var training = _mapper.Map <Training>(trainingVM);

            _unitOfWork.GetRepository().Add(training);
            _unitOfWork.SaveChanges();

            return(Ok(training));
        }
Beispiel #9
0
        public void TestTrainingDate(int startYear, int startMonth, int StartDay,
                                     int endYear, int endMonth, int endDay, int expected)
        {
            TrainingDto testTraining = new TrainingDto()
            {
                Name      = "Test",
                StartDate = new DateTime(startYear, startMonth, StartDay),
                EndDate   = new DateTime(endYear, endMonth, endDay)
            };
            ITrainingService trainingService = new TrainingService(_moqTrainingRepository.Object);
            int dayInTraining = trainingService.AddTraining(testTraining);

            Assert.Equal(expected, dayInTraining);
        }
Beispiel #10
0
        public List <TrainingDto> GetIndividualTraining(Guid id)
        {
            var list = _clientRepository.GetIndividualTraining(id);
            List <TrainingDto> trainigs = new List <TrainingDto>();

            foreach (var item in list)
            {
                TrainingDto dto = new TrainingDto(item);

                trainigs.Add(dto);
            }

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

            _sut          = _fixture.Create <LearnerSubmissionDto>();
            _startDate    = DateTime.Now;
            _endDate      = _startDate.AddMonths(2);
            _periodNumber = 3;
            var dueDate = _startDate.AddMonths(1);

            var pendingPaymentModel = _fixture
                                      .Build <PendingPaymentModel>()
                                      .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                                      .With(p => p.DueDate, dueDate)
                                      .Create();

            _apprenticeshipIncentiveModel = _fixture.Build <ApprenticeshipIncentiveModel>()
                                            .With(p => p.Apprenticeship, _fixture.Create <Apprenticeship>())
                                            .With(p => p.PendingPaymentModels, new List <PendingPaymentModel> {
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(1))
                .With(pp => pp.CollectionPeriod, (Domain.ValueObjects.CollectionPeriod)null)
                .Create(),
                _fixture.Build <PendingPaymentModel>()
                .With(pp => pp.PaymentMadeDate, (DateTime?)null)
                .With(pp => pp.DueDate, dueDate.AddMonths(2))
                .With(pp => pp.CollectionPeriod, (Domain.ValueObjects.CollectionPeriod)null)
                .Create(),
                pendingPaymentModel
            })
                                            .Create();

            _incentive      = new ApprenticeshipIncentiveFactory().GetExisting(_apprenticeshipIncentiveModel.Id, _apprenticeshipIncentiveModel);
            _pendingPayment = _incentive.PendingPayments.Single(p => p.Id == pendingPaymentModel.Id);

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startDate;
            _testPriceEpisodeDto.EndDate   = _endDate;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _apprenticeshipIncentiveModel.Apprenticeship.Id;
            _testPeriodDto.Period           = _periodNumber;
            _testPeriodDto.IsPayable        = true;
        }
Beispiel #12
0
 public ActionResult <int> Post([FromBody] TrainingDto trainingDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Data Model Error!"));
     }
     try
     {
         int trainingDays = _trainingService.AddTraining(trainingDto);
         return(StatusCode(StatusCodes.Status201Created, trainingDays));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
     }
 }
Beispiel #13
0
        public async Task <ActionResult <Player> > Put(TrainingDto trainingVM)
        {
            if (trainingVM == null)
            {
                return(BadRequest());
            }
            if (_unitOfWork.GetRepository().GetAll().All(x => x.Id != trainingVM.Id))
            {
                return(NotFound());
            }

            var training = _mapper.Map <Training>(trainingVM);

            _unitOfWork.GetRepository().Update(training);
            _unitOfWork.SaveChanges();
            return(Ok(training));
        }
Beispiel #14
0
        public void Arrange()
        {
            _fixture = new Fixture();

            var model = _fixture.Create <ApprenticeshipIncentiveModel>();

            _incentive = new ApprenticeshipIncentiveFactory().GetExisting(model.Id, model);

            _sut       = _fixture.Create <LearnerSubmissionDto>();
            _startTime = DateTime.Now;

            _testTrainingDto           = _sut.Training.First();
            _testTrainingDto.Reference = "ZPROG001";

            _testPriceEpisodeDto           = _testTrainingDto.PriceEpisodes.First();
            _testPriceEpisodeDto.StartDate = _startTime;

            _testPeriodDto = _testPriceEpisodeDto.Periods.First();

            _testPeriodDto.ApprenticeshipId = _incentive.Apprenticeship.Id;
            _testPeriodDto.IsPayable        = true;
        }
Beispiel #15
0
        public async Task <ActionResult> UpdateTraining([FromBody] TrainingDto training, int trainingId)
        {
            var trainingResponse = await TrainingFactory.UpdateTraining().Execute(training, trainingId);

            return(new OkObjectResult(trainingResponse));
        }
Beispiel #16
0
        public async Task <ActionResult> CreateTraining([FromBody] TrainingDto training)
        {
            await TrainingFactory.CreateTraining().Execute(training);

            return(Ok());
        }