public async Task Transforms_property_value_with_propagated_original_object_async() { var validator = new InlineValidator <Person>(); validator.Transform(x => x.Forename, (person, forename) => new { Nicks = person.NickNames, Name = forename }) .Must(context => context.Nicks.Any(nick => nick == context.Name.ToLower())); var result = await validator.ValidateAsync(new Person { NickNames = new[] { "good11", "peter" }, Forename = "Peter" }); result.IsValid.ShouldBeTrue(); }
public void Transforms_property_value() { var validator = new InlineValidator <Person>(); validator.Transform(x => x.Surname, name => "foo" + name).Equal("foobar"); var result = validator.Validate(new Person { Surname = "bar" }); result.IsValid.ShouldBeTrue(); }
public void Transforms_property_value_to_another_type() { var validator = new InlineValidator <Person>(); validator.Transform(x => x.Surname, name => 1).GreaterThan(10); var result = validator.Validate(new Person { Surname = "bar" }); result.IsValid.ShouldBeFalse(); result.Errors[0].ErrorCode.ShouldEqual("GreaterThanValidator"); }