Пример #1
0
        public void Can_Set_And_Get_Errors()
        {
            var obj = new MockValidatableObject();

            Assert.IsFalse(obj.HasErrors);
            Assert.IsNull(obj.GetErrors(() => obj.Name)?.Cast <string>().ToList().FirstOrDefault());

            obj.Invalidate();

            Assert.IsTrue(obj.HasErrors);
            Assert.AreEqual("The name is required.", obj.GetErrors(() => obj.Name).Cast <string>().ToList().FirstOrDefault());
        }
        public void Can_Set_And_Get_Errors()
        {
            var obj = new MockValidatableObject();

            Assert.IsFalse(obj.HasErrors);
            Assert.IsNull(obj.GetErrors(() => obj.Name)?.ToList().FirstOrDefault());

            obj.SetError(() => obj.Name, "The name is invalid.");
            obj.SetError(() => obj.Name, "The name is unknown.");

            Assert.IsTrue(obj.HasErrors);

            var errors = obj.GetErrors(() => obj.Name).ToList();

            Assert.AreEqual("The name is invalid.", errors[0]);
            Assert.AreEqual("The name is unknown.", errors[1]);
        }