public async Task GivenStoredInstancesWhereOneIsMissingFile_WhenRetrieveRequestForSeries_ThenNotFoundIsThrown() { List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Series); // For each instance identifier but the last, set up the fileStore to return a stream containing a file associated with the identifier. versionedInstanceIdentifiers.SkipLast(1).Select(x => _fileStore.GetFileAsync(x, _defaultCancellationToken).Returns( StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(x), frames: 0, disposeStreams: true).Result.Value)); // For the last identifier, set up the fileStore to throw a store exception with the status code 404 (NotFound). _fileStore.GetFileAsync(versionedInstanceIdentifiers.Last(), _defaultCancellationToken).Throws(new InstanceNotFoundException()); await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetSeries() }), _defaultCancellationToken)); }
public async Task GivenARequestWithInvalidInstanceIdentifier_WhenRetrievingInstance_ThenDicomInvalidIdentifierExceptionIsThrown(string sopInstanceUid) { EnsureArg.IsNotNull(sopInstanceUid, nameof(sopInstanceUid)); RetrieveResourceRequest request = new RetrieveResourceRequest(TestUidGenerator.Generate(), TestUidGenerator.Generate(), sopInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance() }); var ex = await Assert.ThrowsAsync <InvalidIdentifierException>(() => _retrieveResourceHandler.Handle(request, CancellationToken.None)); Assert.Equal($"DICOM Identifier 'SopInstanceUid' value '{sopInstanceUid.Trim()}' is invalid. Value length should not exceed the maximum length of 64 characters. Value should contain characters in '0'-'9' and '.'. Each component must start with non-zero number.", ex.Message); }
public async Task GivenNoStoredInstances_WhenRetrieveRequestForSeries_ThenNotFoundIsThrown() { _instanceStore.GetInstanceIdentifiersInSeriesAsync(_studyInstanceUid, _firstSeriesInstanceUid).Returns(new List <VersionedInstanceIdentifier>()); await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetSeries() }), _defaultCancellationToken)); }
public void GivenRetrieveResourcesRequestForStudy_WhenConstructed_ThenStudyResourceTypeIsSet() { var request = new RetrieveResourceRequest(TestUidGenerator.Generate(), new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance(transferSyntax: string.Empty) }); Assert.Equal(ResourceType.Study, request.ResourceType); }
public async Task GivenIncorrectTransferSyntax_WhenRetrievingStudy_ThenDicomBadRequestExceptionIsThrownAsync(string transferSyntax) { var request = new RetrieveResourceRequest(TestUidGenerator.Generate(), new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance(transferSyntax: transferSyntax) }); var ex = await Assert.ThrowsAsync <BadRequestException>(() => _retrieveResourceHandler.Handle(request, CancellationToken.None)); Assert.Equal("The specified Transfer Syntax value is not valid.", ex.Message); }
public async Task GivenStoredInstancesWithFrames_WhenRetrieveRequestForFrames_ThenFramesInInstanceAreRetrievedSuccesfully() { // Add multiple instances to validate that we return the requested instance and ignore the other(s). List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Frames); var framesToRequest = new List <int> { 1, 2 }; // For the first instance identifier, set up the fileStore to return a stream containing a file associated with the identifier. KeyValuePair <DicomFile, Stream> streamAndStoredFile = StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(versionedInstanceIdentifiers.First()), frames: 3).Result; _fileStore.GetFileAsync(versionedInstanceIdentifiers.First(), DefaultCancellationToken).Returns(streamAndStoredFile.Value); // Setup frame handler to return the frames as streams from the file. Stream[] frames = framesToRequest.Select(f => GetFrameFromFile(streamAndStoredFile.Key.Dataset, f)).ToArray(); var retrieveResourceRequest = new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, framesToRequest, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetFrame() }); _dicomFrameHandler.GetFramesResourceAsync(streamAndStoredFile.Value, retrieveResourceRequest.Frames, true, "*").Returns(frames); RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync( retrieveResourceRequest, DefaultCancellationToken); // Validate response status code and ensure response streams has expected frames - it should be equivalent to what the store was set up to return. AssertPixelDataEqual(DicomPixelData.Create(streamAndStoredFile.Key.Dataset).GetFrame(framesToRequest[0]), response.ResponseStreams.ToList()[0]); AssertPixelDataEqual(DicomPixelData.Create(streamAndStoredFile.Key.Dataset).GetFrame(framesToRequest[1]), response.ResponseStreams.ToList()[1]); // Validate dicom request is populated with correct transcode values ValidateDicomRequestIsPopulated(); streamAndStoredFile.Value.Dispose(); }
public async Task GivenARequestWithInvalidStudyAndSeriesIdentifiers_WhenRetrievingSeries_ThenDicomInvalidIdentifierExceptionIsThrown(string studyInstanceUid, string seriesInstanceUid) { RetrieveResourceRequest request = new RetrieveResourceRequest(studyInstanceUid, seriesInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetSeries() }); var ex = await Assert.ThrowsAsync <InvalidIdentifierException>(() => _retrieveResourceHandler.Handle(request, CancellationToken.None)); Assert.Equal($"DICOM Identifier 'StudyInstanceUid' value '{studyInstanceUid.Trim()}' is invalid. Value length should not exceed the maximum length of 64 characters. Value should contain characters in '0'-'9' and '.'. Each component must start with non-zero number.", ex.Message); }
public async Task GivenStoredInstancesWithFrames_WhenRetrieveRequestForNonExistingFrame_ThenNotFoundIsThrown() { // Add multiple instances to validate that we evaluate the requested instance and ignore the other(s). List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Frames); var framesToRequest = new List <int> { 1, 4 }; // For the instance, set up the fileStore to return a stream containing the file associated with the identifier with 3 frames. Stream streamOfStoredFiles = StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(versionedInstanceIdentifiers.First()), frames: 3).Result.Value; _fileStore.GetFileAsync(versionedInstanceIdentifiers.First(), DefaultCancellationToken).Returns(streamOfStoredFiles); var retrieveResourceRequest = new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, framesToRequest, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetFrame() }); _dicomFrameHandler.GetFramesResourceAsync(streamOfStoredFiles, retrieveResourceRequest.Frames, true, "*").Throws(new FrameNotFoundException()); // Request 2 frames - one which exists and one which doesn't. await Assert.ThrowsAsync <FrameNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( retrieveResourceRequest, DefaultCancellationToken)); // Dispose the stream. streamOfStoredFiles.Dispose(); }
public async Task GivenStoredInstancesWithMissingFile_WhenRetrieveRequestForInstance_ThenNotFoundIsThrown() { // Add multiple instances to validate that we return the requested instance and ignore the other(s). List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Instance); // For the first instance identifier, set up the fileStore to throw a store exception with the status code 404 (NotFound). _fileStore.GetFileAsync(versionedInstanceIdentifiers.First(), DefaultCancellationToken).Throws(new InstanceNotFoundException()); await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance() }), DefaultCancellationToken)); }
public async Task GivenNoStoredInstances_WhenRetrieveRequestForSeries_ThenNotFoundIsThrown() { await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetSeries() }), CancellationToken.None)); }
public async Task GivenStoredInstancesWithMissingFile_WhenRetrieveRequestForStudy_ThenNotFoundIsThrown() { await GenerateDicomDatasets(_firstSeriesInstanceUid, 1, true); await GenerateDicomDatasets(_firstSeriesInstanceUid, 1, false); await GenerateDicomDatasets(_secondSeriesInstanceUid, 1, true); await Assert.ThrowsAsync <ItemNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }), CancellationToken.None)); }
public async Task GivenStoredInstances_WhenRetrieveRequestForSeries_ThenInstancesInSeriesAreRetrievedSuccesfully() { var datasets = new List <DicomDataset>(); datasets.AddRange(await GenerateDicomDatasets(_firstSeriesInstanceUid, 2, true)); datasets.AddRange(await GenerateDicomDatasets(_secondSeriesInstanceUid, 1, true)); RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync( new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetSeries() }), CancellationToken.None); ValidateResponseDicomFiles(response.ResponseStreams, datasets.Select(ds => ds).Where(ds => ds.ToInstanceIdentifier().SeriesInstanceUid == _firstSeriesInstanceUid)); }