public void AllowedValuesProvider_Single() { var model = new AllowedValuesProviderModel { AllowedValues = ListOf("a") }; Assert.True(ValidateModelValues(model, ListOf("a"))); Assert.True(ValidateModelValues(model, ListOf("a", "a"))); }
public void AllowedValuesProvider_Empty() { var model = new AllowedValuesProviderModel { AllowedValues = new List <string>(), }; Assert.True(ValidateModelValues(model, new List <string>())); Assert.True(ValidateModelValues(model, ListOf("a"))); Assert.True(ValidateModelValues(model, ListOf("a", "b"))); }
private bool ValidateModelAllowedValues(AllowedValuesProviderModel model, object?allowedValues) { model.AllowedValues = allowedValues; var context = new ValidationContext(model) { MemberName = nameof(model.Values) }; return(Validator.TryValidateProperty(model.Values, context, new List <ValidationResult>())); }
public void AllowedValuesProvider_InvalidValuesTypeThrows() { var model = new AllowedValuesProviderModel { AllowedValues = ListOf("a") }; Assert.Throws <ArgumentException>(() => ValidateModelValues(model, 1)); Assert.Throws <ArgumentException>(() => ValidateModelValues(model, new { })); Assert.Throws <ArgumentException>(() => ValidateModelValues(model, null)); }
public void AllowedValuesProvider_Single_Invalid() { var model = new AllowedValuesProviderModel { AllowedValues = ListOf("a") }; Assert.False(ValidateModelValues(model, ListOf("A"))); Assert.False(ValidateModelValues(model, ListOf("A", "a"))); Assert.False(ValidateModelValues(model, ListOf("b"))); Assert.False(ValidateModelValues(model, ListOf("b", "a"))); }
public void AllowedValuesProvider_Multiple() { var model = new AllowedValuesProviderModel { AllowedValues = ListOf("a", "b", "c") }; Assert.True(ValidateModelValues(model, ListOf <string>())); Assert.True(ValidateModelValues(model, ListOf("a"))); Assert.True(ValidateModelValues(model, ListOf("b"))); Assert.True(ValidateModelValues(model, ListOf("c"))); Assert.True(ValidateModelValues(model, ListOf("a", "b"))); Assert.True(ValidateModelValues(model, ListOf("a", "b", "c"))); Assert.True(ValidateModelValues(model, ListOf("a", "a", "b"))); Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b"))); Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b", "c"))); Assert.True(ValidateModelValues(model, ListOf("a", "a", "b", "b", "c", "c"))); }