public void AddCustomerCommand_Test() { MainWindowViewModel mainWindowVM = new MainWindowViewModel(); mainWindowVM.Workspaces.Add(new AddEditCustomerViewModel()); mainWindowVM.Workspaces.Add(new SearchCustomersViewModel()); //MainWindowViewModel.Workspaces starts out //with a StartPageViewModel already present Assert.AreEqual(mainWindowVM.Workspaces.Count(), 3); //Now remove all the current AddEditCustomerViewModel //from the list of Workspaces in MainWindowViewModel var addEditCustomerVM = mainWindowVM.Workspaces.Where(x => x.GetType() == typeof(AddEditCustomerViewModel)).FirstOrDefault(); mainWindowVM.Workspaces.Remove(addEditCustomerVM); Assert.AreEqual(mainWindowVM.Workspaces.Count(), 2); //Create a new StartPageViewModel and test its AddCustomerCommand //is able to add a new Workspace item to the MainWindowViewModel StartPageViewModel startPageVM = new StartPageViewModel(); //Test AddCustomerCommand : Should be able //to add a new AddEditCustomerViewModel startPageVM.AddCustomerCommand.Execute(null); Assert.AreEqual(mainWindowVM.Workspaces.Count(), 3); }
public void CheckNoMoreWorkSpacesCanBeAdded() { MainWindowViewModel mainWindowVM = new MainWindowViewModel(); mainWindowVM.Workspaces.Add(new AddEditCustomerViewModel()); mainWindowVM.Workspaces.Add(new SearchCustomersViewModel()); //MainWindowViewModel.Workspaces starts out //with a StartPageViewModel already present Assert.AreEqual(mainWindowVM.Workspaces.Count(), 3); //Create a new StartPageViewModel and test its command //to ensure that they do no effect the number of workspace //items in the MainWindowViewModel StartPageViewModel startPageVM = new StartPageViewModel(); //Test AddCustomerCommand : Should not be able //to add a new AddEditCustomerViewModel startPageVM.AddCustomerCommand.Execute(null); Assert.AreEqual(mainWindowVM.Workspaces.Count(), 3); //Test SearchCustomersViewModel : Should not be able //to add a new SearchCustomersViewModel startPageVM.SearchCustomersCommand.Execute(null); Assert.AreEqual(mainWindowVM.Workspaces.Count(), 3); }
public MainWindowViewModel() { Workspaces = new ObservableCollection <ViewModelBase>(); Workspaces.CollectionChanged += this.OnWorkspacesChanged; StartPageViewModel startPageViewModel = new StartPageViewModel(); startPageViewModel.IsCloseable = false; Workspaces.Add(startPageViewModel); #region Obtain Services try { messageBoxService = Resolve <IMessageBoxService>(); } catch { Logger.Log(LogType.Error, "Error resolving services"); throw new ApplicationException("Error resolving services"); } #endregion #region Create Commands //Create exit application command exitApplicationCommand = new SimpleCommand { CanExecuteDelegate = x => true, ExecuteDelegate = x => ExecuteExitApplicationCommand() }; //Create Add Cusomer command addCustomerCommand = new SimpleCommand { CanExecuteDelegate = x => true, ExecuteDelegate = x => ExecuteAddCustomerCommand() }; //Create Search Customers command searchCustomersCommand = new SimpleCommand { CanExecuteDelegate = x => true, ExecuteDelegate = x => ExecuteSearchCusomersCommand() }; #endregion }