public void ViewModelBaseNoErrorsTest() { var personViewModel = new PersonViewModel { PersonFirstName = "Igr Alexánder", PersonLastName = "Fernández Saúco" }; personViewModel.Validate(); IValidationSummary validationSummary = personViewModel.ValidationContext.GetValidationSummary("Person"); Assert.IsFalse(validationSummary.HasErrors); Assert.IsFalse(validationSummary.HasWarnings); }
public void ViewModelBaseWithFieldErrorsAndBusinessRuleWarningsValidationTest() { var personViewModel = new PersonViewModel(); personViewModel.Validate(); IValidationSummary validationSummary = personViewModel.ValidationContext.GetValidationSummary("Person"); Assert.IsTrue(validationSummary.HasErrors); Assert.IsTrue(validationSummary.HasFieldErrors); Assert.AreEqual(2, validationSummary.FieldErrors.Count); Assert.IsTrue(validationSummary.FieldErrors[0].Message.Contains("First name")); Assert.IsTrue(validationSummary.FieldErrors[1].Message.Contains("Last name")); Assert.IsTrue(validationSummary.HasWarnings); Assert.IsTrue(validationSummary.HasBusinessRuleWarnings); Assert.AreEqual(2, validationSummary.BusinessWarnings.Count); Assert.IsTrue(validationSummary.BusinessWarnings[0].Message.Contains("First name")); Assert.IsTrue(validationSummary.BusinessWarnings[1].Message.Contains("Last name")); }