public void File_RtfIdentifiedBlueword_Validates() { mockAdwService.Setup(m => m.GetRelatedCodes("OFTW", "UNA")).Returns(new List <RelatedCodeModel> { new RelatedCodeModel { Dominant = true, DominantCode = "DominantCode", SubordinateDescription = "asd", RelatedCode = "OFTW", SubordinateCode = "UNA" } }); mockAdwService.Setup(m => m.GetRelatedCodes("OFTW", "IDE")).Returns(new List <RelatedCodeModel> { new RelatedCodeModel { Dominant = true, DominantCode = "DominantCode", SubordinateDescription = "asdfooasd", RelatedCode = "OFTW", SubordinateCode = "IDE" } }); var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; mockFile.Setup(m => m.FileName).Returns("file.rtf"); mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF))); var sut = new FileAttribute(new[] { FileType.Rtf }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreEqual(ValidationResult.Success, valid); }
public void File_Rtf_Validates() { var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; mockFile.Setup(m => m.FileName).Returns("file.rtf"); mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF))); var sut = new FileAttribute(new[] { FileType.Rtf }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreEqual(ValidationResult.Success, valid); }
public void File_RtfWithDrawing_Fails() { var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; mockFile.Setup(m => m.FileName).Returns("file.rtf"); mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF_Drawing.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF_Drawing))); var sut = new FileAttribute(new[] { FileType.Rtf }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.IsNotNull(valid); Assert.AreEqual(string.Format(DataAnnotationsResources.FileAttribute_InvalidRtfImage, validationContext.DisplayName), valid.ErrorMessage); }
public void File_Png_Validates() { var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; var data = (byte[])new ImageConverter().ConvertTo(FileResources.PNG, typeof(byte[])); mockFile.Setup(m => m.FileName).Returns("file.png"); mockFile.Setup(m => m.ContentLength).Returns(data.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(data)); var sut = new FileAttribute(new[] { FileType.Png }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreEqual(ValidationResult.Success, valid); }
public void File_ExpectingRtfButGetGif_Fails() { var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; var data = (byte[])new ImageConverter().ConvertTo(FileResources.GIF, typeof(byte[])); mockFile.Setup(m => m.FileName).Returns("file.gif"); mockFile.Setup(m => m.ContentLength).Returns(data.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(data)); var sut = new FileAttribute(new[] { FileType.Rtf }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreNotEqual(ValidationResult.Success, valid); Assert.IsNotNull(valid); Assert.IsTrue(!string.IsNullOrEmpty(valid.ErrorMessage)); }
public void File_RtfBlueword_Fails() { mockAdwService.Setup(m => m.GetRelatedCodes("OFTW", "UNA")).Returns(new List <RelatedCodeModel> { new RelatedCodeModel { Dominant = true, DominantCode = "DominantCode", SubordinateDescription = "foo", RelatedCode = "OFTW", SubordinateCode = "UNA" } }); var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; mockFile.Setup(m => m.FileName).Returns("file.rtf"); mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF))); var sut = new FileAttribute(new[] { FileType.Rtf }); var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreEqual(string.Format(DataAnnotationsResources.BlueWordAttribute_InvalidWithBlueWords, validationContext.DisplayName, "foo"), valid.ErrorMessage); }
public void File_CompressedSizeFail_Fails() { var validationContext = new ValidationContext(this, null, null); validationContext.DisplayName = "File"; var data = (byte[])new ImageConverter().ConvertTo(FileResources.PNG, typeof(byte[])); mockFile.Setup(m => m.FileName).Returns("file.png"); mockFile.Setup(m => m.ContentLength).Returns(data.Length); mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(data)); var sut = new FileAttribute(new[] { FileType.Png }); var compressedData = mockFile.Object.GetBytes().Compress(); sut.CompressedSize = compressedData.Length - 1; var valid = sut.GetValidationResult(mockFile.Object, validationContext); Assert.AreNotEqual(ValidationResult.Success, valid); Assert.IsNotNull(valid); Assert.IsTrue(!string.IsNullOrEmpty(valid.ErrorMessage)); }