public void IsNotValidWhenNull_Null_False() { var validator = Bouncer.For <Person>(model => model.BlockNull()); var person = default(Person); Assert.IsFalse(validator.Validate(person).Success); }
public void ThrowOrDefault_InvalidPerson_PersonValidationException() { var validator = Bouncer.For <Person>(model => model.Block(p => p.FirstName == null)); var person = new Person(); Assert.That.Throws <DynamicException>(() => validator.Validate(person).ThrowIfInvalid(), filter => filter.When(name: "PersonValidationException")); }
public void IsNotValidWhenNull_NotNull_True() { var validator = Bouncer.For <Person>(model => model.BlockNull()); var person = new Person(); Assert.IsTrue(validator.Validate(person).Success); }
public void IsValidWhenNull_NotNull_False() { var validator = Bouncer.For <Person>(model => model.EnsureNull()); var person = new Person(); Assert.IsFalse(validator.Validate(person).Success); }
public void IsValidWhenNull_Null_True() { var validator = Bouncer.For <Person>(model => model.EnsureNull()); var person = default(Person); Assert.IsTrue(validator.Validate(person).Success); }
public void CanEnsureMultipleRules() { var validator = Bouncer.For <Person>(builder => { builder.Ensure(p => p.FirstName != null); builder.Ensure(p => p.LastName != null); }); var person = new Person { FirstName = "John", LastName = "Doe" }; Assert.IsTrue(validator.Validate(person).Success); }
public void CanBlockMultipleRules() { var validator = Bouncer.For <Person>(builder => { builder.Block(p => p.FirstName == null); builder.Block(p => p.LastName == null); }); var person = new Person(); var weelidationResult = validator.Validate(person); Assert.AreEqual(1, weelidationResult.Count); Assert.AreEqual(2, weelidationResult.False.Count()); Assert.IsFalse(weelidationResult.Success); }