public void MetadataHttpError()
        {
            var handler = new Mock <MockHttpHandler>()
            {
                CallBase = true
            };

            handler
            .Setup(f => f.Send(It.IsAny <HttpRequestMessage>()))
            .Returns(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.InternalServerError
            });



            var httpClient = new HttpClient(handler.Object);

            var filename         = @"http://example.com/my_imaginary_file.tif";
            var defaultTileWidth = 512;

            try
            {
                TiffExpander.GetMetadata(httpClient, Log, new Uri(filename), defaultTileWidth, string.Empty);
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
        }
        public void MetadataFileNotFound()
        {
            var filename         = Path.GetFullPath(@"my_imaginary_file.tif");
            var defaultTileWidth = 512;

            var result = TiffExpander.GetMetadata(null, Log, new Uri(filename), defaultTileWidth, string.Empty);
        }
        public void MetadataFromHttp()
        {
            var tiff = Path.GetFullPath(@"test_image.tif");

            using (var fs = File.OpenRead(tiff))
            {
                var handler = new Mock <MockHttpHandler>()
                {
                    CallBase = true
                };
                handler
                .Setup(f => f.Send(It.IsAny <HttpRequestMessage>()))
                .Returns(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.OK,
                    Content    = new StreamContent(fs)
                });

                var httpClient = new HttpClient(handler.Object);

                var filename         = @"http://example.com/my_imaginary_file.tif";
                var defaultTileWidth = 512;
                var expectedWidth    = 1000;
                var expectedHeight   = 1000;

                var result = TiffExpander.GetMetadata(httpClient, Log, new Uri(filename), defaultTileWidth, string.Empty);

                Assert.IsNotNull(result);
                Assert.AreEqual(defaultTileWidth, result.TileWidth, "Returned TileWidth does not match expected value");
                Assert.AreEqual(0, result.TileHeight, "TileHeight should not be set");
                Assert.AreEqual(expectedWidth, result.Width, "Expected Width does not match returned value");
                Assert.AreEqual(expectedHeight, result.Height, "Expected Height does not match returned value");
                Assert.AreEqual(6, result.ScalingLevels, "Returned ScalingLevels does not match expected value");
            }
        }
        public void MetadataHttpTaskCanceledException()
        {
            var handler = new Mock <MockHttpHandler>()
            {
                CallBase = true
            };

            handler
            .Setup(f => f.Send(It.IsAny <HttpRequestMessage>()))
            .Throws(new TaskCanceledException(Task.FromCanceled(new System.Threading.CancellationToken(true))));

            var httpClient = new HttpClient(handler.Object);

            var logger = new Mock <ILogger>();

            logger.Setup(l => l.Error(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable();

            var filename         = @"http://example.com/my_imaginary_file.tif";
            var defaultTileWidth = 512;

            try
            {
                TiffExpander.GetMetadata(httpClient, logger.Object, new Uri(filename), defaultTileWidth, string.Empty);
            }
            catch (AggregateException ex)
            {
                logger.Verify(v => v.Error(It.IsAny <TaskCanceledException>(), "HTTP Request Cancelled"), Times.Once);
                throw ex.InnerException;
            }
        }
        public void Metadata()
        {
            var filename         = Path.GetFullPath(@"test_image.tif");
            var defaultTileWidth = 512;
            var expectedWidth    = 1000;
            var expectedHeight   = 1000;

            var result = TiffExpander.GetMetadata(null, Log, new Uri(filename), defaultTileWidth, string.Empty);

            Assert.IsNotNull(result);
            Assert.AreEqual(defaultTileWidth, result.TileWidth, "Returned TileWidth does not match expected value");
            Assert.AreEqual(0, result.TileHeight, "TileHeight should not be set");
            Assert.AreEqual(expectedWidth, result.Width, "Expected Width does not match returned value");
            Assert.AreEqual(expectedHeight, result.Height, "Expected Height does not match returned value");
            Assert.AreEqual(6, result.ScalingLevels, "Returned ScalingLevels does not match expected value");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Get Metadata fromt he source image, for info.json requests
        /// </summary>
        /// <param name="imageUri">The <see cref="Uri"/> of the source image</param>
        /// <param name="defaultTileWidth">The default tile width (pixels) if the source image is not natively tiled</param>
        /// <param name="requestId">The correlation ID to include on any subsequent HTTP requests</param>
        /// <returns></returns>
        public async Task <Metadata> GetMetadata(Uri imageUri, int defaultTileWidth, string requestId)
        {
            var sourceFormat = await Task.Run(() => GetSourceFormat(imageUri, requestId));

            switch (sourceFormat)
            {
            case ImageFormat.jp2:
                return(J2KExpander.GetMetadata(HttpClient, Log, imageUri, defaultTileWidth, requestId));

            case ImageFormat.tif:
                return(TiffExpander.GetMetadata(HttpClient, Log, imageUri, defaultTileWidth, requestId));

            default:
                throw new IOException("Unsupported source format");
            }
        }