コード例 #1
0
        public async Task ReadImageSizeTest()
        {
            await using var fileStream = ImageTestsHelper.OpenFileForReading(Path.Combine(ImageTestsHelper.JpegImagesDirectory, "1043-1200x900.jpg"));
            var imageSize = _imageMetadataReader.ReadSize(fileStream);

            Assert.Equal(1200, imageSize.Width);
            Assert.Equal(900, imageSize.Height);
            Assert.Equal(265504, imageSize.Bytes);
        }
コード例 #2
0
        private async Task DetectionTest(string directory, ImageType expectedImageType)
        {
            foreach (var file in Directory.EnumerateFiles(directory))
            {
                await using var fileStream = ImageTestsHelper.OpenFileForReading(file);
                var imageFormat = _imageMetadataReader.DetectFormat(fileStream);

                Assert.Equal(expectedImageType, imageFormat.ImageType);
            }
        }
コード例 #3
0
        public async Task NotImageDetectionTest()
        {
            await using var fileStream = ImageTestsHelper.OpenFileForReading("textFile.txt");
            var imageFormat = _imageMetadataReader.DetectFormat(fileStream);

            Assert.Null(imageFormat);

            var imageSize = _imageMetadataReader.ReadSize(fileStream);

            Assert.Null(imageSize);
        }
コード例 #4
0
        public async Task UnsupportedImageFormatTest()
        {
            await using var fileStream = ImageTestsHelper.OpenFileForReading("Images\\556-200x300.webp");
            var imageFormat = _imageMetadataReader.DetectFormat(fileStream);

            Assert.Null(imageFormat);

            var imageSize = _imageMetadataReader.ReadSize(fileStream);

            Assert.Null(imageSize);
        }
コード例 #5
0
        private void ResizingTest(string directory)
        {
            var images = SelectImages(directory);

            var originalImageStream = ImageTestsHelper.OpenFileForReading(images[0].FilePath);

            for (int i = 1; i < images.Count; i++)
            {
                var imageResizingResult = _imageResizing.Resize(originalImageStream, ImageType.JPEG, images[i].Width);
                Assert.Equal(images[i].Height, imageResizingResult.Size.Height);
            }
        }