public void OnValidationEqualValues_ShouldNotThrowException() { _testingObject.AddValidation(dto => dto.I, _someDto.I); _testingObject.AddValidation(dto => dto.S, _someDto.S); _testingObject.AddValidation(dto => dto.Dt, _someDto.Dt); _testingObject.RunValidation(); }
public void OnMissingPropertyValidation_ShouldThrowPropertiesNotValidatedException() { _testingObject.AddValidation(dto => dto.I, 0); var success = false; try { _testingObject.RunValidation(); } catch (PropertiesNotValidatedException) { success = true; } Assert.IsTrue(success); }
static void PerformValidation() { var dtoValidator = new DtoValidator <DtoCustomer>(_dtoPerson); dtoValidator.AddValidation(dto => dto.address_city, _address.City); dtoValidator.AddValidation(dto => dto.address_complement, _address.Complement); dtoValidator.AddValidation(dto => dto.address_numberm, _address.Number); dtoValidator.AddValidation(dto => dto.address_street, _address.Street); dtoValidator.AddValidation(dto => dto.birthday, _person.Birthday); dtoValidator.AddValidation(dto => dto.name, _person.Name); dtoValidator.IgnoreValidation(dto => dto.is_famous); dtoValidator.AddValidation(dto => dto.contacts, ValidateContacts); dtoValidator.RunValidation(); }
static bool ValidateContacts(DtoContact[] contacts) { for (int i = 0; i < contacts.Length; i++) { try { var dtoValidation = new DtoValidator <DtoContact>(contacts[i]); dtoValidation.AddValidation(c => c.number, contacts[i].number); dtoValidation.AddValidation(c => c.type, contacts[i].type); dtoValidation.RunValidation(); } catch (GenericDtoValidationException) { return(false); } } return(true); }