public void IsValid() { var attribute = new MustBeValidIntegerAttribute(); Assert.AreEqual(true, attribute.IsValid(null)); Assert.AreEqual(true, attribute.IsValid(DBNull.Value)); Assert.AreEqual(false, attribute.IsValid(string.Empty)); Assert.AreEqual(true, attribute.IsValid("1")); Assert.AreEqual(true, attribute.IsValid("12")); Assert.AreEqual(true, attribute.IsValid("123")); Assert.AreEqual(true, attribute.IsValid("0123")); Assert.AreEqual(false, attribute.IsValid("aaa")); Assert.AreEqual(false, attribute.IsValid("1.1")); }
public void IsValidFail(object value) { var attribute = new MustBeValidIntegerAttribute(); try { attribute.IsValid(value); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual("Value must be of type String.", ex.Message); } }