public static async Task <ResourceElement> CancelReindexAsync(this IMediator mediator, string jobId, CancellationToken cancellationToken) { EnsureArg.IsNotNull(mediator, nameof(mediator)); EnsureArg.IsNotNullOrWhiteSpace(jobId, nameof(jobId)); var request = new CancelReindexRequest(jobId); var response = await mediator.Send(request, cancellationToken); return(response.Job.ToParametersResourceElement()); }
public async Task GivenACancelRequest_WhenUserUnauthorized_ThenUnauthorizedFhirExceptionThrown() { var request = new CancelReindexRequest("id"); var jobRecord = new ReindexJobRecord("hash", 1, null); var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", Arg.Any <CancellationToken>()).Returns(jobWrapper); var authorizationService = Substitute.For <IFhirAuthorizationService>(); authorizationService.CheckAccess(DataActions.Reindex).Returns(DataActions.None); var handler = new CancelReindexRequestHandler(_fhirOperationDataStore, authorizationService); await Assert.ThrowsAsync <UnauthorizedFhirActionException>(() => handler.Handle(request, CancellationToken.None)); }
public async Task GivenACancelRequest_WhenJobCompleted_ThenRequestNotValidExceptionThrown() { var request = new CancelReindexRequest("id"); var jobRecord = new ReindexJobRecord("hash", 1, null) { Status = OperationStatus.Completed, }; var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", Arg.Any <CancellationToken>()).Returns(jobWrapper); var handler = new CancelReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); await Assert.ThrowsAsync <RequestNotValidException>(() => handler.Handle(request, CancellationToken.None)); }
public async Task GivenACancelRequest_WhenJobInProgress_ThenJobUpdatedToCanceled() { var request = new CancelReindexRequest("id"); var jobRecord = new ReindexJobRecord("hash", 1, null) { Status = OperationStatus.Running, }; var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", Arg.Any <CancellationToken>()).Returns(jobWrapper); _fhirOperationDataStore.UpdateReindexJobAsync(jobRecord, WeakETag.FromVersionId("id"), Arg.Any <CancellationToken>()).Returns(jobWrapper); var handler = new CancelReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); var result = await handler.Handle(request, CancellationToken.None); Assert.Equal(OperationStatus.Canceled, result.Job.JobRecord.Status); }