示例#1
0
        public void ValidOriginalSize(int width, int height, int minWidth, int minHeight, int maxWidth, int maxHeight)
        {
            var image = CreateImage(width, height, new PngEncoder());
            const FileFormat PngFormat = FileFormat.Png;
            var constraints            = CreateConstraints(minWidth, minHeight, maxWidth, maxHeight, PngFormat);

            BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, PngFormat, image);
        }
示例#2
0
        public void ValidOriginalFormat(FileFormat format)
        {
            var encoder     = GetEncoder(format);
            var image       = CreateImage(5, 5, encoder);
            var constraints = CreateConstraints(1, 1, 10, 10, format);

            BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, format, image);
        }
示例#3
0
        private static void EnsureFileHeaderIsValid(
            int templateCode,
            ElementDescriptorType elementDescriptorType,
            IElementConstraints elementConstraints,
            Stream inputStream,
            IUploadedFileMetadata uploadedFileMetadata)
        {
            var fileFormat = DetectFileFormat(uploadedFileMetadata.FileName);

            switch (elementDescriptorType)
            {
            case ElementDescriptorType.BitmapImage:
                BitmapImageValidator.ValidateBitmapImageHeader(templateCode, (BitmapImageElementConstraints)elementConstraints, fileFormat, inputStream);
                break;

            case ElementDescriptorType.CompositeBitmapImage:
                if (uploadedFileMetadata.FileType == FileType.SizeSpecificBitmapImage)
                {
                    var imageMetadata = (UploadedImageMetadata)uploadedFileMetadata;
                    BitmapImageValidator.ValidateSizeSpecificBitmapImageHeader(
                        templateCode,
                        (CompositeBitmapImageElementConstraints)elementConstraints,
                        fileFormat,
                        inputStream,
                        imageMetadata.Size);
                }
                else
                {
                    BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(
                        templateCode,
                        (CompositeBitmapImageElementConstraints)elementConstraints,
                        fileFormat,
                        inputStream);
                }

                break;

            case ElementDescriptorType.VectorImage:
                VectorImageValidator.ValidateVectorImageHeader(templateCode, fileFormat, inputStream);
                break;

            case ElementDescriptorType.Article:
                break;

            case ElementDescriptorType.PlainText:
            case ElementDescriptorType.FormattedText:
            case ElementDescriptorType.FasComment:
            case ElementDescriptorType.Link:
            case ElementDescriptorType.Phone:
            case ElementDescriptorType.VideoLink:
            case ElementDescriptorType.Color:
                throw new NotSupportedException($"Not binary element descriptor type {elementDescriptorType}");

            default:
                throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type");
            }
        }
示例#4
0
        public void InvalidOriginalSize(int width, int height, int minWidth, int minHeight, int maxWidth, int maxHeight)
        {
            var image = CreateImage(width, height, new GifEncoder());
            const FileFormat GifFormat = FileFormat.Gif;
            var constraints            = CreateConstraints(minWidth, minHeight, maxWidth, maxHeight, GifFormat);

            var ex = Assert.Throws <InvalidBinaryException>(() => BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, GifFormat, image));

            Assert.IsType <ImageSizeOutOfRangeError>(ex.Error);
        }
示例#5
0
        public void InvalidOriginalFormat(FileFormat expectedFormat, FileFormat actualFormat)
        {
            var encoder     = GetEncoder(actualFormat);
            var image       = CreateImage(5, 5, encoder);
            var constraints = CreateConstraints(1, 1, 10, 10, expectedFormat);

            var ex = Assert.Throws <InvalidBinaryException>(() => BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, actualFormat, image));

            Assert.IsType <BinaryInvalidFormatError>(ex.Error);
        }