public void Test_PersonModelProperties() { var vm = new PersonModelViewModel(); vm.PropertyChanged += ((s, e) => { if (e.PropertyName == "FirstName") { string firstName = (s as PersonModelViewModel).FirstName; Assert.AreEqual("Hugo", firstName); } }); vm.FirstName = "Hugo"; vm.LastName = "Dieter"; vm.BirthDate = new DateTime(1993, 6, 1); vm.Company = new CompanyModelViewModel(new CompanyModel(1, "A", "B", "C", "Firma X", "1234")); vm.Suffix = "Suffix"; vm.Title = "Master of the universe"; Assert.AreEqual("Hugo", vm.FirstName); Assert.AreEqual("Dieter", vm.LastName); Assert.AreEqual(new DateTime(1993, 6, 1), vm.BirthDate); Assert.AreEqual("Firma X", vm.Company.Name); Assert.AreEqual("Suffix", vm.Suffix); Assert.AreEqual("Master of the universe", vm.Title); }
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"); }