public void Test_CustomerModelProperties() { var customer = new PersonModel { FirstName = "Dummy", LastName = "Dieter" }; var vm = new CustomerModelViewModel(customer); vm.PropertyChanged += ((s, e) => { if (e.PropertyName == "ShippingAddress") { string shippingAddress = (s as CustomerModelViewModel).ShippingAddress; Assert.AreEqual("Z", shippingAddress); } }); vm.Address = "X"; vm.BillingAddress = "Y"; vm.ShippingAddress = "Z"; Assert.AreEqual("X", vm.Address); Assert.AreEqual("Y", vm.BillingAddress); Assert.AreEqual("Z", vm.ShippingAddress); Assert.AreEqual(customer.Address, vm.Address); Assert.AreEqual(customer.BillingAddress, vm.BillingAddress); Assert.AreEqual(customer.ShippingAddress, vm.ShippingAddress); }
public CustomerDataViewModel(IUnityContainer container, ICustomerService customerService, INotificationService notificationService, CustomerModel customer) { if (customer == null) { throw new ArgumentNullException("customer"); } this.customerService = customerService; this.notificationService = notificationService; this.SaveCustomerCommand = new RelayCommand(onSaveCustomerExecuted, onSaveCustomerCanExecute); this.customer = customer; this.customerViewModel = new CustomerModelViewModel(customer); var company = customer as CompanyModel; if (company != null) { this.companyViewModel = new CompanyModelViewModel(company); return; } var person = customer as PersonModel; if (person != null) { this.personViewModel = new PersonModelViewModel(person); this.CustomerSearchBoxViewModel = container.Resolve <CustomerSearchBoxViewModel>(new ParameterOverrides { { "customerType", CustomerType.Company } }); if (person.Company != null) { this.CustomerSearchBoxViewModel.SelectedCustomer = new CustomerDisplayNameViewModel(person.Company); } this.CustomerSearchBoxViewModel.PropertyChanged += ((s, e) => { if (e.PropertyName == "SelectedCustomer" && s is CustomerSearchBoxViewModel) { var selectedCustomer = (s as CustomerSearchBoxViewModel).SelectedCustomer; person.Company = selectedCustomer == null ? null : selectedCustomer.Model as CompanyModel; } }); return; } throw new ArgumentOutOfRangeException("customer"); }