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')")); }
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); }
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); }
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); }
public void validate_should_return_false_if_file_is_null() { _validate.IsValid(null).Should().BeFalse(); }