public void IsValid() { var attribute = new MustBeValidTimeSpanAttribute(); 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:00:00:01")); Assert.AreEqual(false, attribute.IsValid("aaa")); attribute.TimeSpanFormat = "hh\\:mm\\:ss\\.fff"; Assert.AreEqual(true, attribute.IsValid("12:13:14.156")); Assert.AreEqual(false, attribute.IsValid("12:13:14")); Assert.AreEqual(false, attribute.IsValid("12:13:14.15")); }
public void IsValidFail(object value) { var attribute = new MustBeValidTimeSpanAttribute(); try { attribute.IsValid(value); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual("Value must be of type String.", ex.Message); } }