示例#1
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));
        }
        private List <VersionedInstanceIdentifier> SetupInstanceIdentifiersList(ResourceType resourceType)
        {
            var dicomInstanceIdentifiersList = new List <VersionedInstanceIdentifier>();

            switch (resourceType)
            {
            case ResourceType.Study:
                dicomInstanceIdentifiersList.Add(new VersionedInstanceIdentifier(_studyInstanceUid, TestUidGenerator.Generate(), TestUidGenerator.Generate(), version: 0));
                dicomInstanceIdentifiersList.Add(new VersionedInstanceIdentifier(_studyInstanceUid, TestUidGenerator.Generate(), TestUidGenerator.Generate(), version: 1));
                _instanceStore.GetInstanceIdentifiersInStudyAsync(_studyInstanceUid, DefaultCancellationToken).Returns(dicomInstanceIdentifiersList);
                break;

            case ResourceType.Series:
                dicomInstanceIdentifiersList.Add(new VersionedInstanceIdentifier(_studyInstanceUid, _seriesInstanceUid, TestUidGenerator.Generate(), version: 0));
                dicomInstanceIdentifiersList.Add(new VersionedInstanceIdentifier(_studyInstanceUid, _seriesInstanceUid, TestUidGenerator.Generate(), version: 1));
                _instanceStore.GetInstanceIdentifiersInSeriesAsync(_studyInstanceUid, _seriesInstanceUid, DefaultCancellationToken).Returns(dicomInstanceIdentifiersList);
                break;

            case ResourceType.Instance:
                dicomInstanceIdentifiersList.Add(new VersionedInstanceIdentifier(_studyInstanceUid, _seriesInstanceUid, _sopInstanceUid, version: 0));
                _instanceStore.GetInstanceIdentifierAsync(_studyInstanceUid, _seriesInstanceUid, _sopInstanceUid, DefaultCancellationToken).Returns(dicomInstanceIdentifiersList);
                break;
            }

            return(dicomInstanceIdentifiersList);
        }
        public static async Task <IEnumerable <VersionedInstanceIdentifier> > GetInstancesToRetrieve(
            this IInstanceStore instanceStore,
            ResourceType resourceType,
            int partitionKey,
            string studyInstanceUid,
            string seriesInstanceUid,
            string sopInstanceUid,
            CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(instanceStore, nameof(instanceStore));

            IEnumerable <VersionedInstanceIdentifier> instancesToRetrieve = Enumerable.Empty <VersionedInstanceIdentifier>();

            switch (resourceType)
            {
            case ResourceType.Frames:
            case ResourceType.Instance:
                instancesToRetrieve = await instanceStore.GetInstanceIdentifierAsync(
                    partitionKey,
                    studyInstanceUid,
                    seriesInstanceUid,
                    sopInstanceUid,
                    cancellationToken);

                break;

            case ResourceType.Series:
                instancesToRetrieve = await instanceStore.GetInstanceIdentifiersInSeriesAsync(
                    partitionKey,
                    studyInstanceUid,
                    seriesInstanceUid,
                    cancellationToken);

                break;

            case ResourceType.Study:
                instancesToRetrieve = await instanceStore.GetInstanceIdentifiersInStudyAsync(
                    partitionKey,
                    studyInstanceUid,
                    cancellationToken);

                break;

            default:
                Debug.Fail($"Unknown retrieve transaction type: {resourceType}", nameof(resourceType));
                break;
            }

            if (!instancesToRetrieve.Any())
            {
                ThrowNotFoundException(resourceType);
            }

            return(instancesToRetrieve);
        }