public void NoValuesSetGenericEmptyList(string propertyName) { // nothing to validate because list is empty ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, new string[] { }); attr.IsValid(new List <string>()).Should().BeTrue(); }
public void NoValuesSetNullList(string propertyName) { // nothing to validate because list is null ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, new string[] { }); attr.IsValid(null).Should().BeTrue(); }
public void GenericListNoValuesDefinedToBeAllowedNullValueIsAllowed(string propertyName) { ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, new string[] { }); List <string> inList = new List <string>(1); inList.Add(null); attr.IsValid(inList).Should().BeTrue(); }
public void PropertyNameInvalidAllowedValuesNull(string propertyName) { ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, new string[] { }); List <SomeDemoObject> inList = new List <SomeDemoObject>(5); inList.Add(new SomeDemoObject()); Action act = () => attr.IsValid(inList); act.ShouldThrowExactly <ArgumentException>().WithMessage($"Item doesn't contain property named: '{propertyName}'.*"); }
public void ArrayListNoValuesDefinedToBeAllowedNullValueIsAllowed(string propertyName) { // the underlying AllowedValuesAttribute validator allows null values // the property name is null or empty string (or just whitespaces) this should be true ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, new string[] { }); ArrayList inList = new ArrayList(1); inList.Add(null); attr.IsValid(inList).Should().BeTrue(); }
public void ListContainsAllowedStringValues(string propertyName) { string[] allowedValues = new string[] { "ptv", "vrk", "some other text" }; ListPropertyAllowedValuesAttribute attr = new ListPropertyAllowedValuesAttribute(propertyName, allowedValues); List <string> inList = new List <string>(); inList.Add("some other text"); inList.Add("ptv"); inList.Add(null); // null should be always allowed inList.Add("vrk"); attr.IsValid(inList).Should().BeTrue(); }