Example #1
0
        public async Task GivenStoredInstances_WhenRetrieveRequestForInstance_ThenInstanceIsRetrievedSuccessfully()
        {
            // 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 return a stream containing a file associated with the identifier.
            KeyValuePair <DicomFile, Stream> streamAndStoredFile = StreamAndStoredFileFromDataset(GenerateDatasetsFromIdentifiers(versionedInstanceIdentifiers.First())).Result;

            _fileStore.GetFileAsync(streamAndStoredFile.Key.Dataset.ToVersionedInstanceIdentifier(0), DefaultCancellationToken).Returns(streamAndStoredFile.Value);

            RetrieveResourceResponse response = await _retrieveResourceService.GetInstanceResourceAsync(
                new RetrieveResourceRequest(
                    _studyInstanceUid,
                    _firstSeriesInstanceUid,
                    _sopInstanceUid,
                    new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance() }),
                DefaultCancellationToken);

            // Validate response status code and ensure response stream has expected file - it should be equivalent to what the store was set up to return.
            ValidateResponseStreams(new List <DicomFile>()
            {
                streamAndStoredFile.Key
            }, response.ResponseStreams);

            // Dispose created streams.
            streamAndStoredFile.Value.Dispose();
        }
        public void GivenRetrieveResourcesRequestForInstance_WhenConstructed_ThenInstanceResourceTypeIsSet()
        {
            var request = new RetrieveResourceRequest(
                TestUidGenerator.Generate(),
                TestUidGenerator.Generate(),
                TestUidGenerator.Generate(),
                new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance(transferSyntax: string.Empty) });

            Assert.Equal(ResourceType.Instance, request.ResourceType);
        }
Example #3
0
        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));
        }
Example #4
0
        public async Task GivenNoStoredInstances_WhenRetrieveRequestForInstance_ThenNotFoundIsThrown()
        {
            _instanceStore.GetInstanceIdentifierAsync(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid).Returns(new List <VersionedInstanceIdentifier>());

            await Assert.ThrowsAsync <InstanceNotFoundException>(() => _retrieveResourceService.GetInstanceResourceAsync(
                                                                     new RetrieveResourceRequest(_studyInstanceUid, _firstSeriesInstanceUid, _sopInstanceUid, new[] { AcceptHeaderHelpers.CreateAcceptHeaderForGetInstance() }),
                                                                     DefaultCancellationToken));
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
 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() });
     await Assert.ThrowsAsync <InvalidIdentifierException>(() => _retrieveResourceHandler.Handle(request, CancellationToken.None));
 }