public async Task NotEmpty_List() { var entity1 = new Entity1(); var validator = entity1.Validator(); validator.For(_ => _.List1) .NotEmpty(); var failureDatas = await validator.Validate(); Assert.Equal("List1", failureDatas.Single().GetPropertyName()); Assert.Equal("'List1' should not be empty.", failureDatas.Single().ErrorMessage); }
public async Task NotEmpty_NullableInt() { var entity1 = new Entity1(); var validator = entity1.Validator(); validator.For(_ => _.NullableInt1) .NotEmpty(); var errorInfos = await validator.Validate(); Assert.Equal("NullableInt1", errorInfos.Single().PropertyName); Assert.Equal("'NullableInt1' should not be empty.", errorInfos.Single().Message); }
public async Task NotNull_NullableInt() { var entity1 = new Entity1(); var validator = entity1.Validator(); validator.For(_ => _.NullableInt1) .NotNull(); var failureDatas = await validator.Validate(); Assert.Equal("NullableInt1", failureDatas.Single().GetPropertyName()); Assert.Equal("NullableInt1", failureDatas.Single().GetPropertyLocalizedName()); Assert.Equal("'NullableInt1' must not be empty.", failureDatas.Single().ErrorMessage); }
public async Task NotNull_NullableInt() { var entity1 = new Entity1(); var validator = entity1.Validator(); validator.For(_ => _.NullableInt1) .NotNull(); var errorInfos = await validator.Validate(); Assert.Equal("NullableInt1", errorInfos.Single().PropertyName); Assert.Equal("NullableInt1", errorInfos.Single().DisplayPropertyName); Assert.Equal("notnull_error", errorInfos.Single().Code); Assert.Equal("'NullableInt1' must not be empty.", errorInfos.Single().Message); }
public async Task ExclusiveBetween() { var entity1 = new Entity1 { Long1 = -25 }; var validator = entity1.Validator(); validator.For(_ => _.Long1) .ExclusiveBetween(1, 200); var failureDatas = await validator.Validate(); Assert.Equal("Long1", failureDatas.Single().GetPropertyName()); Assert.Equal("Long1", failureDatas.Single().GetPropertyLocalizedName()); Assert.Equal("'Long1' must be between 1 and 200. You entered -25.", failureDatas.Single().ErrorMessage); }
public async Task NotEqual() { var entity1 = new Entity1 { Int2 = 7 }; var validator = entity1.Validator(); validator.For(_ => _.Int2) .NotEqual(7); var failureDatas = await validator.Validate(); Assert.Equal("Int2", failureDatas.Single().GetPropertyName()); Assert.Equal("Int2", failureDatas.Single().GetPropertyLocalizedName()); Assert.Equal("'Int2' should not be equal to '7'.", failureDatas.Single().ErrorMessage); }
public async Task NotEqual() { var entity1 = new Entity1 { Int2 = 7 }; var validator = entity1.Validator(); validator.For(_ => _.Int2) .NotEqual(7); var errorInfos = await validator.Validate(); Assert.Equal("Int2", errorInfos.Single().PropertyName); Assert.Equal("Int2", errorInfos.Single().DisplayPropertyName); Assert.Equal("notequal_error", errorInfos.Single().Code); Assert.Equal("'Int2' should not be equal to '7'.", errorInfos.Single().Message); }
public async Task ForThis() { var entity1 = new Entity1 { List2 = new List <long> { 0 } }; var validator = entity1.Validator(); validator.For(_ => _.List2) .NotEmpty() .ForEach(item => item.For("Name1") .NotEmpty()); var failureDatas = await validator.Validate(); Assert.Equal("List2[0]", failureDatas.Single().GetPropertyName()); Assert.Equal("'Name1' should not be empty.", failureDatas.Single().ErrorMessage); }