Example #1
0
        public void IsValid_InvalidObjectarameter_ThrowsArgumentNullExceptionException()
        {
            var subject = new MaxFileSizeAttribute(5 * 1024 * 1024);
            var ex      = Assert.Throws <ArgumentException>(() => subject.IsValid(new object()));

            Assert.That(ex.Message, Is.EqualTo("Invalid argument type, expected type : IFormFile (Parameter 'value')"));
        }
Example #2
0
        public void MaxFileSizeAttributeShouldReturnFalseIfTheFileIsBiggerThanMaxFileSize()
        {
            var       attribute = new MaxFileSizeAttribute(500);
            IFormFile fileJpg   = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("dummy image")), 0, 1024, "Data", "fake.jpg");

            var actualResult = attribute.IsValid(fileJpg);

            Assert.False(actualResult);
        }
Example #3
0
        public void MaxFileSizeAttributeShouldReturnTrueIfTheFileIsSamllerThanMaxFileSize()
        {
            var       attribute = new MaxFileSizeAttribute(5 * 1024 * 1024);
            IFormFile file      = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("dummy image")), 0, 10, "Data", "fake.jpg");

            var actualResult = attribute.IsValid(file);

            Assert.True(actualResult);
        }
        public void IsValid_ValidatesCorrectly_WhenSizeIsBiggerThenMax(int maxSize)
        {
            var       allowedExtensionsAttribute = new MaxFileSizeAttribute(maxSize);
            IFormFile file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("Test file")), 0, 10, "Data", "testfile.xls");

            var result = allowedExtensionsAttribute.IsValid(file);

            Assert.False(result);
        }
Example #5
0
        public void IsValid_IncorrectSmallFile_ReturnTure()
        {
            // arrange
            Mock <IFormFile> fileMock = new Mock <IFormFile>();

            fileMock.Setup(f => f.Length).Returns(4 * 1024 * 1024);
            var subject = new MaxFileSizeAttribute(5 * 1024 * 1024);

            // act
            var result = subject.IsValid(fileMock.Object);

            // assert
            Assert.That(result, Is.True);
        }
Example #6
0
 public void validate_should_return_false_if_file_is_null()
 {
     _validate.IsValid(null).Should().BeFalse();
 }