Beispiel #1
0
        public void ExpectNullReferenceException()
        {
            var customer = new Customer();
            customer.Employees = new List<Contact>();
            customer.Employees.Add(null);

            ValidationCatalog.Validate<CustomerExpectNullReferenceExceptionSpecification>(customer);
        }
 public void Validate_CustomerWithNullContact_WithNestedRequiredRegisteredTypes_IsInValid()
 {
     var customerWithMissingContact = new Customer {Name = "Customer"};
     ValidationNotification results = ValidationCatalog.Validate(customerWithMissingContact);
     Assert.That(results.Errors, Is.Not.Empty);
     //Check that null PrimaryContact only generates 1, error and the validator doesn't continue down the tree
     Assert.That(results.Errors.Count, Is.EqualTo(1));
 }
        public void Validate_CustomerWithInvalidContact_WithNestedRequiredRegisteredTypes_IsInValid()
        {
            var customerWithInvalidContact = new Customer();
            customerWithInvalidContact.PrimaryContact = new Contact {FirstName = "First"};
            customerWithInvalidContact.PrimaryContact.PrimaryAddress = new Address {Street = "123 Main Street"};

            ValidationNotification results = ValidationCatalog.Validate(customerWithInvalidContact);
            Assert.That(results.Errors, Is.Not.Empty);
            Assert.That(
                results.Errors.Select(e => e.Message.Contains("Primary Contact Last Name is required.")).Any(),
                Is.True);
        }
Beispiel #4
0
        public void ListNullReferenceException()
        {
            try
            {
                var customer = new Customer();
                customer.Employees = new List<Contact>();
                customer.Employees.Add(null);

                ValidationCatalog.Validate<CustomerNullReferenceSpecification>(customer);
            }
            catch (NullReferenceException exception)
            {
                Assert.IsTrue(exception.Message.Contains(typeof(Customer).FullName));
            }
        }
        public void ValidationNotification_WithAllWarnDeepTree_IsValid()
        {
            var customer = new SpecExpress.Test.Domain.Entities.Customer {
                PrimaryContact = new Contact()
            };

            var vn = Specification.Validate(
                spec =>
                spec.Check(c => customer.PrimaryContact)
                .Required()
                .Specification(contactSpec => contactSpec.Warn(c => c.FirstName).Required()));


            Assert.IsTrue(vn.Errors.Count == 1);
            Assert.That(vn.IsValid, Is.True);
        }
        public void Validate_ContextUsesDefinedSpecifications()
        {
            //Scan all
            ValidationCatalog.Scan(x => x.TheCallingAssembly());

            //Setup entity
            var customer = new Customer()
                               {
                                   Active = true,
                                   Employees = new List<Contact>() {new Contact() {Active = true}}
                               };

            //Validate
            var results = ValidationCatalog<DeleteValidationContext>.Validate(customer);

            Assert.That(results.Errors.First().Message, Is.EqualTo("Active must be false."));
            Assert.That(results.Errors[1].NestedValidationResults.First().Message, Is.EqualTo("Contact 1 in Employees is invalid."));
            Assert.That(results.Errors[1].NestedValidationResults.First().NestedValidationResults.First().Message, Is.EqualTo("Active must be false."));
        }
Beispiel #7
0
 public void ListNullReferenceException()
 {
     var customer = new Customer {Employees = new List<Contact> {null}};
     Specification.Assert(spec => spec.Check(c => customer.Employees).Optional().ForEachSpecification());
 }
Beispiel #8
0
 public void ExpectNullReferenceException()
 {
     var customer = new Customer {Employees = new List<Contact> {null}};
     Specification.Assert(spec => spec.Check(c => customer.Employees).Required().Expect(ThrowHereNullReferenceException, "object not valid"));
 }