public void AllowedValues_Single() { var attribute = new ContainsOnlyAttribute("a"); Assert.True(attribute.IsValid(ListOf <string>())); Assert.True(attribute.IsValid(ListOf("a"))); Assert.True(attribute.IsValid(ListOf("a", "a"))); }
public void AllowedValues_InvalidValuesTypeThrows() { var attribute = new ContainsOnlyAttribute("a"); Assert.Throws <ArgumentException>(() => attribute.IsValid(1)); Assert.Throws <ArgumentException>(() => attribute.IsValid(new { })); Assert.Throws <ArgumentException>(() => attribute.IsValid(null)); }
public void AllowedValues_Single_Invalid() { var attribute = new ContainsOnlyAttribute("a"); Assert.False(attribute.IsValid(ListOf("A"))); Assert.False(attribute.IsValid(ListOf("A", "a"))); Assert.False(attribute.IsValid(ListOf("b"))); Assert.False(attribute.IsValid(ListOf("b", "a"))); Assert.False(attribute.IsValid(ListOf(1))); Assert.False(attribute.IsValid(ListOf(new { }))); Assert.False(attribute.IsValid(ListOf <object>("a", new { }, 1))); }