public void IsValidFail(object value) { var attribute = new MustBeDateAttribute(); try { attribute.IsValid(value); Assert.Fail(); } catch (ArgumentException ex) { Assert.AreEqual("Value must be of type DateTime.", ex.Message); } }
public void IsValid() { DateTime?dateNullable = new DateTime(2018, 3, 4); var attribute = new MustBeDateAttribute(); Assert.AreEqual(true, attribute.IsValid(DateTime.Today as DateTime?)); Assert.AreEqual(true, attribute.IsValid(null as DateTime?)); Assert.AreEqual(true, attribute.IsValid(DateTime.Today)); Assert.AreEqual(false, attribute.IsValid(DateTime.Now)); Assert.AreEqual(true, attribute.IsValid(null as DateTime?)); Assert.AreEqual(false, attribute.IsValid(DateTime.Now as DateTime?)); Assert.AreEqual(true, attribute.IsValid(dateNullable)); }