private static async Task <ImageData> RunFileTestAsync(string imageFileName, bool deleteFile, bool runTest) { if (imageFileName is null) { throw new ArgumentNullException(nameof(imageFileName)); } if (imageFileName.Length == 0) { throw new ArgumentException("path must not be empty string", nameof(imageFileName)); } var myPictures = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); var cacheFileName = Path.Combine(myPictures, imageFileName); var cacheFile = new FileInfo(cacheFileName); if (deleteFile && cacheFile.Exists) { cacheFile.Delete(); } var cache = new CachingStrategy { new FileCacheLayer(cacheFile.Directory) }; var imageRequest = new ImageRequest( new Uri("https://www.seanmcbeth.com"), "2015-05.min.jpg"); var imageDecoder = new TranscoderCodec <BitMiracle.LibJpeg.JpegImage, ImageData>( new LibJpegNETCodec(80), new LibJpegNETImageDataTranscoder()); var actual = await cache .LoadAsync(imageDecoder, imageRequest) .ConfigureAwait(false); if (runTest) { var path = Path.Combine(myPictures, "portrait-expected.jpg"); using var stream = FileDataSource.Instance.GetStream(path); var expected = imageDecoder.Deserialize(stream); var expectedData = expected.GetData(); var actualData = actual.GetData(); Assert.AreEqual(expected.Info.Dimensions.Width, actual.Info.Dimensions.Width); Assert.AreEqual(expected.Info.Dimensions.Height, actual.Info.Dimensions.Height); Assert.AreEqual(expectedData.Length, actualData.Length); for (var i = 0; i < expectedData.Length; ++i) { Assert.AreEqual(expectedData[i], actualData[i]); } } return(actual); }
public async Task GetImageAsync() { var search = new TileRequest(apiKey, signingKey, new Size(640, 640)) { Zoom = 20, Address = "4909 Rutland Pl, Alexandria, VA, 22304" }; var decoder = new TranscoderCodec <Hjg.Pngcs.ImageLines, ImageData>( new HjgPngcsCodec(), new HjgPngcsImageDataTranscoder()); var results = await cache .LoadAsync(decoder, search) .ConfigureAwait(false); Assert.IsNotNull(results); Assert.AreEqual(640, results.Info.Dimensions.Width); Assert.AreEqual(640, results.Info.Dimensions.Height); }