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."); }
/// <summary> /// 初始化 EmailViewModel 类的新实例。 /// </summary> /// <param name="detail">此 ViewModel 基于的基础电子邮件</param> public EmailViewModel(Email detail) { if (detail == null) { throw new ArgumentNullException("detail"); } this.email = detail; }
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 BuildViewModel() { Phone p = new Phone(); Email e = new Email(); Address a = new Address(); var pvm = ContactDetailViewModel.BuildViewModel(p); Assert.IsInstanceOfType(pvm, typeof(PhoneViewModel), "Factory method created wrong ViewModel type."); Assert.AreEqual(p, pvm.Model, "Underlying model object on ViewModel is not correct."); var evm = ContactDetailViewModel.BuildViewModel(e); Assert.IsInstanceOfType(evm, typeof(EmailViewModel), "Factory method created wrong ViewModel type."); Assert.AreEqual(e, evm.Model, "Underlying model object on ViewModel is not correct."); var avm = ContactDetailViewModel.BuildViewModel(a); Assert.IsInstanceOfType(avm, typeof(AddressViewModel), "Factory method created wrong ViewModel type."); Assert.AreEqual(a, avm.Model, "Underlying model object on ViewModel is not correct."); }
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."); }
public void AddContactDetailToEmployeeOutsideUnitOfWork() { using (FakeEmployeeContext ctx = new FakeEmployeeContext()) { UnitOfWork unit = new UnitOfWork(ctx); Employee emp = new Employee(); ContactDetail detail = new Email(); try { unit.AddContactDetail(emp, detail); Assert.Fail("Adding a contact detail to an employee outside the Unit of Work did not throw."); } catch (InvalidOperationException ex) { Assert.AreEqual("The supplied Employee is not part of this Unit of Work.", ex.Message); } } }