private static bool EventMatchesCommand(ApprenticeshipEvent e, CreateApprenticeshipEventCommand command) { return(e.EmployerAccountId == command.EmployerAccountId && e.Event == command.Event && e.ProviderId == command.ProviderId && e.AgreementStatus == command.AgreementStatus && e.ApprenticeshipId == command.ApprenticeshipId && e.LearnerId == command.LearnerId && e.PaymentOrder == command.PaymentOrder && e.PaymentStatus == command.PaymentStatus && e.PausedOnDate == command.PausedOnDate && e.StoppedOnDate == command.StoppedOnDate && e.TrainingEndDate == command.TrainingEndDate && e.TrainingId == command.TrainingId && e.TrainingStartDate == command.TrainingStartDate && e.TrainingTotalCost == command.TrainingTotalCost && e.TrainingType == command.TrainingType && e.LegalEntityId == command.LegalEntityId && e.LegalEntityName == command.LegalEntityName && e.LegalEntityOrganisationType == command.LegalEntityOrganisationType && e.AccountLegalEntityPublicHashedId == command.AccountLegalEntityPublicHashedId && e.DateOfBirth == command.DateOfBirth && e.PriceHistory.Count() == command.PriceHistory.Count() && e.TransferSenderId == command.TransferSenderId && e.TransferSenderName == command.TransferSenderName && e.TransferApprovalStatus == command.TransferApprovalStatus && e.TransferApprovalActionedOn == command.TransferApprovalActionedOn); }
private bool DomainEventMatchesApiEvent(Domain.Entities.ApprenticeshipEvent domainEvent, ApprenticeshipEvent apiEvent) { return(domainEvent.ProviderId == apiEvent.ProviderId && domainEvent.AgreementStatus.ToString() == apiEvent.AgreementStatus.ToString() && domainEvent.ApprenticeshipId == apiEvent.ApprenticeshipId && domainEvent.EmployerAccountId == apiEvent.EmployerAccountId && domainEvent.Event == apiEvent.Event && domainEvent.LearnerId == apiEvent.LearnerId && domainEvent.PaymentOrder == apiEvent.PaymentOrder && domainEvent.PaymentStatus.ToString() == apiEvent.PaymentStatus.ToString() && domainEvent.PausedOnDate == apiEvent.PausedOnDate && domainEvent.StoppedOnDate == apiEvent.StoppedOnDate && domainEvent.TrainingEndDate == apiEvent.TrainingEndDate && domainEvent.TrainingId == apiEvent.TrainingId && domainEvent.TrainingStartDate == apiEvent.TrainingStartDate && domainEvent.TrainingTotalCost == apiEvent.TrainingTotalCost && domainEvent.TrainingType.ToString() == apiEvent.TrainingType.ToString() && domainEvent.LegalEntityId == apiEvent.LegalEntityId && domainEvent.LegalEntityName == apiEvent.LegalEntityName && domainEvent.LegalEntityOrganisationType == apiEvent.LegalEntityOrganisationType && domainEvent.DateOfBirth == apiEvent.DateOfBirth && domainEvent.TransferSenderId == apiEvent.TransferSenderId && domainEvent.TransferSenderName == apiEvent.TransferSenderName && domainEvent.TransferApprovalStatus.ToString() == apiEvent.TransferApprovalStatus.ToString() && domainEvent.TransferApprovalActionedOn == apiEvent.TransferApprovalActionedOn && DomainPriceHistoryMatchesApiPriceHistory(domainEvent.PriceHistory, apiEvent.PriceHistory?.ToList())); }
private static Domain.Entities.ApprenticeshipEvent MapFrom(ApprenticeshipEvent a) { return(new Domain.Entities.ApprenticeshipEvent { AgreementStatus = (Domain.Entities.AgreementStatus)a.AgreementStatus, ApprenticeshipId = a.ApprenticeshipId, EmployerAccountId = a.EmployerAccountId, Event = a.Event, LearnerId = a.LearnerId, PaymentOrder = a.PaymentOrder, PaymentStatus = (Domain.Entities.PaymentStatus)a.PaymentStatus, PausedOnDate = a.PausedOnDate, StoppedOnDate = a.StoppedOnDate, ProviderId = a.ProviderId, TrainingStartDate = a.TrainingStartDate, TrainingEndDate = a.TrainingEndDate, TrainingId = a.TrainingId, TrainingType = (Domain.Entities.TrainingTypes)a.TrainingType, TrainingTotalCost = a.TrainingTotalCost, LegalEntityId = a.LegalEntityId, LegalEntityName = a.LegalEntityName, LegalEntityOrganisationType = a.LegalEntityOrganisationType, AccountLegalEntityPublicHashedId = a.AccountLegalEntityPublicHashedId, EffectiveFrom = a.EffectiveFrom, EffectiveTo = a.EffectiveTo, DateOfBirth = a.DateOfBirth, PriceHistory = a.PriceHistory?.Select(ToDomainModel).ToList() ?? new List <Domain.Entities.PriceHistory>(), TransferSenderId = a.TransferSenderId, TransferSenderName = a.TransferSenderName ?? string.Empty, TransferApprovalStatus = (Domain.Entities.TransferApprovalStatus?)a.TransferApprovalStatus, TransferApprovalActionedOn = a.TransferApprovalActionedOn }); }
public async Task <IHttpActionResult> Post(ApprenticeshipEvent request) { await _orchestrator.CreateEvent(request); // 201 for list of all events return(CreatedAtRoute("GetAllEvents", new {}, default(ApprenticeshipEvent))); }
private bool CommandMatchesRequest(CreateApprenticeshipEventCommand command, ApprenticeshipEvent request) { return(command.ProviderId == request.ProviderId && command.AgreementStatus.ToString() == request.AgreementStatus.ToString() && command.ApprenticeshipId == request.ApprenticeshipId && command.EmployerAccountId == request.EmployerAccountId && command.Event == request.Event && command.LearnerId == request.LearnerId && command.PaymentOrder == request.PaymentOrder && command.PaymentStatus.ToString() == request.PaymentStatus.ToString() && command.PausedOnDate == request.PausedOnDate && command.StoppedOnDate == request.StoppedOnDate && command.TrainingEndDate == request.TrainingEndDate && command.TrainingId == request.TrainingId && command.TrainingStartDate == request.TrainingStartDate && command.TrainingTotalCost == request.TrainingTotalCost && command.TrainingType.ToString() == request.TrainingType.ToString() && command.LegalEntityId == request.LegalEntityId && command.LegalEntityName == request.LegalEntityName && command.LegalEntityOrganisationType == request.LegalEntityOrganisationType && command.AccountLegalEntityPublicHashedId == request.AccountLegalEntityPublicHashedId && command.DateOfBirth == request.DateOfBirth && command.TransferSenderId == request.TransferSenderId && command.TransferSenderName == request.TransferSenderName && command.TransferApprovalStatus.ToString() == request.TransferApprovalStatus.ToString() && command.TransferApprovalActionedOn == request.TransferApprovalActionedOn); }
public void Arrange() { _validator = new BulkUploadCreateApprentieshipEventsCommandValidator(); _apprenticeshipEvent = new ApprenticeshipEvent(); _command = new BulkUploadCreateApprenticeshipEventsCommand { ApprenticeshipEvents = new List <ApprenticeshipEvent>() }; _command.ApprenticeshipEvents.Add(_apprenticeshipEvent); }
protected override async Task HandleCore(CreateApprenticeshipEventCommand command) { _logger.Info($"Received message {command.Event}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event); var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } try { var newApprenticeshipEvent = new ApprenticeshipEvent { Event = command.Event, CreatedOn = DateTime.UtcNow, ApprenticeshipId = command.ApprenticeshipId, PaymentStatus = command.PaymentStatus, PausedOnDate = command.PausedOnDate, StoppedOnDate = command.StoppedOnDate, AgreementStatus = command.AgreementStatus, ProviderId = command.ProviderId, LearnerId = command.LearnerId, EmployerAccountId = command.EmployerAccountId, TrainingType = command.TrainingType, TrainingId = command.TrainingId, TrainingStartDate = command.TrainingStartDate, TrainingEndDate = command.TrainingEndDate, TrainingTotalCost = command.TrainingTotalCost, PaymentOrder = command.PaymentOrder, LegalEntityId = command.LegalEntityId, LegalEntityOrganisationType = command.LegalEntityOrganisationType, AccountLegalEntityPublicHashedId = command.AccountLegalEntityPublicHashedId, LegalEntityName = command.LegalEntityName, EffectiveFrom = command.EffectiveFrom, EffectiveTo = command.EffectiveTo, DateOfBirth = command.DateOfBirth, PriceHistory = command.PriceHistory, TransferSenderId = command.TransferSenderId, TransferSenderName = command.TransferSenderName, TransferApprovalStatus = command.TransferApprovalStatus, TransferApprovalActionedOn = command.TransferApprovalActionedOn }; await _apprenticeshipEventRepository.Create(newApprenticeshipEvent); _logger.Info($"Finished processing message {command.Event}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event); } catch (Exception ex) { _logger.Error(ex, $"Error processing message {command.Event} - {ex.Message}", accountId: command.EmployerAccountId, providerId: command.ProviderId, @event: command.Event); throw; } }
public async Task CreateApprenticeshipEvent() { var input = new ApprenticeshipEvent(); var employerRequest = new TestRequest(new Uri(ExpectedApiBaseUrl + $"api/events/apprenticeships"), JsonConvert.SerializeObject(input)); _fakeHandler.AddFakeResponse(employerRequest, new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(string.Empty) }); await _sut.CreateApprenticeshipEvent(input); Assert.Pass(); }
public void AndAnExceptionOccursThenTheErrorIsLogged() { var request = new ApprenticeshipEvent { PriceHistory = new List <PriceHistory>() }; var exception = new Exception("Exception"); Mediator.Setup(m => m.SendAsync(It.IsAny <CreateApprenticeshipEventCommand>())).ThrowsAsync(exception); Assert.ThrowsAsync <Exception>(() => Orchestrator.CreateEvent(request)); EventsLogger.Verify(x => x.Error(exception, exception.Message, null, null, null)); }
public void AndValidationFailsThenTheFailureIsLogged() { var request = new ApprenticeshipEvent { PriceHistory = new List <PriceHistory>() }; var validationException = new ValidationException("Exception"); Mediator.Setup(m => m.SendAsync(It.IsAny <CreateApprenticeshipEventCommand>())).ThrowsAsync(validationException); Assert.ThrowsAsync <ValidationException>(() => Orchestrator.CreateEvent(request)); EventsLogger.Verify(x => x.Warn(validationException, "Invalid request", request.EmployerAccountId, request.ProviderId, request.Event)); }
public async Task CreateEvent(ApprenticeshipEvent request) { try { _logger.Info($"Creating Apprenticeship Event ({request.Event}) for Employer: {request.EmployerAccountId}, Provider: {request.ProviderId}", @event: request.Event, accountId: request.EmployerAccountId, providerId: request.ProviderId); await _mediator.SendAsync(new CreateApprenticeshipEventCommand { Event = request.Event, ApprenticeshipId = request.ApprenticeshipId, PaymentStatus = (Domain.Entities.PaymentStatus)request.PaymentStatus, PausedOnDate = request.PausedOnDate, StoppedOnDate = request.StoppedOnDate, AgreementStatus = (Domain.Entities.AgreementStatus)request.AgreementStatus, ProviderId = request.ProviderId, LearnerId = request.LearnerId, EmployerAccountId = request.EmployerAccountId, TrainingType = (Domain.Entities.TrainingTypes)request.TrainingType, TrainingId = request.TrainingId, TrainingStartDate = request.TrainingStartDate, TrainingEndDate = request.TrainingEndDate, TrainingTotalCost = request.TrainingTotalCost, PaymentOrder = request.PaymentOrder, LegalEntityId = request.LegalEntityId, LegalEntityName = request.LegalEntityName, LegalEntityOrganisationType = request.LegalEntityOrganisationType, AccountLegalEntityPublicHashedId = request.AccountLegalEntityPublicHashedId, EffectiveFrom = request.EffectiveFrom, EffectiveTo = request.EffectiveTo, DateOfBirth = request.DateOfBirth, PriceHistory = request.PriceHistory?.Select(ToDomainModel).ToList() ?? new List <Domain.Entities.PriceHistory>(), TransferSenderId = request.TransferSenderId, TransferSenderName = request.TransferSenderName ?? string.Empty, TransferApprovalStatus = (Domain.Entities.TransferApprovalStatus?)request.TransferApprovalStatus, TransferApprovalActionedOn = request.TransferApprovalActionedOn }); } catch (ValidationException ex) { _logger.Warn(ex, "Invalid request", accountId: request.EmployerAccountId, providerId: request.ProviderId, @event: request.Event); throw; } catch (Exception ex) { _logger.Error(ex, ex.Message); throw; } }
private bool EventMatchesParameters(ApprenticeshipEvent apprenticeshipEvent, string @event, DateTime?effectiveFrom) { return(EventMatchesParameters(apprenticeshipEvent, @event, (PaymentStatus)Apprenticeship.PaymentStatus) && apprenticeshipEvent.EffectiveFrom == effectiveFrom); }
private bool EventMatchesParameters(ApprenticeshipEvent apprenticeshipEvent, string @event) { return(EventMatchesParameters(apprenticeshipEvent, @event, PaymentStatus.Deleted)); }
/// <summary> /// Creates a new ApprenticeshipEvent /// </summary> /// <param name="apprenticeshipEvent">ApprenticeshipEvent to create</param> /// <returns></returns> public async Task CreateApprenticeshipEvent(ApprenticeshipEvent apprenticeshipEvent) { var url = $"{_configuration.BaseUrl}api/events/apprenticeships"; await PostEvent(url, apprenticeshipEvent); }
public async Task Create(ApprenticeshipEvent @event) { await BulkUploadApprenticeshipEvents(new List <ApprenticeshipEvent> { @event }); }
private static DataRow AddApprenticeshipEventToTable(DataTable apprenticeshipEventsTable, ApprenticeshipEvent apprenticeshipEvent) { var a = apprenticeshipEvent; return(apprenticeshipEventsTable.Rows.Add(a.Event, a.CreatedOn, a.ApprenticeshipId, a.PaymentOrder, a.PaymentStatus, a.AgreementStatus, a.ProviderId, a.LearnerId, a.EmployerAccountId, a.TrainingType, a.TrainingId, a.TrainingStartDate, a.TrainingEndDate, a.TrainingTotalCost, a.LegalEntityId, a.LegalEntityName, a.LegalEntityOrganisationType, a.EffectiveFrom, a.EffectiveTo, a.DateOfBirth, a.TransferSenderId, a.TransferSenderName, a.TransferApprovalStatus, a.TransferApprovalActionedOn, a.StoppedOnDate, a.PausedOnDate, a.AccountLegalEntityPublicHashedId)); }