コード例 #1
0
        public void AfterTodayAttributeTest_ShouldFail()
        {
            AfterTodayTest afterToday = new AfterTodayTest();

            afterToday.MustBeAfterToday = new DateTime(1993, 10, 5);

            ValidationContext validationContext = new ValidationContext(afterToday)
            {
                MemberName = "MustBeAfterToday"
            };

            Assert.IsFalse(Validator.TryValidateProperty(afterToday.MustBeAfterToday, validationContext, null));
        }
コード例 #2
0
        public void AfterTodayAttributeTest_ShouldPass()
        {
            AfterTodayTest afterToday = new AfterTodayTest();

            afterToday.MustBeAfterToday = new DateTime(2022, 10, 5);

            ValidationContext validationContext = new ValidationContext(afterToday)
            {
                MemberName = "MustBeAfterToday"
            };

            var results = new List<ValidationResult>();

            Assert.IsTrue(Validator.TryValidateProperty(afterToday.MustBeAfterToday, validationContext, results));
        }