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 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 SaveOrderCommandTest() { AddEditOrderViewModel addEditOrderViewModel = new AddEditOrderViewModel(); //Test Command can't run without an order Assert.AreEqual(addEditOrderViewModel.SaveOrderCommand.CanExecute(null), false); #region AddMode addEditOrderViewModel.CurrentViewMode = ViewMode.AddMode; addEditOrderViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); addEditOrderViewModel.CurrentCustomerOrder = OrderModel.OrderToOrderModel(ord); //test Save Command can run Assert.AreEqual(addEditOrderViewModel.SaveOrderCommand.CanExecute(null), true); //Execute SaveCommand addEditOrderViewModel.SaveOrderCommand.Execute(null); Assert.Greater(addEditOrderViewModel.CurrentCustomerOrder.OrderId.DataValue, 0); #endregion #region EditMode addEditOrderViewModel.CurrentViewMode = ViewMode.EditMode; addEditOrderViewModel.CurrentCustomer = CustomerModel.CustomerToCustomerModel(cust); Order o = DataAccess.DataService.FetchAllOrders(cust.CustomerId).First(); addEditOrderViewModel.CurrentCustomerOrder = OrderModel.OrderToOrderModel(o); //test Save Command can run Assert.AreEqual(addEditOrderViewModel.SaveOrderCommand.CanExecute(null), true); //Execute SaveCommand addEditOrderViewModel.SaveOrderCommand.Execute(null); Assert.AreEqual(addEditOrderViewModel.SaveOrderCommand.CommandSucceeded, true); #endregion }
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 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 }