public async Task ThenAppropriateCommandIsSentToMediator(ApprenticeshipUpdateStatus updateStatus, Type expectedCommand) { //Arrange var submission = new ApprenticeshipUpdateSubmission { UpdateStatus = updateStatus, LastUpdatedByInfo = new LastUpdateInfo(), UserId = "TEST" }; //Act await Orchestrator.PatchApprenticeshipUpdate(1, 1, submission); //Assert MockMediator.Verify(x => x.SendAsync(It.Is <IAsyncRequest>(o => o.GetType() == expectedCommand)), Times.Once); }
protected override Task Handle(UndoApprenticeshipUpdateCommand command, CancellationToken cancellationToken) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var submission = new ApprenticeshipUpdateSubmission { UpdateStatus = ApprenticeshipUpdateStatus.Deleted, UserId = command.UserId, LastUpdatedByInfo = new LastUpdateInfo { EmailAddress = command.UserEmailAddress, Name = command.UserDisplayName } }; return(_commitmentsApi.PatchApprenticeshipUpdate(command.ProviderId, command.ApprenticeshipId, submission)); }
protected override async Task HandleCore(UndoApprenticeshipUpdateCommand command) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid()) { throw new ValidationException(validationResult.ValidationDictionary.FirstOrDefault().Value); } var submission = new ApprenticeshipUpdateSubmission { UpdateStatus = ApprenticeshipUpdateStatus.Deleted, UserId = command.UserId, LastUpdatedByInfo = new LastUpdateInfo { EmailAddress = command.UserEmailAddress, Name = command.UserDisplayName } }; await _commitmentsApi.PatchApprenticeshipUpdate(command.AccountId, command.ApprenticeshipId, submission); }
public async Task <IHttpActionResult> PatchApprenticeshipUpdate(long accountId, long apprenticeshipId, [FromBody] ApprenticeshipUpdateSubmission apprenticeshipSubmission) { await _employerOrchestrator.PatchApprenticeshipUpdate(accountId, apprenticeshipId, apprenticeshipSubmission); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task PatchApprenticeshipUpdate(long employerAccountId, long apprenticeshipId, ApprenticeshipUpdateSubmission submission) { var url = $"{_configuration.BaseUrl}api/employer/{employerAccountId}/apprenticeships/{apprenticeshipId}/update"; await _commitmentHelper.PatchApprenticeshipUpdate(url, submission); }
public async Task PatchApprenticeshipUpdate(string url, ApprenticeshipUpdateSubmission submission) { var data = JsonConvert.SerializeObject(submission); await PatchAsync(url, data); }
public async Task PatchApprenticeshipUpdate(long providerId, long apprenticeshipId, ApprenticeshipUpdateSubmission submission) { _logger.Trace($"Patching update for apprenticeship {apprenticeshipId} for provider {providerId} with status {submission.UpdateStatus}", providerId: providerId, apprenticeshipId: apprenticeshipId); switch (submission.UpdateStatus) { case Types.Apprenticeship.Types.ApprenticeshipUpdateStatus.Approved: await _mediator.SendAsync(new AcceptApprenticeshipChangeCommand { ApprenticeshipId = apprenticeshipId, Caller = new Caller(providerId, CallerType.Provider), UserId = submission.UserId, UserName = submission.LastUpdatedByInfo?.Name }); break; case Types.Apprenticeship.Types.ApprenticeshipUpdateStatus.Rejected: await _mediator.SendAsync(new RejectApprenticeshipChangeCommand { ApprenticeshipId = apprenticeshipId, Caller = new Caller(providerId, CallerType.Provider), UserId = submission.UserId, UserName = submission.LastUpdatedByInfo?.Name }); break; case Types.Apprenticeship.Types.ApprenticeshipUpdateStatus.Deleted: await _mediator.SendAsync(new UndoApprenticeshipChangeCommand { ApprenticeshipId = apprenticeshipId, Caller = new Caller(providerId, CallerType.Provider), UserId = submission.UserId, UserName = submission.LastUpdatedByInfo?.Name }); break; default: throw new InvalidOperationException($"Invalid update status {submission.UpdateStatus}"); } _logger.Info($"Patched update for apprenticeship {apprenticeshipId} for provider {providerId} with status {submission.UpdateStatus}", providerId, apprenticeshipId: apprenticeshipId); }