public void IsValid() { var attribute = new MustBeNullOrEmptyAttribute(); Assert.AreEqual(true, attribute.IsValid(null)); Assert.AreEqual(true, attribute.IsValid(DBNull.Value)); Assert.AreEqual(true, attribute.IsValid(string.Empty)); Assert.AreEqual(false, attribute.IsValid("aaa")); Assert.AreEqual(true, attribute.IsValid(Array.Empty <string>())); Assert.AreEqual(false, attribute.IsValid(new string[] { "aaa" })); Assert.AreEqual(true, attribute.IsValid(Array.Empty <int>())); Assert.AreEqual(false, attribute.IsValid(new int[] { 1 })); }
public void IsValidFail(object value) { var attribute = new MustBeNullOrEmptyAttribute(); try { attribute.IsValid(value); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual("Value must be subtype of IEnumerable.", ex.Message); } }