lundi 27 avril 2020

How can I apply some generic fluent validation to check all API response?

I have some came across the fluent validation, and I am really liking it. I want to know how can create some generic rules so I can apply to all the API response I get. Instead of validating for the models I want to validate for the response the server gives back. How can I create some generic method to apply these rules.

I have also looked at this Generic Validator for Model T Using Fluent Validation? I am trying to achieve something similar.

public class Validator : AbstractValidator<> {

  public Validator()
    {
        //Get the response here from the server and validate against in the Test
        //Then use that method to apply to the API calls

        RuleFor(x => x.response).NotEmpty().
        RuleFor(x => x.response).NotNull();
}        RuleFor(x => x.response).Must<BeAValidGuid>();
   }

Aucun commentaire:

Enregistrer un commentaire