Exemplo n.º 1
0
        void specify_dynamic_validation()
        {
            dynamic person = new Person();

            person.FirstName = "Amir";

            person.Email = "*****@*****.**";

            person.EmailConfirmation = "";

            Assert.AreEqual(false, person.IsValid());

            Assert.AreEqual("Emails must match.", person.FirstError());

            Assert.AreEqual("AMIR", person.UpperCaseFirstName());
        }
Exemplo n.º 2
0
        void specify_taking_it_to_the_next_level()
        {
            dynamic person = new Person();

            person.FirstName = "Amir";

            Assert.AreEqual("Amir", person.FirstName);

            Assert.AreEqual(true, person.RespondsTo("FirstName"));

            person.SetMember("FirstName", "Jane");

            Assert.AreEqual("Jane", person.FirstName);

            Assert.AreEqual("Jane", person.GetMember("FirstName"));

            person.DeleteMember("FirstName");

            Assert.AreEqual(false, person.RespondsTo("FirstName"));

            person = new Person(new { FirstName = "Amir" });

            Assert.AreEqual(false, person.HasChanged());

            person.FirstName = "Jane";

            Assert.AreEqual(true, person.HasChanged());

            Assert.AreEqual("Amir", person.Original("FirstName"));

            var change = person.Changes("FirstName");

            Assert.AreEqual("Amir", change.Original);

            Assert.AreEqual("Jane", change.New);

            Assert.AreEqual(true, person.IsValid());  //this should throw exception if there is no validation defined

            person.FirstName = "";

            Assert.AreEqual(false, person.IsValid());

            Assert.AreEqual("First name is required.", person.FirstError());
        }