Exemple #1
0
        public async Task GivenSpecificTransferSyntax_WhenRetrieveRequestForStudy_ThenInstancesInStudyAreTranscodedSuccesfully()
        {
            // Add multiple instances to validate that we return the requested instance and ignore the other(s).
            List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Study);

            // For each instance identifier, set up the fileStore to return a stream containing a file associated with the identifier.
            var streamsAndStoredFiles = versionedInstanceIdentifiers.Select(
                x => StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(x)).Result).ToList();

            streamsAndStoredFiles.ForEach(x => _fileStore.GetFileAsync(x.Key.Dataset.ToVersionedInstanceIdentifier(0), DefaultCancellationToken).Returns(x.Value));

            string transferSyntax = "1.2.840.10008.1.2.1";

            streamsAndStoredFiles.ForEach(x => _retrieveTranscoder.TranscodeFileAsync(x.Value, transferSyntax).Returns(x.Value));

            RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync(
                new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy(transferSyntax: transferSyntax) }),
                DefaultCancellationToken);

            // Validate response status code and ensure response streams have expected files - they should be equivalent to what the store was set up to return.
            ValidateResponseStreams(streamsAndStoredFiles.Select(x => x.Key), response.ResponseStreams);

            // Validate dicom request is populated with correct transcode values
            ValidateDicomRequestIsPopulated(true, response.ResponseStreams.Sum(s => s.Length));

            // Dispose created streams.
            streamsAndStoredFiles.ToList().ForEach(x => x.Value.Dispose());
        }
        public void GivenNoMatchedAcceptHeaders_WhenGetTransferSyntax_ThenShouldThrowNotAcceptableException()
        {
            // Use content type that GetStudy doesn't support
            AcceptHeader           acceptHeader = AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy(mediaType: KnownContentTypes.ImageJpeg);
            AcceptHeaderDescriptor acceptHeaderDescriptor;

            Assert.ThrowsAny <NotAcceptableException>(() => _handler.GetTransferSyntax(ResourceType.Study, new[] { acceptHeader }, out acceptHeaderDescriptor));
        }
Exemple #3
0
        public async Task GivenStoredInstances_WhenRetrieveRequestForStudy_ThenInstancesInStudyAreRetrievedSuccesfully()
        {
            List <DicomDataset> 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, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }),
                _defaultCancellationToken);

            ValidateResponseDicomFiles(response.ResponseStreams, datasets.Select(ds => ds));
        }
        public async Task GivenStoredInstances_WhenRetrieveRequestForStudy_ThenInstancesInStudyAreRetrievedSuccesfully()
        {
            // Add multiple instances to validate that we return the requested instance and ignore the other(s).
            List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Study);

            // For each instance identifier, set up the fileStore to return a stream containing a file associated with the identifier.
            List <KeyValuePair <DicomFile, Stream> > streamsAndStoredFiles = versionedInstanceIdentifiers.Select(
                x => StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(x)).Result).ToList();

            streamsAndStoredFiles.ForEach(x => _fileStore.GetFileAsync(x.Key.Dataset.ToVersionedInstanceIdentifier(0), _defaultCancellationToken).Returns(x.Value));

            RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync(
                new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }),
                _defaultCancellationToken);

            // Validate response status code and ensure response streams have expected files - they should be equivalent to what the store was set up to return.
            ValidateResponseStreams(streamsAndStoredFiles.Select(x => x.Key), response.ResponseStreams);

            // Dispose created streams.
            streamsAndStoredFiles.ToList().ForEach(x => x.Value.Dispose());
        }
Exemple #5
0
        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() }),
                                                                 _defaultCancellationToken));
        }
Exemple #6
0
 public async Task GivenNoStoredInstances_WhenRetrieveRequestForStudy_ThenNotFoundIsThrown()
 {
     await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync(
                                                              new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }),
                                                              _defaultCancellationToken));
 }
Exemple #7
0
        public async Task GivenStoredInstancesWhereOneIsMissingFile_WhenRetrieveRequestForStudy_ThenNotFoundIsThrown()
        {
            List <VersionedInstanceIdentifier> versionedInstanceIdentifiers = SetupInstanceIdentifiersList(ResourceType.Study);

            // 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, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }),
                                                                     DefaultCancellationToken));
        }
Exemple #8
0
        public async Task GivenNoStoredInstances_WhenRetrieveRequestForStudy_ThenNotFoundIsThrown()
        {
            _instanceStore.GetInstanceIdentifiersInStudyAsync(_studyInstanceUid).Returns(new List <VersionedInstanceIdentifier>());

            await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync(
                                                                     new RetrieveResourceRequest(_studyInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetStudy() }),
                                                                     DefaultCancellationToken));
        }