public static async Task <ResourceElement> GetReindexJobAsync(this IMediator mediator, string jobId, CancellationToken cancellationToken) { EnsureArg.IsNotNull(mediator, nameof(mediator)); var request = new GetReindexRequest(jobId); GetReindexResponse response = await mediator.Send(request, cancellationToken); return(response.Job.ToParametersResourceElement()); }
public async Task GivenAGetRequest_WhenTooManyRequestsThrown_ThenTooManyRequestsThrown() { var request = new GetReindexRequest("id"); var jobRecord = new ReindexJobRecord("hash", 1, null); var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", CancellationToken.None).Throws(new RequestRateExceededException(TimeSpan.FromMilliseconds(100))); var handler = new GetReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); await Assert.ThrowsAsync <RequestRateExceededException>(() => handler.Handle(request, CancellationToken.None)); }
public async Task GivenAGetRequest_WhenIdNotFound_ThenJobNotFoundExceptionThrown() { var request = new GetReindexRequest("id"); var jobRecord = new ReindexJobRecord("hash", 1, null); var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", Arg.Any <CancellationToken>()).Throws(new JobNotFoundException("not found")); var handler = new GetReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); await Assert.ThrowsAsync <JobNotFoundException>(() => handler.Handle(request, CancellationToken.None)); }
public async Task GivenAGetRequest_WhenGettingAnExistingJob_ThenHttpResponseCodeShouldBeOk() { var request = new GetReindexRequest("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 handler = new GetReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); var result = await handler.Handle(request, CancellationToken.None); Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
public async Task GivenAGetRequest_WhenTooManyRequestsThrown_ThenTooManyRequestsThrown() { var request = new GetReindexRequest("id"); var jobRecord = new ReindexJobRecord(_resourceTypeSearchParameterHashMap, 1); var jobWrapper = new ReindexJobWrapper(jobRecord, WeakETag.FromVersionId("id")); _fhirOperationDataStore.GetReindexJobByIdAsync("id", CancellationToken.None).Throws(new Exception(null, new RequestRateExceededException(TimeSpan.FromMilliseconds(100)))); var handler = new GetReindexRequestHandler(_fhirOperationDataStore, DisabledFhirAuthorizationService.Instance); Exception thrownException = await Assert.ThrowsAsync <Exception>(() => handler.Handle(request, CancellationToken.None)); Assert.IsType <RequestRateExceededException>(thrownException.InnerException); }
public async Task GivenAGetRequest_WhenUserUnauthorized_ThenUnauthorizedFhirExceptionThrown() { var request = new GetReindexRequest("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 GetReindexRequestHandler(_fhirOperationDataStore, authorizationService); await Assert.ThrowsAsync <UnauthorizedFhirActionException>(() => handler.Handle(request, CancellationToken.None)); }