public ActionResult NewCustomer() { var model = new AddEditCustomerViewModel { }; return(View(model)); }
public MainWindowViewModel() { NavCommand = new RelayCommand <string>(OnNav); _customerListViewModel = ContainerHelper.Container.Resolve <CustomerListViewModel>(); _addEditViewModel = ContainerHelper.Container.Resolve <AddEditCustomerViewModel>(); _customerListViewModel.PlaceOrderRequested += NavToOrder; _customerListViewModel.AddCustomerRequested += NavToAddCustomer; _customerListViewModel.EditCustomerRequested += NavToEditCustomer; _addEditViewModel.Done += NavToCustomerList; }
public MainWindowViewModel() { _customerListViewModel = new CustomerListViewModel(repo); _addEditCustomerViewModel = new AddEditCustomerViewModel(repo); NavCommand = new RelayCommand <string>(OnNav); _customerListViewModel.PlaceOrderRequested += NavToOrder; _customerListViewModel.AddCustomerRequested += NavToAddCustomer; _customerListViewModel.EditCustomerRequested += NavToEditCustomer; _addEditCustomerViewModel.Done += NavToCustomerList; }
public void CheckEditCustomer_Fails() { //create some Customers in the Database 1st String cust1String = Guid.NewGuid().ToString(); Assert.Greater(DataService.AddCustomer( GetCustomer(cust1String, "1")), 0); SearchCustomersViewModel searchCustomersVM = new SearchCustomersViewModel(); //should not be able to delete without a current customer Assert.AreEqual(false, searchCustomersVM.EditCustomerCommand.CanExecute(null)); FetchCustomer(searchCustomersVM, String.Format("{0}_1", cust1String)); Assert.AreEqual(1, searchCustomersVM.MatchedCustomers.Where( c => c.FirstName.DataValue == searchCustomersVM.CurrentFilterText).Count()); searchCustomersVM.CurrentCustomer = searchCustomersVM.MatchedCustomers[0]; //should be able to delete with a current customer Assert.AreEqual(true, searchCustomersVM.EditCustomerCommand.CanExecute(null)); //As we are testing for failure ensure that this Customer up for editing //is currently being edited within the AddEditCustomerViewModel workspace //within the MainWindowViewModel. //Then try and edit the customer, but can only do it if the customer //is not being edited in MainWindowViewModel, so should fail MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(); AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); addEditCustomerViewModel.CurrentCustomer = searchCustomersVM.MatchedCustomers[0]; mainWindowViewModel.Workspaces.Add(addEditCustomerViewModel); searchCustomersVM.EditCustomerCommand.Execute(null); //should only have the 1 AddEditCustomerViewModel Int32 openCustomerWorkSpaces = mainWindowViewModel.Workspaces.Where(w => w.GetType() == typeof(AddEditCustomerViewModel)).Count(); Assert.AreEqual(1, openCustomerWorkSpaces); Assert.IsNull(searchCustomersVM.CurrentCustomer); }
public void AddOrderFromOrderVMTest() { AddEditOrderViewModel addEditOrderViewModel = new AddEditOrderViewModel(); addEditOrderViewModel.CurrentViewMode = ViewMode.AddMode; addEditOrderViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); addEditOrderViewModel.CurrentCustomerOrder = OrderModel.OrderToOrderModel(ord); addEditOrderViewModel.CurrentCustomerOrder.Quantity.DataValue = 1; AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue ManualResetEvent manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); //Execute AddEditOrderViewModel.SaveOrderCommand addEditOrderViewModel.SaveOrderCommand.Execute(null); Int32 currentCustomerOrderCount = addEditCustomerViewModel.CurrentCustomer.Orders.Count; //Wait for Lazy load of AddEditCustomerViewModel.CurrentCustomer.Orders //which is triggered via Mediator, and is run on the AddEditCustomerViewModel //BackgroundTaskManager manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); Assert.AreEqual(currentCustomerOrderCount + 1, addEditCustomerViewModel.CurrentCustomer.Orders.Count); }
public MainViewModel() { this.customerListViewModel = ContainerHelper.Container.Resolve <CustomerListViewModel>(); this.addEditViewModel = ContainerHelper.Container.Resolve <AddEditCustomerViewModel>(); //this.CurrentViewModel = new CustomerListViewModel(); this.NavigateCommand = new RelayCommand <string>(this.OnNavigate); this.customerListViewModel.PlaceOrderRequested += this.NavigateToOrder; this.customerListViewModel.AddCustomerRequested += this.NavigateToAddCustomer; this.customerListViewModel.EditCustomerRequested += this.NavigateToEditCustomer; this.addEditViewModel.Done += this.NavigateToCustomerList; }
public void EditOrderTest() { AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); //Test Command can't run without an order Assert.AreEqual(addEditCustomerViewModel.EditOrderCommand.CanExecute(null), false); addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue ManualResetEvent manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); addEditCustomerViewModel.CurrentCustomerOrder = addEditCustomerViewModel.CurrentCustomer.Orders.First(); addEditCustomerViewModel.CurrentCustomerOrder.Quantity.DataValue = 1; //Test that EditOrderCommand can now Execute Assert.AreEqual(addEditCustomerViewModel.EditOrderCommand.CanExecute(null), true); //Run the AddOrderCommand TestUIVisualizerService testUIVisualizerService = (TestUIVisualizerService) ViewModelBase.ServiceProvider.Resolve <IUIVisualizerService>(); //Queue up the response we expect for our given TestUIVisualizerService //for a given ICommand/Method call within the test ViewModel testUIVisualizerService.ShowDialogResultResponders.Enqueue (() => { return(true); } ); addEditCustomerViewModel.EditOrderCommand.Execute(null); Assert.AreEqual(addEditCustomerViewModel.EditOrderCommand.CommandSucceeded, true); //Clear the TestUIVisualizerService.ShowDialogResultResponders testUIVisualizerService.ShowDialogResultResponders.Clear(); }
public void CreatorTestMethodAddEditView() { AddEditCustomerViewModel vm = new AddEditCustomerViewModel(); Assert.IsTrue(String.IsNullOrEmpty(vm.ActionText)); Assert.IsNotNull(vm.MessageBoxShowDelegate); Assert.IsNotNull(vm.AddCustomerCommand); Assert.IsNotNull(vm.EditCustomerCommand); Assert.IsTrue(vm.AddCustomerCommand.CanExecute(null)); Assert.IsTrue(vm.EditCustomerCommand.CanExecute(null)); }
public ActionResult Create(AddEditCustomerViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var newContact = Mapper.Map <Contact>(model); var isAdded = _contactService.Add(newContact); if (!isAdded) { return(View(model)); } return(RedirectToAction("List")); }
public ShellViewModel( CustomersViewModel customerListVM, OrdersListViewModel ordersListVM, AddEditCustomerViewModel addEditCustomerVM, AddNewOrderViewModel addNewOrderVM, IEventAggregator eventAggregator) { _navigationStates = new Dictionary <NavigationState, Action <NavigationState> > { [NavigationState.Search] = x => InternalNavigateTo(x, customerListVM), [NavigationState.Orders] = x => InternalNavigateTo(x, ordersListVM) }; _customerListVM = customerListVM; _addEditCustomerVM = addEditCustomerVM; _addNewOrderVM = addNewOrderVM; eventAggregator.Subscribe(this); }
public MainWindowViewModel() { NavCommand = new RelayCommand <string>(OnNav); //after DI changes, without IOC container.. //_customerListViewModel = new CustomerListViewModel(_repo); //_addEditCustomerViewModel = new AddEditCustomerViewModel(_repo); //DI with IOC Unity _customerListViewModel = ContainerHelper.Container.Resolve <CustomerListViewModel>(); _addEditCustomerViewModel = ContainerHelper.Container.Resolve <AddEditCustomerViewModel>(); //subscribe to event from child viewmodel _customerListViewModel.PlaceOrderRequested += _customerListView_PlaceOrderRequested; //adding the add/edit, created events, need to subscribe to them _customerListViewModel.AddCustomerRequested += _customerListViewModel_AddCustomerRequested; _customerListViewModel.EditCustomerRequested += _customerListViewModel_EditCustomerRequested; //Done event from add/edit _addEditCustomerViewModel.Done += _addEditCustomerViewModel_Done; }
public ActionResult NewCustomer(AddEditCustomerViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var newContact = Mapper.Map <Contact>(model); newContact.CreatedDate = DateTime.UtcNow; newContact.Status = StatusConstants.Active; var isAdded = _contactService.Add(newContact); if (isAdded) { return(RedirectToAction("login")); } return(View(model)); }
public void AddReaderPopUpWasShownTest() { CustomerViewModel vm = new CustomerViewModel(); vm.CurrentCustomer = new Presentation.Model.CustomerModel(); vm.CurrentCustomer.customer_id = 0; vm.CurrentCustomer.customer_f_name = "Test"; vm.CurrentCustomer.customer_l_name = "Test"; AddEditCustomerViewModel evm = new AddEditCustomerViewModel(); int _boxShowCount = 0; evm.MessageBoxShowDelegate = (messageBoxText) => { _boxShowCount++; Assert.AreEqual("Customer Added", messageBoxText); }; evm.ActionText = "Customer Added"; Assert.IsTrue(vm.AddCustomerCommand.CanExecute(null)); Assert.IsTrue(vm.RefreshCustomerCommand.CanExecute(null)); Assert.IsTrue(vm.DeleteCustomerCommand.CanExecute(null)); evm.AddCustomerCommand.Execute(null); Assert.AreEqual(1, _boxShowCount); vm.RefreshCustomerCommand.Execute(null); Thread.Sleep(3000); Assert.IsTrue(vm.Customers.Count() > 4); vm.CurrentCustomer = vm.Customers.FirstOrDefault(); Assert.IsNotNull(vm.CurrentCustomer); vm.DeleteCustomerCommand.Execute(null); }
public ActionResult Edit(AddEditCustomerViewModel model) { ModelState.Remove("Username"); ModelState.Remove("Password"); ModelState.Remove("ConfirmPassword"); if (!ModelState.IsValid) { return(View(model)); } var updateContact = Mapper.Map <Contact>(model); var isUpdated = _contactService.Update(updateContact); if (!isUpdated) { return(View(model)); } return(RedirectToAction("List")); }
private void EditCustomerCommandTest(AddEditCustomerViewModel addEditCustomerViewModel) { //Test that EditCustomerCommand can not execute with no current order addEditCustomerViewModel.CurrentCustomer = null; //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue ManualResetEvent manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); Assert.AreEqual(addEditCustomerViewModel.EditCustomerCommand.CanExecute(null), false); //now give it an Customer, and check that EditCustomerCommand can't run until its in correct mode addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); addEditCustomerViewModel.CurrentViewMode = ViewMode.EditMode; Assert.AreEqual(addEditCustomerViewModel.EditCustomerCommand.CanExecute(null), false); //now allow the EditCustomerCommand to run by placing it in the correct mode addEditCustomerViewModel.CurrentViewMode = ViewMode.ViewOnlyMode; Assert.AreEqual(addEditCustomerViewModel.EditCustomerCommand.CanExecute(null), true); //execute the EditCustomerCommand addEditCustomerViewModel.EditCustomerCommand.Execute(null); Assert.AreEqual(addEditCustomerViewModel.CurrentViewMode, ViewMode.EditMode); Assert.AreEqual(addEditCustomerViewModel.EditCustomerCommand.CommandSucceeded, true); }
public void CancelCustomerCommandTest() { AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); //test the edit command first, which allows us to put //order into edit mode EditCustomerCommandTest(addEditCustomerViewModel); //so now make an edit to the Customer, say change MobilePhoneNumber Int32 editPhoneNum = 9999; cust.MobilePhoneNumber = editPhoneNum.ToString(); #region CancelCustomerCommandTests //check that CancelCustomerCommand can't run until its in correct mode addEditCustomerViewModel.CurrentViewMode = ViewMode.ViewOnlyMode; Assert.AreEqual(addEditCustomerViewModel.CancelCustomerCommand.CanExecute(null), false); //now allow the CancelCustomerCommand to run by placing it in the correct mode addEditCustomerViewModel.CurrentViewMode = ViewMode.EditMode; Assert.AreEqual(addEditCustomerViewModel.CancelCustomerCommand.CanExecute(null), true); //execute the CancelCustomerCommand addEditCustomerViewModel.CancelCustomerCommand.Execute(null); Assert.AreNotEqual(addEditCustomerViewModel.CurrentCustomer.HomePhoneNumber.DataValue, editPhoneNum); Assert.AreEqual(addEditCustomerViewModel.CancelCustomerCommand.CommandSucceeded, true); //Test that CancelCustomerCommand can not execute with out a current Customer addEditCustomerViewModel.CurrentCustomer = null; Assert.AreEqual(addEditCustomerViewModel.CancelCustomerCommand.CanExecute(null), false); #endregion }
public ActionResult Create() { var model = new AddEditCustomerViewModel(); return(View(model)); }
public void SaveCustomerCommandTest() { AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); //Test Command can't run without an order Assert.AreEqual(addEditCustomerViewModel.SaveCustomerCommand.CanExecute(null), false); #region AddMode addEditCustomerViewModel.CurrentViewMode = ViewMode.AddMode; Customer newCust = GetCustomer("blah", "more"); addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(newCust); //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue ManualResetEvent manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); //test Save Command can run Assert.AreEqual(addEditCustomerViewModel.SaveCustomerCommand.CanExecute(null), true); //Execute SaveCommand addEditCustomerViewModel.SaveCustomerCommand.Execute(null); Assert.Greater(addEditCustomerViewModel.CurrentCustomer.CustomerId.DataValue, 0); #endregion #region EditMode addEditCustomerViewModel.CurrentViewMode = ViewMode.EditMode; addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); //test Save Command can run Assert.AreEqual(addEditCustomerViewModel.SaveCustomerCommand.CanExecute(null), true); //Execute SaveCustomerCommand addEditCustomerViewModel.SaveCustomerCommand.Execute(null); Assert.AreEqual(addEditCustomerViewModel.SaveCustomerCommand.CommandSucceeded, true); #endregion }
public void DeleteOrderTest() { AddEditCustomerViewModel addEditCustomerViewModel = new AddEditCustomerViewModel(); //Test Command can't run without an order Assert.AreEqual(addEditCustomerViewModel.DeleteOrderCommand.CanExecute(null), false); addEditCustomerViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); //As setting the AddEditCustomerViewModel.CurrentCustomer causes //a background fetch of all CurrentCustomer.Orders, we need to wait //until that completes to continue ManualResetEvent manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); addEditCustomerViewModel.CurrentCustomerOrder = addEditCustomerViewModel.CurrentCustomer.Orders.First(); addEditCustomerViewModel.CurrentCustomerOrder.Quantity.DataValue = 1; //Test that DeleteOrderCommand can now Execute Assert.AreEqual(addEditCustomerViewModel.DeleteOrderCommand.CanExecute(null), true); #region Test NO, delete MessageBox option //Run the DeleteOrderCommand, with a NO, Do not delete MessageBox option Queued up TestMessageBoxService testMessageBoxService = (TestMessageBoxService) ViewModelBase.ServiceProvider.Resolve <IMessageBoxService>(); //Queue up the response we expect for our given TestMessageBoxService //for a given ICommand/Method call within the test ViewModel testMessageBoxService.ShowYesNoResponders.Enqueue (() => { return(CustomDialogResults.No); } ); Int32 existingCustomerOrdersCount = addEditCustomerViewModel.CurrentCustomer.Orders.Count(); addEditCustomerViewModel.DeleteOrderCommand.Execute(null); //Clear the TestMessageBoxService.ShowYesNoResponders testMessageBoxService.ShowYesNoResponders.Clear(); Assert.AreEqual(existingCustomerOrdersCount, addEditCustomerViewModel.CurrentCustomer.Orders.Count()); #endregion #region Test YES, delete MessageBox option //Run the DeleteOrderCommand, with a YES, Do delete MessageBox option Queued up //Queue up the response we expect for our given TestMessageBoxService //for a given ICommand/Method call within the test ViewModel testMessageBoxService.ShowYesNoResponders.Enqueue (() => { return(CustomDialogResults.Yes); } ); existingCustomerOrdersCount = addEditCustomerViewModel.CurrentCustomer.Orders.Count(); addEditCustomerViewModel.DeleteOrderCommand.Execute(null); //Clear the TestMessageBoxService.ShowYesNoResponders testMessageBoxService.ShowYesNoResponders.Clear(); manualEvent = new ManualResetEvent(false); addEditCustomerViewModel.BgWorker.BackgroundTaskCompleted += delegate(object sender, EventArgs args) { // Signal the waiting NUnit thread that we're ready to move on. manualEvent.Set(); }; //Wait for signal to move on from BackgroundTaskManager.BackgroundTaskCompleted manualEvent.WaitOne(5000, false); Assert.AreEqual(existingCustomerOrdersCount - 1, addEditCustomerViewModel.CurrentCustomer.Orders.Count()); #endregion }