Ejemplo n.º 1
0
        public async Task Store_ShallThrowIfNoFilesSpecified()
        {
            var response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK
            };

            var httpClient = new HttpClient();
            var service    = new StowService(httpClient, _logger.Object);

            await Assert.ThrowsAsync <ArgumentNullException>(async() => await service.Store(null));

            await Assert.ThrowsAsync <ArgumentException>(async() => await service.Store(new List <DicomFile>()));
        }
Ejemplo n.º 2
0
        public async Task Store_HandlesResponses(HttpStatusCode status, string message)
        {
            var studyInstanceUid = DicomUIDGenerator.GenerateDerivedFromUUID();
            var instances        = _fixture.GenerateDicomFiles(3, studyInstanceUid);

            var response = new HttpResponseMessage
            {
                StatusCode = status,
                Content    = new StringContent(message)
            };

            Mock <HttpMessageHandler> handlerMock;
            HttpClient httpClient;

            GenerateHttpClient(response, out handlerMock, out httpClient);

            var service = new StowService(httpClient, _logger.Object);

            var dicomWebResponse = await service.Store(instances);

            Assert.IsType <DicomWebResponse <string> >(dicomWebResponse);
            Assert.Equal(message, dicomWebResponse.Result);
            Assert.Equal(status, dicomWebResponse.StatusCode);

            handlerMock.Protected().Verify(
                "SendAsync",
                Times.Exactly(1),
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Post &&
                                               req.Content is MultipartContent &&
                                               req.RequestUri.ToString().Equals($"{BaseUri}studies/")),
                ItExpr.IsAny <CancellationToken>());
        }
Ejemplo n.º 3
0
        public async Task Store_ShallThrowIfNoFilesMatchStudyInstanceUid()
        {
            var studyInstanceUid = DicomUIDGenerator.GenerateDerivedFromUUID();
            var instances        = _fixture.GenerateDicomFiles(3, studyInstanceUid);

            var httpClient = new HttpClient();
            var service    = new StowService(httpClient, _logger.Object);

            var otherStudyInstanceUid = "1.2.3.4.5";
            await Assert.ThrowsAsync <ArgumentException>(async() => await service.Store(otherStudyInstanceUid, instances));
        }
Ejemplo n.º 4
0
        public async Task Store_HandlesSendAsyncFailures()
        {
            var studyInstanceUid = DicomUIDGenerator.GenerateDerivedFromUUID();
            var instances        = _fixture.GenerateDicomFiles(1, studyInstanceUid);

            var handlerMock = new Mock <HttpMessageHandler>();

            handlerMock
            .Protected()
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>())
            .Throws(new Exception("unknown"));
            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri(BaseUri)
            };

            var service = new StowService(httpClient, _logger.Object);

            var exception = await Assert.ThrowsAsync <DicomWebClientException>(async() => await service.Store(instances));

            Assert.Null(exception.StatusCode);
        }