public async Task RetrieveMetadata_Series_BadUids() { var httpClient = new HttpClient(); var wado = new WadoService(httpClient, new Uri("http://dummy/api/")); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>(null, seriesInstanceUid: null)) { } }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>("bad uid", seriesInstanceUid: null)) { } }); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: null)) { } }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: "bad uid")) { } }); }
public async Task RetrieveMetadata_Instance_HandleEmptyDataWithHttpOk() { var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var instanceUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("") }; Mock <HttpMessageHandler> handlerMock; HttpClient httpClient; GenerateHttpClient(response, out handlerMock, out httpClient); var wado = new WadoService(httpClient, new Uri("http://dummy/api/")); var result = await wado.RetrieveMetadata <string>(studyUid.UID, seriesUid.UID, instanceUid.UID); Assert.Null(result); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.Headers.Accept.First().MediaType.Equals(DicomFileGeneratorFixture.MimeApplicationDicomJson)), ItExpr.IsAny <CancellationToken>()); }
public async Task RetrieveMetadata_Series_DicomDataset() { var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = _fixture.GenerateInstancesAsJson(2, studyUid, seriesUid), }; Mock <HttpMessageHandler> handlerMock; HttpClient httpClient; GenerateHttpClient(response, out handlerMock, out httpClient); var wado = new WadoService(httpClient, new Uri("http://dummy/api/")); var count = 0; await foreach (var instance in wado.RetrieveMetadata <DicomDataset>(studyUid.UID, seriesUid.UID)) { count++; Assert.IsType <DicomDataset>(instance); } Assert.Equal(2, count); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.Headers.Accept.First().MediaType.Equals(DicomFileGeneratorFixture.MimeApplicationDicomJson)), ItExpr.IsAny <CancellationToken>()); }
public async Task RetrieveMetadata_Instance_DicomDataset() { var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var instanceUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = _fixture.GenerateInstancesAsJson(2, studyUid, seriesUid), }; Mock <HttpMessageHandler> handlerMock; HttpClient httpClient; GenerateHttpClient(response, out handlerMock, out httpClient); var wado = new WadoService(httpClient); var instance = await wado.RetrieveMetadata <string>(studyUid.UID, seriesUid.UID, instanceUid.UID); Assert.IsType <string>(instance); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri.ToString().Equals($"{BaseUri}studies/{studyUid.UID}/series/{seriesUid.UID}/instances/{instanceUid.UID}/metadata") && req.Headers.Accept.First().MediaType.Equals(DicomFileGeneratorFixture.MimeApplicationDicomJson)), ItExpr.IsAny <CancellationToken>()); }
public async Task RetrieveMetadata_Study_BadStudyUid() { var httpClient = new HttpClient(); var wado = new WadoService(httpClient, new Uri("http://dummy/api/")); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>(null)) { } }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await foreach (var instance in wado.RetrieveMetadata <string>("bad uid")) { } }); }
public async Task RetrieveMetadata_Instance_BadUids() { var httpClient = GetHttpClient(); var wado = new WadoService(httpClient); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await wado.RetrieveMetadata <string>(null, seriesInstanceUid: null, sopInstanceUid: null); }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await wado.RetrieveMetadata <string>("bad uid", seriesInstanceUid: null, sopInstanceUid: null); }); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: null, sopInstanceUid: null); }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: "bad id", sopInstanceUid: "bad id"); }); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: DicomUIDGenerator.GenerateDerivedFromUUID().UID, sopInstanceUid: null); }); await Assert.ThrowsAsync <DicomValidationException>(async() => { await wado.RetrieveMetadata <string>(DicomUIDGenerator.GenerateDerivedFromUUID().UID, seriesInstanceUid: DicomUIDGenerator.GenerateDerivedFromUUID().UID, sopInstanceUid: "bad id"); }); }
public async Task RetrieveMetadata_Study_InvalidReturnType() { var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var httpClient = new HttpClient(); var wado = new WadoService(httpClient, new Uri("http://dummy/api/")); await Assert.ThrowsAsync <UnsupportedReturnTypeException>(async() => { await foreach (var instance in wado.RetrieveMetadata <int>(studyUid.UID)) { } }); }
public async Task RetrieveMetadata_Instance_InvalidReturnType() { var studyUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var seriesUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var instanceUid = DicomUIDGenerator.GenerateDerivedFromUUID(); var httpClient = new HttpClient(); var wado = new WadoService(httpClient); await Assert.ThrowsAsync <UnsupportedReturnTypeException>(async() => { await wado.RetrieveMetadata <int>(studyUid.UID, seriesUid.UID, instanceUid.UID); }); }