I have a big form like a few hundreds controls. All those controls spread between popups, collection of items in list view and so on but basically it is one entity that is going to be saved to the database and then send to the external service.
I have to validate this form and it has a lot of rules. Probably hundreds.
Besides the process of validation I would like to make user's life easier and show validation messages and some suggestions about how to fill the form.
How can I organize the code?
Obviously, if I'm going to do it in one method or group of methods and directly interact with UI it might become a mess very soon.
My current idea is do define validation rule class and contract.
Something like this:
public abstract class ValidationRuleBase
{
public ValidationRuleBase()
{
}
public abstract IEnumerable<IUIAction> ValidateForm(IEnumerable<FormControl> controls)
}
public interface IUIAction
{
FormControl Control { get; set; }
string ErrorMessage { get; set; }
string WarningMessage { get; set; }
string AdviceMessage { get; set; }
}
public class FormControl
{
public string Name { get; set; }
public string Value { get; set; }
}
Validation rule class might contain meta information, references to documentation and so on. So we can write tests for those rules, probably make automatic extraction and generate actual documentation for testers.
I guess I just reinventing the wheel and it should be done many times.
Aucun commentaire:
Enregistrer un commentaire