0

I have a unit test that I pass RootContextData, i.e.

var context = new ValidationContext<Person>(person);
context.RootContextData["MyCustomData"] = "Test";
var validator = new PersonValidator();
validator.Validate(context);

When unit testing that validator I need to pass the RootContextData but I don't see any way to do that.
.TestValidate() method does not have an overload that takes a context.

var result = validator.TestValidate(objectToTest);

Is there a way to set RootContextData for the validator before running a unit test?

1 Answer 1

0

From ValidatorTestExtensions.TestValidate function, you can pass the ValidationContext instance as the argument.

var result = validator.TestValidate(context);

Demo @ .NET Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

I see the issue. I'm actually working with .NET 4 with and old version of FluentValidator. The old version doesn't have a TestValidate method that takes a context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.