I have the following method which uses FluentValidation to validate a ConnectionModel
:
internal static bool Validate(ConnectionModel connectionModel)
{
var validator = new ConnectionModelValidator();
var result = validator.Validate(connectionModel);
if (result.IsValid) return true;
foreach (var failure in result.Errors)
throw new ArgumentNullException(failure.ErrorMessage);
return false;
}
How can I unit test, using XUnit, the following bits which should throw ArgumentNullException for each validation error:
foreach (var failure in result.Errors)
throw new ArgumentNullException(failure.ErrorMessage);
return false;
Here is what I tried so far:
public void Validate_ShouldThrowArgumentNullExceptionIfConnectionModelHasEmptyProperty()
{
var connectionModel = new ConnectionModel
{
JumpHostname = "10.1.1.1",
JumpUsername = "test",
SaaHostname = "test",
SaaPassword = "test",
SaaUsername = "test",
SidePassword = "test",
SideServiceName = "test",
};
var validator = new ConnectionModelValidator();
var result = validator.Validate(connectionModel);
Assert.NotEmpty(result.Errors);
}
but this scenario only covers Errors not being empty.