Ejemplo n.º 1
0
        public void IsValidFail(object value)
        {
            var attribute = new MustBeValidDateAttribute();

            try
            {
                attribute.IsValid(value);

                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value must be of type String.", ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void IsValid()
        {
            var attribute = new MustBeValidDateAttribute();

            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.1.2018"));

            attribute.DateFormat = "dd.MM.yyyy";

            Assert.AreEqual(true, attribute.IsValid("31.01.2018"));
            Assert.AreEqual(false, attribute.IsValid("31/01/2018"));

            attribute.DateFormat = "yyyyMMdd";

            Assert.AreEqual(true, attribute.IsValid("20180131"));
            Assert.AreEqual(false, attribute.IsValid("201801311"));
        }