Exemple #1
0
        public void Populate_WithRegularAndComplexClass_Works()
        {
            // Let's pretend these are the values our properties are currently bound to from our View
            FromEmail.Value   = "LOL_I_AM_NOT_AN_EMAIL!"; // bad
            ToName.Value      = "X";                      // bad
            MessageHtml.Value = "NOPE";                   // bad
            Rating.Value      = 5;                        // good

            var testClassInstance = ValidatableProps.Populate <TestClass>();

            Assert.AreEqual("LOL_I_AM_NOT_AN_EMAIL!", testClassInstance.FromEmail);
            Assert.AreEqual("X", testClassInstance.ToName);
            Assert.AreEqual("NOPE", testClassInstance.MessageHtml);
            Assert.AreEqual(5, testClassInstance.Rating);

            var complexClassValidatable1 = new Validatable <TestClass>(nameof(TestComplexClass.TestClassInstance));

            complexClassValidatable1.Value = testClassInstance;

            var complexClassValidatable2 = new Validatable <string>(nameof(TestComplexClass.MyName));

            complexClassValidatable2.Value = "Test Class!";

            var complexValidatables      = new Validatables(complexClassValidatable1, complexClassValidatable2);
            var testComplexClassInstance = complexValidatables.Populate <TestComplexClass>();

            Assert.AreEqual("Test Class!", testComplexClassInstance.MyName);
            Assert.AreEqual(testClassInstance, testComplexClassInstance.TestClassInstance);
        }
        public void ExecuteValidateEmailCommand()
        {
            var email = _emailValidatables.Populate <Email>();

            // if updating an existing instance instead of creating a new one, just pass it in, e.g. _emailValidatables.Populate(email);
            // in either case, only the matching properties in the class will be updated

            if (Validate(email).IsValidOverall)
            {
                EmailWins++;
            }
            else
            {
                EmailFails++;
            }
        }
Exemple #3
0
        public void Populate_WithExistingClass_Works()
        {
            // Let's pretend these are the values our properties are currently bound to from our View
            FromEmail.Value   = "OLD VALUE"; // bad
            ToName.Value      = "OLD VALUE"; // bad
            MessageHtml.Value = "OLD VALUE"; // bad
            Rating.Value      = 5;           // good

            var testClassInstance = ValidatableProps.Populate <TestClass>();

            var subsetOfValidatableProps = new Validatables(FromEmail, ToName);

            FromEmail.Value = "NEW VALUE";
            ToName.Value    = "NEW VALUE";

            subsetOfValidatableProps.Populate(testClassInstance);

            Assert.AreEqual("NEW VALUE", testClassInstance.FromEmail);
            Assert.AreEqual("NEW VALUE", testClassInstance.ToName);
            Assert.AreEqual("OLD VALUE", testClassInstance.MessageHtml);
            Assert.AreEqual(5, testClassInstance.Rating);
        }