public void with_method() { var builder = GetBuilder(); var rule = GetRule(builder); rule .For(m => m) .Assert(with_method_build); rule .For(m => m.Size) .Assert(with_method_build_size); var result = new ValidationRuleValidator <ModelA>(builder) .Validate(new ModelA { Name = string.Empty, Size = 0 }); foreach (var error in result) { Console.WriteLine(error); } Assert.True(result.ElementAt(0) .StartsWith("Name:not-empty")); Assert.True(result.ElementAt(1) .StartsWith("Size:min")); }
public void fail_model_name_is_empty_and_size_is_0() { var builder = GetBuilder(); var rule = GetRule(builder); rule .For(m => m.Name) .Assert(_is.NotNull) .Assert(_is.NotEmpty); rule .For(m => m.Size) .Assert(_is.Min(1)); var result = new ValidationRuleValidator <ModelA>(builder) .Validate(new ModelA { Name = string.Empty, Size = 0 }); foreach (var error in result) { Console.WriteLine(error); } Assert.True(result.ElementAt(0) .StartsWith("Name:not-empty")); Assert.True(result.ElementAt(1) .StartsWith("Size:min")); }
public void with_method_predicate() { var builder = GetBuilder(); var rule = GetRule(builder); rule .For(m => m.Name) .Assert("a-function", with_method_predicate_name); var result = new ValidationRuleValidator <ModelA>(builder) .Validate(new ModelA { Name = string.Empty, Size = 0 }); foreach (var error in result) { Console.WriteLine(error); } Assert.True(result.ElementAt(0) .StartsWith("Name:a-function")); }