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 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); }