Beispiel #1
0
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveFrame_ThenServerShouldReturnExpectedContent(string testDataFolder, string mediaType, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = await DicomFile.OpenAsync(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            var instanceId = inputDicomFile.Dataset.ToInstanceIdentifier();

            _studiesToClean.Add(instanceId.StudyInstanceUid);

            DicomFile      outputDicomFile = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
            DicomPixelData pixelData       = DicomPixelData.Create(outputDicomFile.Dataset);

            using DicomWebAsyncEnumerableResponse <Stream> response = await _client.RetrieveFramesAsync(
                      instanceId.StudyInstanceUid,
                      instanceId.SeriesInstanceUid,
                      instanceId.SopInstanceUid,
                      mediaType,
                      transferSyntax,
                      frames : new[] { 1 });

            int frameIndex = 0;

            await foreach (Stream item in response)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                Assert.Equal(item.ToByteArray(), pixelData.GetFrame(frameIndex).Data);
                frameIndex++;
            }
        }
Beispiel #2
0
        public async Task GivenSinglePartAcceptHeader_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            using DicomWebResponse <DicomFile> response = await _client.RetrieveInstanceAsync(instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.ApplicationDicomMediaType, response.ContentHeaders.ContentType.MediaType);

            var actual = await response.GetValueAsync();

            var expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);

            Assert.Equal(expected, actual, new DicomFileEqualityComparer(
                             ignoredTags: new[]
            {
                DicomTag.ImplementationVersionName,      // Version name is updated as we update fo-dicom
                DicomTag.StudyInstanceUID,
                DicomTag.SeriesInstanceUID,
                DicomTag.SOPInstanceUID
            }));
        }
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveStudy_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            using DicomWebAsyncEnumerableResponse <DicomFile> response = await _client.RetrieveStudyAsync(instanceId.StudyInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.MultipartRelatedMediaType, response.ContentHeaders.ContentType.MediaType);

            await foreach (DicomFile actual in response)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                var expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
                Assert.Equal(expected, actual, new DicomFileEqualityComparer(
                                 ignoredTags: new[]
                {
                    DicomTag.ImplementationVersionName,      // Version name is updated as we update fo-dicom
                    DicomTag.StudyInstanceUID,
                    DicomTag.SeriesInstanceUID,
                    DicomTag.SOPInstanceUID
                }));
            }
        }
Beispiel #4
0
        public async Task GivenMultipartAcceptHeader_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);
            var instanceId = RandomizeInstanceIdentifier(inputDicomFile.Dataset);

            await _instancesManager.StoreAsync(new[] { inputDicomFile });

            var requestUri = new Uri(DicomApiVersions.Latest + string.Format(DicomWebConstants.BaseInstanceUriFormat, instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid), UriKind.Relative);

            using HttpRequestMessage request   = new HttpRequestMessageBuilder().Build(requestUri, singlePart: false, DicomWebConstants.ApplicationDicomMediaType, transferSyntax);
            using HttpResponseMessage response = await _client.HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveStudy_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            string studyInstanceUid = inputDicomFile.Dataset.GetString(DicomTag.StudyInstanceUID);
            var    response         = await _client.RetrieveStudyAsync(studyInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.MultipartRelatedMediaType, response.Content.Headers.ContentType.MediaType);
            foreach (DicomFile actual in response.Value)
            {
                // TODO: verify media type once https://microsofthealth.visualstudio.com/Health/_workitems/edit/75185 is done
                DicomFile expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);
                Assert.Equal(expected, actual, new DicomFileEqualityComparer());
            }
        }
Beispiel #6
0
        public async Task GivenSupportedAcceptHeaders_WhenRetrieveInstance_ThenServerShouldReturnExpectedContent(string testDataFolder, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = DicomFile.Open(transcoderTestData.InputDicomFile);

            await EnsureFileIsStoredAsync(inputDicomFile);

            var instanceId = inputDicomFile.Dataset.ToInstanceIdentifier();

            var response = await _client.RetrieveInstanceAsync(instanceId.StudyInstanceUid, instanceId.SeriesInstanceUid, instanceId.SopInstanceUid, transferSyntax);

            Assert.Equal(DicomWebConstants.ApplicationDicomMediaType, response.Content.Headers.ContentType.MediaType);
            Assert.Equal(1, response.Value.Count);
            DicomFile actual   = response.Value[0];
            DicomFile expected = DicomFile.Open(transcoderTestData.ExpectedOutputDicomFile);

            Assert.Equal(expected, actual, new DicomFileEqualityComparer());
        }
        private async Task <DicomFile> VerifyTranscoding(string testDataFolder)
        {
            TranscoderTestData testData = TranscoderTestDataHelper.GetTestData(testDataFolder);

            using (FileStream fileStream = File.OpenRead(testData.InputDicomFile))
            {
                DicomFile inputFile = DicomFile.Open(fileStream);

                // Verify if input file has correct input transfersyntax
                Assert.Equal(inputFile.Dataset.InternalTransferSyntax.UID.UID, testData.MetaData.InputSyntaxUid);

                // Reset stream position for trasncoder to consume
                fileStream.Seek(0, SeekOrigin.Begin);

                DicomFile outputFile = await VerifyTranscodeFileAsync(testData, fileStream, inputFile);

                VerifyTranscodeFrame(testData, inputFile);
                return(outputFile);
            }
        }
        public async Task GivenInputAndOutputTransferSyntax_WhenRetrieveFrame_ThenServerShouldReturnExpectedContent(string testDataFolder, string mediaType, string transferSyntax)
        {
            TranscoderTestData transcoderTestData = TranscoderTestDataHelper.GetTestData(testDataFolder);
            DicomFile          inputDicomFile     = await DicomFile.OpenAsync(transcoderTestData.InputDicomFile);

            int numberOfFrames = DicomPixelData.Create(inputDicomFile.Dataset).NumberOfFrames;

            string studyInstanceUid  = inputDicomFile.Dataset.GetString(DicomTag.StudyInstanceUID);
            string seriesInstanceUid = inputDicomFile.Dataset.GetString(DicomTag.SeriesInstanceUID);
            string sopInstanceUid    = inputDicomFile.Dataset.GetString(DicomTag.SOPInstanceUID);

            DicomWebResponse <IEnumerable <DicomDataset> > tryQuery = await _client.QueryAsync(
                $"/studies/{studyInstanceUid}/series/{seriesInstanceUid}/instances?SOPInstanceUID={sopInstanceUid}");

            if (tryQuery.StatusCode == HttpStatusCode.OK)
            {
                await _client.DeleteStudyAsync(studyInstanceUid);
            }

            await _client.StoreAsync(new[] { inputDicomFile });

            DicomWebResponse <IReadOnlyList <Stream> > response = await _client.RetrieveFramesAsync(
                studyInstanceUid : studyInstanceUid,
                seriesInstanceUid : seriesInstanceUid,
                sopInstanceUid : sopInstanceUid,
                mediaType : mediaType,
                dicomTransferSyntax : transferSyntax,
                frames : GenerateFrames(numberOfFrames),
                cancellationToken : _defaultCancellationToken);

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            string byteStreamHash = TranscoderTestDataHelper.GetHashFromStream(response.Value[0]);

            Assert.Equal(transcoderTestData.MetaData.OutputFramesHashCode, byteStreamHash);

            await _client.DeleteStudyAsync(studyInstanceUid);
        }
 public static IEnumerable <object[]> GetTestDatas(string testDataRootFolder)
 {
     return(TranscoderTestDataHelper.GetTestDataFolders(testDataRootFolder)
            .Select(item => new object[] { item }));
 }