public void Validate_Text_With_Invalid_ContentType_Failure() { const string value = "MimeTypesConstants.Application.AtomcatXml"; var path = Path.Combine(Environment.CurrentDirectory, "TestData/TestFile.docx"); using var stream = File.OpenRead(path); var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) { Headers = new HeaderDictionary(), ContentType = value }; var wordCountSearchParameter = new WordCountSearchParameter { File = file }; wordCountSearchParameter.Invoking(x => x.Validate()).Should().Throw <ValidationException>().WithMessage( ExceptionMessages.AllowedInputContentTypes(value, WordCountSearchParameter.AllowedContextTypes)); }
public void Validate() { if (File == null) { throw new ValidationException(ExceptionMessages.InvalidInput(nameof(File))); } var contentType = File.ContentType; if (contentType.HasValue() && !AllowedContextTypes.Contains(contentType)) { throw new ValidationException(ExceptionMessages.AllowedInputContentTypes(contentType, AllowedContextTypes)); } Text = ReadFileStream(); if (!Text.HasValue()) { throw new ValidationException(ExceptionMessages.InvalidInput(nameof(Text))); } }