public async void GenerateThumbnailsAsync_FixedWidth_FFixedWidthCalled()
        {
            var options = new List <ThumbnailOption>()
            {
                new ThumbnailOption()
                {
                    ResizeMethod = ResizeMethod.FixedWidth,
                    FileSuffix   = "test",
                }
            };

            var image = new Bitmap(50, 50);

            var mockStorage = new Mock <IImageService>();

            mockStorage.Setup(x => x.LoadImageAsync(It.IsAny <string>())).Returns(Task.FromResult <Image>(image));

            var mockResizer = new Mock <IImageResizer>();

            mockResizer.Setup(x => x.FixedWidth(It.IsAny <Image>(), It.IsAny <int>(), It.IsAny <Color>())).Returns(image);

            var target = new DefaultThumbnailGenerator(mockStorage.Object, mockResizer.Object);
            var result = await target.GenerateThumbnailsAsync("http://pathToFile.bmp", "dest", options, null);

            mockResizer.Verify(x => x.FixedWidth(It.IsAny <Image>(), It.IsAny <int>(), It.IsAny <Color>()));
        }
예제 #2
0
        public async void GenerateThumbnailsAsync_Crop_CropCalled()
        {
            var options = new List <ThumbnailOption>
            {
                new ThumbnailOption
                {
                    ResizeMethod = ResizeMethod.Crop,
                    FileSuffix   = "test",
                    Width        = 10,
                    Height       = 20
                }
            };

            var          image = new Image <Rgba32>(50, 50);
            IImageFormat format;

            var mockStorage = new Mock <IImageService>();

            mockStorage.Setup(x => x.LoadImageAsync(It.IsAny <string>(), out format)).Returns(Task.FromResult(image));

            var mockResizer = new Mock <IImageResizer>();

            mockResizer.Setup(x => x.Crop(It.IsAny <Image <Rgba32> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <AnchorPosition>())).Returns(image);

            var target = new DefaultThumbnailGenerator(mockStorage.Object, mockResizer.Object);
            var result = await target.GenerateThumbnailsAsync("http://pathToFile.bmp", "dest", options, null);

            mockResizer.Verify(x => x.Crop(It.IsAny <Image <Rgba32> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <AnchorPosition>()));
        }
        public async void GenerateThumbnailsAsync_CancellationTokenNotNull_CancellationFired()
        {
            var options             = new List <ThumbnailOption>();
            CancellationToken token = new CancellationToken(true);
            var tokenWrapper        = new CancellationTokenWrapper(token);

            var mockStorage = new Mock <IImageService>();
            var mockResizer = new Mock <IImageResizer>();

            var target = new DefaultThumbnailGenerator(mockStorage.Object, mockResizer.Object);
            await Assert.ThrowsAsync <OperationCanceledException>(async() => await target.GenerateThumbnailsAsync("http://pathToFile.bmp", "dest", options, tokenWrapper));
        }