public void ModelChangesFlowToProperties() { // Test ViewModel returns current value from model Email em = new Email { Address = "EMAIL" }; EmailViewModel vm = new EmailViewModel(em); em.Address = "NEW_EMAIL"; Assert.AreEqual("NEW_EMAIL", vm.Address, "Address property is not fetching the value from the model."); }
public void PropertyGetAndSet() { // Test initial properties are surfaced in ViewModel Email em = new Email { Address = "EMAIL" }; EmailViewModel vm = new EmailViewModel(em); Assert.AreEqual(em, vm.Model, "Bound object property did not return object from model."); Assert.AreEqual(em.ValidUsageValues, vm.ValidUsageValues, "ValidUsageValues property did not return value from model."); Assert.AreEqual("EMAIL", vm.Address, "Address property did not return value from model."); // Test changing properties updates Model and raises PropertyChanged string lastProperty; vm.PropertyChanged += (sender, e) => { lastProperty = e.PropertyName; }; lastProperty = null; vm.Address = "NEW_EMAIL"; Assert.AreEqual("Address", lastProperty, "Setting Address property did not raise correct PropertyChanged event."); Assert.AreEqual("NEW_EMAIL", em.Address, "Setting Address property did not update model."); }
public void PropertyGetAndSet() { // 测试初始属性显示在 ViewModel 中 Email em = new Email { Address = "EMAIL" }; EmailViewModel vm = new EmailViewModel(em); Assert.AreEqual(em, vm.Model, "Bound object property did not return object from model."); Assert.AreEqual(em.ValidUsageValues, vm.ValidUsageValues, "ValidUsageValues property did not return value from model."); Assert.AreEqual("EMAIL", vm.Address, "Address property did not return value from model."); // 更改属性的测试将更新模型并引发 PropertyChanged string lastProperty; vm.PropertyChanged += (sender, e) => { lastProperty = e.PropertyName; }; lastProperty = null; vm.Address = "NEW_EMAIL"; Assert.AreEqual("Address", lastProperty, "Setting Address property did not raise correct PropertyChanged event."); Assert.AreEqual("NEW_EMAIL", em.Address, "Setting Address property did not update model."); }