Example #1
0
        public void CorrectlyTransformsWithDifferentOptions(IOptions <ShopManagerOptions> optionsAccessor)
        {
            //arrange
            var imageTransformer = new ShopImageTransformer(optionsAccessor);
            var imgOptions       = optionsAccessor.Value.Image;
            var image            = new Image()
            {
                BinData = new ImageBinData()
                {
                    FullData  = TestFactory.GenerateValidImageBytes(100, 100, ImageFormat.Png),
                    ThumbData = TestFactory.GenerateValidImageBytes(100, 100, ImageFormat.Png),
                }
            };

            //act
            imageTransformer.ProcessImage(image);
            var fullImg  = ByteArrayToImage(image.BinData.FullData);
            var thumbImg = ByteArrayToImage(image.BinData.ThumbData);


            Assert.True(fullImg.Width <= imgOptions.MaxWidth &&
                        fullImg.Height <= imgOptions.MaxHeight &&
                        fullImg.RawFormat.Equals(imgOptions.SaveFormat));
            Assert.True(thumbImg.Width <= imgOptions.MaxThumbWidth &&
                        thumbImg.Height <= imgOptions.MaxThumbHeight &&
                        thumbImg.RawFormat.Equals(imgOptions.SaveFormat));
        }
Example #2
0
        public void CorrectlyTransformsWithDifferentImages(Image image)
        {
            //arrange
            IOptions <ShopManagerOptions> optionsAccessor = new OptionAccessor1();
            var imageTransformer = new ShopImageTransformer(optionsAccessor);
            var imgOptions       = optionsAccessor.Value.Image;

            //act
            imageTransformer.ProcessImage(image);
            var fullImg  = ByteArrayToImage(image.BinData.FullData);
            var thumbImg = ByteArrayToImage(image.BinData.ThumbData);


            Assert.True(fullImg.Width <= imgOptions.MaxWidth &&
                        fullImg.Height <= imgOptions.MaxHeight &&
                        fullImg.RawFormat.Equals(imgOptions.SaveFormat));
            Assert.True(thumbImg.Width <= imgOptions.MaxThumbWidth &&
                        thumbImg.Height <= imgOptions.MaxThumbHeight &&
                        thumbImg.RawFormat.Equals(imgOptions.SaveFormat));
        }
Example #3
0
        public void DoesntTransformImageThatSatisfiesOptions()
        {
            //arrange
            IOptions <ShopManagerOptions> optionsAccessor = new OptionAccessor200x200x100x100xJpg();
            var imageTransformer = new ShopImageTransformer(optionsAccessor);
            var imgOptions       = optionsAccessor.Value.Image;

            var fullData  = TestFactory.GenerateValidImageBytes(100, 100, ImageFormat.Jpeg);
            var thumbData = TestFactory.GenerateValidImageBytes(100, 100, ImageFormat.Jpeg);

            var image = new Image()
            {
                BinData = new ImageBinData()
                {
                    FullData  = fullData,
                    ThumbData = thumbData,
                }
            };

            //act
            imageTransformer.ProcessImage(image);

            Assert.True(image.BinData.FullData == fullData && image.BinData.ThumbData == thumbData);
        }