public void CanASpecificationDetermineNotSatisfied() { var testSubject = new StringTestSubject(); var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)); Assert.IsFalse(spec.IsSatisfiedBy(testSubject)); }
public void CanAValidationRuleBeCreatedViaLambdaWithMessageLambda() { var testSubject = new StringTestSubject(); var rule = new ValidationRule <StringTestSubject>(x => !String.IsNullOrEmpty(x.TestString1), "Rule", x => String.Format("Entity of type {0} first name is null.", x.GetType().Name)); var valid = rule.Validate(testSubject); Assert.AreEqual("Entity of type StringTestSubject first name is null.", rule.ErrorMessage); }
public void CanSpecificationBeNOTedByOperator() { var testSubject = new StringTestSubject { TestString1 = "Bob" }; var spec = !(new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1))); Assert.IsFalse(spec.IsSatisfiedBy(testSubject)); }
public void CanASpecificationDetermineSatisfaction() { var testSubject = new StringTestSubject { TestString1 = "Bob" }; var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)); Assert.IsTrue(spec.IsSatisfiedBy(testSubject)); }
public void InvalidEntityValidatesBySpecificationAsInvalid() { var ruleSet = new StringTestSubjectRules(); ruleSet.AddRule(x => !String.IsNullOrEmpty(x.TestString1), "TestString1Required."); var testSubject = new StringTestSubject(); var result = ruleSet.Validate(testSubject); Assert.IsFalse(result.Valid); }
public void ValidEntityValidatesBySpecificationAsValid() { var ruleSet = new StringTestSubjectRules(); var testSubject = new StringTestSubject { TestString1 = "Bob" }; var result = ruleSet.Validate(testSubject); Assert.IsTrue(result.Valid); }
public void CanValidateEntitySpecifications() { var ruleSet = new StringTestSubjectRules(); var testSubject = new StringTestSubject { TestString1 = "Bob" }; var result = ruleSet.Validate(testSubject); Assert.IsNotNull(result); }
public void ValidationResultContainsPointerToEntityThatFailedValidation() { var ruleSet = new StringTestSubjectRules(); ruleSet.AddRule(x => !String.IsNullOrEmpty(x.TestString1), "TestString1Required."); var testSubject = new StringTestSubject { TestString1 = "Bob" }; var result = ruleSet.Validate(testSubject); Assert.AreEqual(testSubject, result.Entity); }
public void ValidatedEntityReportsErrors() { var ruleSet = new StringTestSubjectRules(); ruleSet.AddRule(x => !String.IsNullOrEmpty(x.TestString2), "TestString2Required."); var testSubject = new StringTestSubject { TestString1 = "Bob" }; ruleSet.Validate(testSubject); Assert.AreEqual(1, testSubject.ValidationErrors.Count); }
public void ValidatedEntityCanGetErrorsReported() { var ruleSet = new StringTestSubjectRules(); ruleSet.AddRule(x => !String.IsNullOrEmpty(x.TestString1), "TestString1Required."); var testSubject = new StringTestSubject { TestString1 = "Bob" }; ruleSet.Validate(testSubject); Assert.IsNotNull(testSubject.ValidationErrors); }
public void CanSpecificationsBeANDedTogether() { var testSubject = new StringTestSubject { TestString1 = "Bob" }; var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)).And( new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString2))); Assert.IsFalse(spec.IsSatisfiedBy(testSubject)); testSubject.TestString2 = "Smith"; Assert.IsTrue(spec.IsSatisfiedBy(testSubject)); }
public void CanSpecificationBeORedByOperator() { var testSubject = new StringTestSubject(); var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)) | new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString2)); Assert.IsFalse(spec.IsSatisfiedBy(testSubject)); testSubject.TestString2 = "Smith"; Assert.IsTrue(spec.IsSatisfiedBy(testSubject)); testSubject.TestString1 = "Bob"; testSubject.TestString2 = null; Assert.IsTrue(spec.IsSatisfiedBy(testSubject)); }
public void DoesInvalidationSetDefaultErrorMessage() { var testSubject = new StringTestSubject { TestString1 = "Bob" }; var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)); spec &= new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString2)); var rule = new ValidationRule <StringTestSubject>(spec, "FullNameRequired"); var result = rule.Validate(testSubject); Assert.IsNotNullOrEmpty(rule.ErrorMessage); }
public void CanAnEntityBeInvalidated() { var testSubject = new StringTestSubject { TestString1 = "Bob" }; var spec = new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString1)); spec &= new Specification <StringTestSubject>(p => !String.IsNullOrEmpty(p.TestString2)); var rule = new ValidationRule <StringTestSubject>(spec, "FullNameRequired"); var result = rule.Validate(testSubject); Assert.IsFalse(result); }