예제 #1
0
        public async Task LoadNativeThumbnailAsync_ReturnExceptionsThrownByFileSystem()
        {
            var entity = new FileEntity("test");

            _fileSystem
            .Setup(mock => mock.ReadAllBytes(entity.Path))
            .Throws(new Exception("IO exception"));

            var exception = "";

            try
            {
                var image = await _loader.LoadNativeThumbnailAsync(entity, new Size(1, 1), CancellationToken.None);
            }
            catch (Exception e)
            {
                exception = e.Message;
            }

            Assert.AreEqual("IO exception", exception);
            Assert.IsNull(entity.GetValue <ImageValue>(ExifAttributeReaderFactory.Thumbnail));
        }
예제 #2
0
        public async Task LoadNativeThumbnailAsync_DisposeIntermediateResults()
        {
            var originalImage  = new BitmapMock();
            var thumbnailImage = new BitmapMock();
            var entity         = new FileEntity("test");

            _fileSystem
            .Setup(mock => mock.ReadAllBytes(entity.Path))
            .Returns(new byte[] { 0x42 });
            _imageLoader
            .Setup(mock => mock.LoadImage(entity, It.Is <Stream>(stream => stream.ReadByte() == 0x42 && stream.ReadByte() < 0)))
            .Returns(originalImage);
            _thumbnailGenerator
            .Setup(mock => mock.GetThumbnail(originalImage, new Size(1, 1)))
            .Returns(thumbnailImage);

            Assert.IsFalse(originalImage.IsDisposed);
            Assert.IsFalse(thumbnailImage.IsDisposed);
            var image = await _loader.LoadNativeThumbnailAsync(entity, new Size(1, 1), CancellationToken.None);

            Assert.IsNotNull(entity.GetValue <ImageValue>(ExifAttributeReaderFactory.Thumbnail));
            Assert.IsTrue(originalImage.IsDisposed);
            Assert.IsTrue(thumbnailImage.IsDisposed);
        }