コード例 #1
0
        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();
        }
コード例 #2
0
        public void OnMissingPropertyValidation_ShouldThrowPropertiesNotValidatedException()
        {
            _testingObject.AddValidation(dto => dto.I, 0);

            var success = false;

            try
            {
                _testingObject.RunValidation();
            }
            catch (PropertiesNotValidatedException)
            {
                success = true;
            }

            Assert.IsTrue(success);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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);
        }