コード例 #1
0
        private static void Run_Example_With_Valid_Entity(ValidatorEngine vtor)
        {
            Console.WriteLine("==Entity with valid values==");
            var m = new Meeting
                        {
                            Name = "NHibernate Validator virtual meeting",
                            Description = "How to configure NHibernate Validator in different ways.",
                            Start = DateTime.Now,
                            End = DateTime.Now.AddHours(2) // 2 hours of meeting.
                        };

            if(vtor.IsValid(m))
                Console.WriteLine("The entity is valid.");
            else
                throw new Exception("Something was wrong in the NHV configuration, the entity should be invalid.");
        }
コード例 #2
0
        private static void Run_Example_With_Invalid_Entity(ValidatorEngine vtor)
        {
            Console.WriteLine("==Entity with Invalid values==");
            var m = new Meeting
                        {
                            Name = "NHibernate Validator virtual meeting",
                            Description = "How to configure NHibernate Validator in different ways.",
                            Start = DateTime.Now.AddHours(2), //Invalid: the Start date is minor than End.
                            End = DateTime.Now
                        };

            var invalidValues = vtor.Validate(m);
            if (invalidValues.Length == 0)
                throw new Exception("Something was wrong in the NHV configuration, the entity should be invalid.");
            else
            {
                Console.WriteLine("The entity is invalid.");
                foreach (var value in invalidValues)
                {
                    Console.WriteLine(" - " + value.Message);
                }
            }
        }