public RuleValidatorContext<Contact, bool> BuildContextForContactActive(bool value)
        {
            var contact = new Contact { Active = value };
            var context = new RuleValidatorContext<Contact, bool>(contact, "Active", contact.Active, null, ValidationLevelType.Error, null);

            return context;
        }
        public RuleValidatorContext <Contact, bool> BuildContextForContactActive(bool value)
        {
            var contact = new Contact {
                Active = value
            };
            var context = new RuleValidatorContext <Contact, bool>(contact, "Active", contact.Active, null, ValidationLevelType.Error, null);

            return(context);
        }
        public void GetAllValidationResults()
        {
            var contact = new SpecExpress.Test.Domain.Entities.Contact()
            {
                Addresses = new List <Address>()
                {
                    new Address()
                    {
                        City = "Gatlinburg"
                    }
                }
                ,
                PrimaryAddress = new Address()
                {
                }
            };

            var results = ValidationCatalog.Validate <SpecExpress.Test.Domain.Specifications.ContactSpecification>(contact);

            CollectionAssert.IsNotEmpty(results.All());

            Assert.That(results.IsValid, Is.False);
        }
Esempio n. 4
0
        public void When_multiple_specifications_defined_with_default_spec_defined_return_default()
        {
            Assembly assembly = Assembly.LoadFrom("SpecExpress.Test.Domain.dll");

            ValidationCatalog.Scan(x => x.AddAssembly(assembly));

            //Add Default specification with optional last name
            ValidationCatalog.AddSpecification <SpecExpress.Test.Domain.Entities.Contact>(spec =>
            {
                spec.IsDefaultForType();
                spec.Check(c => c.LastName).Optional();
            });

            //Add Secondary specification with required last name
            ValidationCatalog.AddSpecification <SpecExpress.Test.Domain.Entities.Contact>(spec => spec.Check(c => c.LastName).Required());

            //Create valid object, with null Last Name
            var contact = new SpecExpress.Test.Domain.Entities.Contact();

            var vn = ValidationCatalog.Validate(contact);

            Assert.That(vn.IsValid, Is.True);
        }
        public void GetAllValidationResults()
        {
            var contact = new SpecExpress.Test.Domain.Entities.Contact()
                               {
                                   Addresses = new List<Address>()
                                                   {
                                                       new Address()
                                                           {
                                                               City = "Gatlinburg"
                                                           }
                                                   }
                                   ,
                                   PrimaryAddress = new Address()
                                                        {

                                                        }
                               };

            var results = ValidationCatalog.Validate<SpecExpress.Test.Domain.Specifications.ContactSpecification>(contact);

            CollectionAssert.IsNotEmpty(results.All());

            Assert.That(results.IsValid, Is.False);
        }
        public void When_multiple_specifications_defined_with_default_spec_defined_return_default()
        {
            Assembly assembly = Assembly.LoadFrom("SpecExpress.Test.Domain.dll");
            ValidationCatalog.Scan(x => x.AddAssembly(assembly));

            //Add Default specification with optional last name
            ValidationCatalog.AddSpecification<SpecExpress.Test.Domain.Entities.Contact>(spec =>
            {
                spec.IsDefaultForType();
                spec.Check(c => c.LastName).Optional();
            });

            //Add Secondary specification with required last name
            ValidationCatalog.AddSpecification<SpecExpress.Test.Domain.Entities.Contact>(spec => spec.Check(c => c.LastName).Required());

            //Create valid object, with null Last Name
            var contact = new SpecExpress.Test.Domain.Entities.Contact();

            var vn = ValidationCatalog.Validate(contact);

            Assert.That(vn.IsValid, Is.True);
        }