partial void Name_Validate(EntityValidationResultsBuilder results) { /* * This is where the business logic would have gone * Compare this code to the code in CustomerValidationController.ValidateCustomer * * if (Name != null) * { * if (Name.Length < 3) * results.AddPropertyError("Names cannot be less than 3 characters"); * * var reg = Regex.Match(Name, @"[0-9]"); * if (reg.Success) * results.AddPropertyError("Names cannot contain numbers"); * } */ var controller = new CustomerValidationController(this); IEnumerable <string> errorMessages; if (!controller.ValidateCustomer(out errorMessages)) { foreach (var error in errorMessages) { results.AddPropertyError(error); } } }
public void Given_a_name_is_3_or_more_chars_and_does_not_contain_numbers_then_a_customer_can_be_created() { // arrange var mock = new Mock <ICustomer>(); mock.SetupGet(c => c.Name).Returns("Max"); var target = new CustomerValidationController(mock.Object); IEnumerable <string> errorMessages; // act var result = target.ValidateCustomer(out errorMessages); // assert Assert.IsTrue(result); }