public async Task GivenAnInvalidParameter_WhenRetrievingChangeFeed_ThenBadRequestReturned(string limit, string offset, string includeMetadata) { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.GetChangeFeed($"?limit={limit}&offset={offset}&includeMetadata={includeMetadata}")); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task GivenAMixOfTransferSyntaxes_WhenSomeAreSupported_NotAcceptableIsReturned() { var seriesInstanceUid = TestUidGenerator.Generate(); var studyInstanceUid = TestUidGenerator.Generate(); DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, seriesInstanceUid, transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID); DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, seriesInstanceUid, transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID, encode: false); DicomFile dicomFile3 = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, seriesInstanceUid, transferSyntax: DicomTransferSyntax.ImplicitVRLittleEndian.UID.UID); await _client.StoreAsync(new[] { dicomFile1, dicomFile2, dicomFile3 }); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveSeriesAsync( studyInstanceUid, seriesInstanceUid, DicomTransferSyntax.JPEG2000Lossy.UID.UID)); Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode); }
public async Task GivenExistingDataset_WhenStoring_TheServerShouldReturnConflict() { var studyInstanceUID = TestUidGenerator.Generate(); try { DicomFile dicomFile1 = Samples.CreateRandomDicomFile(studyInstanceUID); using DicomWebResponse <DicomDataset> response = await _instancesManager.StoreAsync(new[] { dicomFile1 }); Assert.Equal(HttpStatusCode.OK, response.StatusCode); DicomDataset dataset = await response.GetValueAsync(); await ValidateReferencedSopSequenceAsync( response, ConvertToReferencedSopSequenceEntry(dicomFile1.Dataset)); Assert.False(dataset.TryGetSequence(DicomTag.FailedSOPSequence, out DicomSequence _)); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _instancesManager.StoreAsync(new[] { dicomFile1 })); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); ValidationHelpers.ValidateFailedSopSequence( exception.ResponseDataset, ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, SopInstanceAlreadyExistsFailureCode)); } finally { await _client.DeleteStudyAsync(studyInstanceUID); } }
public async Task GivenARequestWithInvalidTransferSyntax_WhenRetrievingInstance_TheServerShouldReturnBadRequest(string transferSyntax) { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.RetrieveInstanceAsync(TestUidGenerator.Generate(), TestUidGenerator.Generate(), TestUidGenerator.Generate(), transferSyntax)); Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode); }
public async Task GivenAnInvalidParameter_WhenRetrievingChangeFeedLatest_ThenBadRequestReturned() { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.GetChangeFeedLatest("?includeMetadata=asdf")); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task GivenInvalidFrames_WhenRetrievingFrame_TheServerShouldReturnBadRequest(params string[] frames) { var requestUri = new Uri(string.Format(DicomWebConstants.BaseRetrieveFramesUriFormat, TestUidGenerator.Generate(), TestUidGenerator.Generate(), TestUidGenerator.Generate(), string.Join("%2C", frames)), UriKind.Relative); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.RetrieveFramesAsync(requestUri)); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task GivenSearchRequest_WithUnsupportedTag_ReturnBadRequest() { DicomWebException <string> exception = await Assert.ThrowsAsync <DicomWebException <string> >( () => _client.QueryWithBadRequest("/studies?Modality=CT")); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); Assert.Equal(exception.Value, string.Format(DicomCoreResource.UnsupportedSearchParameter, "Modality")); }
public async Task GivenRandomContent_WhenStoring_TheServerShouldReturnConflict() { await using MemoryStream stream = _recyclableMemoryStreamManager.GetStream(); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.StoreAsync(new[] { stream })); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); }
public async Task GivenARequestWithInvalidStudyInstanceUID_WhenStoring_TheServerShouldReturnBadRequest() { await using MemoryStream stream = _recyclableMemoryStreamManager.GetStream(); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.StoreAsync(new[] { stream }, studyInstanceUid: new string('b', 65))); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task GivenSearchRequest_WithUnsupportedTag_ReturnBadRequest() { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.QueryStudyAsync("Modality=CT")); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); Assert.Equal(exception.ResponseMessage, string.Format(DicomCoreResource.UnsupportedSearchParameter, "Modality", "study")); }
public async Task GivenStoredInstance_WhenRetrieveRequestForDifferentInstance_ThenServerShouldReturnNotFound() { (InstanceIdentifier identifier, DicomFile file) = await CreateAndStoreDicomFile(); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.RetrieveInstanceAsync(identifier.StudyInstanceUid, identifier.SeriesInstanceUid, TestUidGenerator.Generate())); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task GivenNonExistingFrames_WhenRetrieveFrame_ThenServerShouldReturnNotFound() { (InstanceIdentifier identifier, DicomFile file) = await CreateAndStoreDicomFile(2); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _client.RetrieveFramesAsync(identifier.StudyInstanceUid, identifier.SeriesInstanceUid, identifier.SopInstanceUid, dicomTransferSyntax: "*", frames: new[] { 4 })); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task GivenARequestWithFrameLessThanOrEqualTo0_WhenRetrievingFrames_TheServerShouldReturnBadRequest(params int[] frames) { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveFramesAsync( studyInstanceUid: TestUidGenerator.Generate(), seriesInstanceUid: TestUidGenerator.Generate(), sopInstanceUid: TestUidGenerator.Generate(), frames: frames)); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task GivenRetrieveSeriesMetadataRequest_WhenSeriesInstanceUidDoesnotExists_ThenNotFoundIsReturned() { string studyInstanceUid = TestUidGenerator.Generate(); await PostDicomFileAsync(ResourceType.Series, studyInstanceUid, TestUidGenerator.Generate()); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveSeriesMetadataAsync(studyInstanceUid, TestUidGenerator.Generate())); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task GivenDicomRequest_WithNoAuthenticationToken_ReturnUnauthorized() { if (AuthenticationSettings.SecurityEnabled) { IDicomWebClient client = _fixture.GetDicomWebClient(TestApplications.InvalidClient); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => client.QueryAsync("/studies")); Assert.Equal(HttpStatusCode.Unauthorized, exception.StatusCode); } }
public async Task GivenDatasetWithInvalidUid_WhenStoring_TheServerShouldReturnConflict(string studyInstanceUID) { DicomFile dicomFile1 = Samples.CreateRandomDicomFile(studyInstanceUID, validateItems: false); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _instancesManager.StoreAsync(new[] { dicomFile1 })); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); Assert.False(exception.ResponseDataset.TryGetSequence(DicomTag.ReferencedSOPSequence, out DicomSequence _)); ValidationHelpers.ValidateFailedSopSequence( exception.ResponseDataset, ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, ValidationFailedFailureCode)); }
public async Task GivenPostDicomRequest_WithAReadOnlyToken_ReturnUnauthorized() { if (AuthenticationSettings.SecurityEnabled) { DicomFile dicomFile = Samples.CreateRandomDicomFileWithPixelData(frames: 1); var dicomInstance = dicomFile.Dataset.ToInstanceIdentifier(); IDicomWebClient client = _fixture.GetDicomWebClient(TestApplications.GlobalAdminServicePrincipal, TestUsers.User1); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => client.StoreAsync(new[] { dicomFile }, dicomInstance.StudyInstanceUid)); Assert.Equal(HttpStatusCode.Forbidden, exception.StatusCode); } }
public async Task GivenDatasetWithInvalidVrValue_WhenStoring_TheServerShouldReturnConflict() { var studyInstanceUID = TestUidGenerator.Generate(); DicomFile dicomFile1 = Samples.CreateRandomDicomFileWithInvalidVr(studyInstanceUID); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.StoreAsync(new[] { dicomFile1 })); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); Assert.False(exception.ResponseDataset.TryGetSequence(DicomTag.ReferencedSOPSequence, out DicomSequence _)); ValidationHelpers.ValidateFailedSopSequence( exception.ResponseDataset, ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, ValidationFailedFailureCode)); }
public async Task GivenAnExistingInstance_WhenDeletingInstanceSecondTime_TheServerShouldReturnNotFound() { var studyInstanceUid = TestUidGenerator.Generate(); var seriesInstanceUid = TestUidGenerator.Generate(); var sopInstanceUid = TestUidGenerator.Generate(); await CreateFile(studyInstanceUid, seriesInstanceUid, sopInstanceUid); DicomWebResponse response = await _client.DeleteInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid); await VerifyAllRemoval(studyInstanceUid, seriesInstanceUid, sopInstanceUid); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.DeleteInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid)); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task GivenAMultipartRequestWithEmptyContent_WhenStoring_TheServerShouldReturnConflict() { var multiContent = new MultipartContent("related"); multiContent.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", $"\"{DicomWebConstants.MediaTypeApplicationDicom.MediaType}\"")); var byteContent = new ByteArrayContent(Array.Empty <byte>()); byteContent.Headers.ContentType = DicomWebConstants.MediaTypeApplicationDicom; multiContent.Add(byteContent); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>( () => _instancesManager.StoreAsync(multiContent)); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); }
public async Task GivenUnsupportedInternalTransferSyntax_WhenRetrieveInstance_ThenServerShouldReturnNotAcceptable() { var studyInstanceUid = TestUidGenerator.Generate(); var seriesInstanceUid = TestUidGenerator.Generate(); var sopInstanceUid = TestUidGenerator.Generate(); DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, seriesInstanceUid, sopInstanceUid, transferSyntax: DicomTransferSyntax.MPEG2.UID.UID, encode: false); await InternalStoreAsync(new[] { dicomFile }); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid, dicomTransferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID)); Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode); }
public async void GivenAllDifferentStudyInstanceUIDs_WhenStoringWithProvidedStudyInstanceUID_TheServerShouldReturnConflict() { DicomFile dicomFile1 = Samples.CreateRandomDicomFile(); DicomFile dicomFile2 = Samples.CreateRandomDicomFile(); var studyInstanceUID = TestUidGenerator.Generate(); DicomWebException <DicomDataset> exception = await Assert.ThrowsAsync <DicomWebException <DicomDataset> >(() => _client.StoreAsync( new[] { dicomFile1, dicomFile2 }, studyInstanceUID)); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); Assert.NotNull(exception.Value); Assert.True(exception.Value.Count() == 1); ValidationHelpers.ValidateFailedSopSequence( exception.Value, ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, MismatchStudyInstanceUidFailureCode), ConvertToFailedSopSequenceEntry(dicomFile2.Dataset, MismatchStudyInstanceUidFailureCode)); }
[InlineData("1.2.840.10008.5.1.4.1.1.1", HttpStatusCode.BadRequest)] // Valid UID, but not a transfer syntax public async Task GivenAnUnsupportedTransferSyntax_WhenRetrievingStudy_NotAcceptableIsReturned(string transferSyntax, HttpStatusCode expectedStatusCode) { IEnumerable <DicomFile> dicomFiles = Samples.GetDicomFilesForTranscoding(); DicomFile dicomFile = dicomFiles.FirstOrDefault(f => (Path.GetFileNameWithoutExtension(f.File.Name) == "ExplicitVRLittleEndian")); var dicomInstance = dicomFile.Dataset.ToInstanceIdentifier(); try { await _client.StoreAsync(new[] { dicomFile }); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveInstanceAsync( dicomInstance.StudyInstanceUid, dicomInstance.SeriesInstanceUid, dicomInstance.SopInstanceUid, transferSyntax)); Assert.Equal(expectedStatusCode, exception.StatusCode); } finally { await _client.DeleteInstanceAsync(dicomInstance.StudyInstanceUid, dicomInstance.SeriesInstanceUid, dicomInstance.SopInstanceUid); } }
public async Task GivenMultipleInstancesWithMixTransferSyntax_WhenRetrieveStudy_ThenServerShouldReturnNotAcceptable() { var studyInstanceUid = TestUidGenerator.Generate(); DicomFile dicomFile1 = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, TestUidGenerator.Generate(), transferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID); DicomFile dicomFile2 = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, TestUidGenerator.Generate(), transferSyntax: DicomTransferSyntax.MPEG2.UID.UID, encode: false); await _instancesManager.StoreAsync(new[] { dicomFile1, dicomFile2 }); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveStudyAsync(studyInstanceUid, dicomTransferSyntax: DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID)); Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode); }
public async Task GivenDatasetWithInvalidUid_WhenStoring_TheServerShouldReturnConflict(string studyInstanceUID) { #pragma warning disable CS0618 // Type or member is obsolete DicomValidation.AutoValidation = false; #pragma warning restore CS0618 // Type or member is obsolete DicomFile dicomFile1 = Samples.CreateRandomDicomFile(studyInstanceUID); #pragma warning disable CS0618 // Type or member is obsolete DicomValidation.AutoValidation = true; #pragma warning restore CS0618 // Type or member is obsolete DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.StoreAsync(new[] { dicomFile1 })); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); Assert.False(exception.ResponseDataset.TryGetSequence(DicomTag.ReferencedSOPSequence, out DicomSequence _)); ValidationHelpers.ValidateFailedSopSequence( exception.ResponseDataset, ConvertToFailedSopSequenceEntry(dicomFile1.Dataset, ValidationFailedFailureCode)); }
public async void GivenAMultipartRequestWithEmptyContent_WhenStoring_TheServerShouldReturnConflict() { var request = new HttpRequestMessage(HttpMethod.Post, "studies"); request.Headers.Add(HeaderNames.Accept, DicomWebClient.MediaTypeApplicationDicomJson.MediaType); var multiContent = new MultipartContent("related"); multiContent.Headers.ContentType.Parameters.Add(new System.Net.Http.Headers.NameValueHeaderValue("type", $"\"{DicomWebClient.MediaTypeApplicationDicom.MediaType}\"")); var byteContent = new ByteArrayContent(Array.Empty <byte>()); byteContent.Headers.ContentType = DicomWebClient.MediaTypeApplicationDicom; multiContent.Add(byteContent); request.Content = multiContent; DicomWebException <DicomDataset> exception = await Assert.ThrowsAsync <DicomWebException <DicomDataset> >( () => _client.PostMultipartContentAsync(multiContent, "studies")); Assert.Equal(HttpStatusCode.Conflict, exception.StatusCode); }
public async Task GivenUnsupportedTransferSyntax_WhenRetrieveFrame_ThenServerShouldReturnNotAcceptable() { string studyInstanceUid = TestUidGenerator.Generate(); string seriesInstanceUid = TestUidGenerator.Generate(); string sopInstanceUid = TestUidGenerator.Generate(); DicomFile dicomFile = Samples.CreateRandomDicomFileWith8BitPixelData( studyInstanceUid, seriesInstanceUid, sopInstanceUid, transferSyntax: DicomTransferSyntax.HEVCH265Main10ProfileLevel51.UID.UID, encode: false); await InternalStoreAsync(new[] { dicomFile }); DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveFramesAsync( studyInstanceUid, seriesInstanceUid, sopInstanceUid, dicomTransferSyntax: DicomTransferSyntax.JPEG2000Lossless.UID.UID, frames: new[] { 1 })); Assert.Equal(HttpStatusCode.NotAcceptable, exception.StatusCode); }
public async Task GivenNonExistingInstance_WhenRetrieveInstance_ThenServerShouldReturnNotFound() { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveInstanceAsync(TestUidGenerator.Generate(), TestUidGenerator.Generate(), TestUidGenerator.Generate())); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
private async Task VerifySopInstanceRemoval(string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid) { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.RetrieveInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid)); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task GivenABadSopInstanceUid_WhenDeleting_TheServerShouldReturnBackRequest(string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid) { DicomWebException exception = await Assert.ThrowsAsync <DicomWebException>(() => _client.DeleteInstanceAsync(studyInstanceUid, seriesInstanceUid, sopInstanceUid)); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }