public async Task FailsIfOneConfigsInCollectionIsInvalid() { var max = 4; var sample = new SampleConfig { ListOfConfigs = new List <ListConfig> { new ListConfig { Name = "item one", Value = 5 }, new ListConfig { Name = "item two", Value = 2 } } }; modelBuilder.Collection(p => p.ListOfConfigs) .Property(p => p.Value) .WithMaxValue(max); var model = modelBuilder.Build(); var result = await target.Validate(sample, model, configIdentity); Assert.False(result.IsValid); Assert.Single(result.Errors); Assert.Equal(ValidationStrings.GreaterThanMax(nameof(ListConfig.Value), max), result.Errors.Single()); }
public async Task FailsIfGreaterThanMax_decimal() { var max = 3m; var sample = new SampleConfig { Decimal = 4m }; modelBuilder.Property(k => k.Decimal).WithMaxValue(max); var model = modelBuilder.Build(); var result = await target.Validate(sample, model, configIdentity); Assert.False(result.IsValid); Assert.Single(result.Errors); Assert.Equal(ValidationStrings.GreaterThanMax(nameof(SampleConfig.Decimal), max), result.Errors.Single()); }
public async Task FailsIfGreaterThanMax_date() { var max = new DateTime(2013, 10, 10); var sample = new SampleConfig { StartDate = max.AddDays(1) }; modelBuilder.Property(k => k.StartDate).WithMaxValue(max); var model = modelBuilder.Build(); var result = await target.Validate(sample, model, configIdentity); Assert.False(result.IsValid); Assert.Single(result.Errors); Assert.Equal(ValidationStrings.GreaterThanMax(nameof(SampleConfig.StartDate), max), result.Errors.Single()); }
public async Task FailsIfGreaterThanMax_int() { var max = 3; var sample = new SampleConfig { LlamaCapacity = 4 }; modelBuilder.Property(k => k.LlamaCapacity).WithMaxValue(max); var model = modelBuilder.Build(); var result = await target.Validate(sample, model, configIdentity); Assert.False(result.IsValid); Assert.Equal(1, result.Errors.Count()); Assert.Equal(ValidationStrings.GreaterThanMax(nameof(SampleConfig.LlamaCapacity), max), result.Errors.Single()); }