Пример #1
0
        public void Test_ImageValidator_Valid()
        {
            var file = MockRepository.GenerateMock<HttpPostedFileBase>();
            var image = MockRepository.GenerateMock<IImageService>();

            image.Stub(x => x.IsImage(file)).Return(true);

            var validator = new ImageValidator(image);
            var results = validator.Validate(new PropertyValidatorContext("test", file, file, "value"));

            Assert.IsEmpty(results.ToList());
        }
Пример #2
0
        public void Test_ImageDimensionMaxValidator_NotValid()
        {
            var file = MockRepository.GenerateMock<HttpPostedFileBase>();

            file.Stub(x => x.ContentType).Return("application/zip");

            var image = MockRepository.GenerateMock<IImageService>();

            image.Stub(x => x.IsImage(file)).Return(false);

            var validator = new ImageValidator(image);
            var results = validator.Validate(new PropertyValidatorContext("test", file, file, "value"));

            foreach (var result in results)
            {
                Assert.AreEqual(
                    Errors.ImageContentTypeNotValid.FormatInvariant(
                        file.ContentType,
                        Setting.ImageExtension.Value
                    ),
                    result.ErrorMessage
                );
            }
        }