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); }
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); } }
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); }
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); }
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); } }