public void ExecuteAndCommandParameterTest() { var service = new TestMessageBoxService(); object executeCommandParameter = null; object canExecuteCommandParameter = null; DelegateCommand <object> command = new DelegateCommand <object>( x => { executeCommandParameter = x; }, x => { canExecuteCommandParameter = x; return(true); }); ConfirmationBehavior b = new ConfirmationBehavior(); b.MessageBoxService = service; Button control = new Button(); Interaction.GetBehaviors(control).Add(b); b.Command = command; object controlCommandParameter = new object(); control.CommandParameter = controlCommandParameter; Assert.IsNull(executeCommandParameter); control.Command.Execute(controlCommandParameter); Assert.AreEqual(controlCommandParameter, executeCommandParameter); Assert.AreEqual(controlCommandParameter, canExecuteCommandParameter); object confirmationBehaviorCommandParameter = new object(); b.CommandParameter = confirmationBehaviorCommandParameter; Assert.AreEqual(controlCommandParameter, executeCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter); control.Command.Execute(controlCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, executeCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter); }
public void ShouldCanExecuteIfStateIsNotChanging(Services.PortState portState) { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService { PortState = portState }; var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); viewModel.ConnectionCommand.CanExecute(null).Should().BeTrue(); }
public void ExecuteAndMessageBoxServiceTest() { int executeCount = 0; DelegateCommand command = new DelegateCommand(() => executeCount++, () => true); TestMessageBoxService service = new TestMessageBoxService(); Button control = new Button(); ConfirmationBehavior b = new ConfirmationBehavior(); b.Command = command; Interaction.GetBehaviors(control).Add(b); b.MessageBoxService = service; control.Command.Execute(null); Assert.AreEqual(1, executeCount); Assert.AreEqual(1, service.ShowCount); Assert.AreEqual("Confirmation", service.Caption); Assert.AreEqual("Do you want to perform this action?", service.MessageBoxTest); #if !SILVERLIGHT Assert.AreEqual(MessageIcon.None, service.Icon); Assert.AreEqual(MessageButton.YesNo, service.Button); #else Assert.AreEqual(MessageButton.OKCancel, service.Button); #endif Assert.AreEqual(MessageResult.None, service.DefaultResult); b.MessageText = "MessageText"; b.MessageTitle = "MessageTitle"; #if !SILVERLIGHT b.MessageIcon = MessageBoxImage.Hand; #endif b.MessageButton = MessageBoxButton.OKCancel; b.MessageDefaultResult = MessageBoxResult.Cancel; service.Result = MessageResult.OK; control.Command.Execute(null); Assert.AreEqual(2, executeCount); Assert.AreEqual(2, service.ShowCount); Assert.AreEqual("MessageTitle", service.Caption); Assert.AreEqual("MessageText", service.MessageBoxTest); #if !SILVERLIGHT Assert.AreEqual(MessageIcon.Hand, service.Icon); #endif Assert.AreEqual(MessageButton.OKCancel, service.Button); Assert.AreEqual(MessageResult.Cancel, service.DefaultResult); service.Result = MessageResult.Cancel; control.Command.Execute(null); Assert.AreEqual(2, executeCount); Assert.AreEqual(3, service.ShowCount); }
public async void ShouldNotShowMessageIfOpenedResultIsReceived() { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService(); hartCommunicationService.OpenAsyncResponders.Enqueue(() => OpenResult.Opened); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); messageBoxService.ShowInformationRequests.Count.Should().Be(0); }
public async void ShouldShowMessageIfNotOpenedIsReceived(OpenResult openResult) { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService(); hartCommunicationService.OpenAsyncResponders.Enqueue(() => openResult); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); messageBoxService.ShowInformationRequests.Count.Should().Be(1); messageBoxService.ShowInformationRequests[0].Message.Should().NotBeNullOrEmpty(); }
public void DisableConfirmationMessage() { int executeCount = 0; DelegateCommand command = new DelegateCommand(() => executeCount++, () => true); TestMessageBoxService service = new TestMessageBoxService(); Button control = new Button(); ConfirmationBehavior b = new ConfirmationBehavior(); b.Command = command; Interaction.GetBehaviors(control).Add(b); b.MessageBoxService = service; b.EnableConfirmationMessage = false; control.Command.Execute(null); Assert.AreEqual(1, executeCount); Assert.AreEqual(0, service.ShowCount); Assert.IsNull(service.Caption); Assert.IsNull(service.MessageBoxTest); }
public async void ShouldCallCloseIfStateIsOpened() { var messageBoxService = new TestMessageBoxService(); var hartCommunicationService = new TestHartCommunicationService { PortState = Services.PortState.Opened }; hartCommunicationService.CloseAsyncResponders.Enqueue(() => CloseResult.Closed); var viewModel = new RibbonViewModel(new ApplicationServices { HartCommunicationService = hartCommunicationService }, new CommonServices { MessageBoxService = messageBoxService }); await viewModel.ConnectionCommand.Execute(null); hartCommunicationService.OpenAsyncResponders.Count.Should().Be(0); }
public void DisableConfirmationMessage() { int executeCount = 0; DelegateCommand command = new DelegateCommand(() => executeCount++, () => true); TestMessageBoxService service = new TestMessageBoxService(); Button control = new Button(); ConfirmationBehavior b = new ConfirmationBehavior(); b.Command = command; Interaction.GetBehaviors(control).Add(b); b.MessageBoxService = service; b.EnableConfirmationMessage = false; control.Command.Execute(null); Assert.AreEqual(1, executeCount); Assert.AreEqual(0, service.ShowCount); Assert.IsNull(service.Caption); Assert.IsNull(service.MessageBoxTest); }
public void ExecuteAndMessageBoxServiceTest() { int executeCount = 0; DelegateCommand command = new DelegateCommand(() => executeCount++, () => true); TestMessageBoxService service = new TestMessageBoxService(); Button control = new Button(); ConfirmationBehavior b = new ConfirmationBehavior(); b.Command = command; Interaction.GetBehaviors(control).Add(b); b.MessageBoxService = service; control.Command.Execute(null); Assert.AreEqual(1, executeCount); Assert.AreEqual(1, service.ShowCount); Assert.AreEqual("Confirmation", service.Caption); Assert.AreEqual("Do you want to perform this action?", service.MessageBoxTest); #if !SILVERLIGHT Assert.AreEqual(MessageIcon.None, service.Icon); Assert.AreEqual(MessageButton.YesNo, service.Button); #else Assert.AreEqual(MessageButton.OKCancel, service.Button); #endif Assert.AreEqual(MessageResult.None, service.DefaultResult); b.MessageText = "MessageText"; b.MessageTitle = "MessageTitle"; #if !SILVERLIGHT b.MessageIcon = MessageBoxImage.Hand; #endif b.MessageButton = MessageBoxButton.OKCancel; b.MessageDefaultResult = MessageBoxResult.Cancel; service.Result = MessageResult.OK; control.Command.Execute(null); Assert.AreEqual(2, executeCount); Assert.AreEqual(2, service.ShowCount); Assert.AreEqual("MessageTitle", service.Caption); Assert.AreEqual("MessageText", service.MessageBoxTest); #if !SILVERLIGHT Assert.AreEqual(MessageIcon.Hand, service.Icon); #endif Assert.AreEqual(MessageButton.OKCancel, service.Button); Assert.AreEqual(MessageResult.Cancel, service.DefaultResult); service.Result = MessageResult.Cancel; control.Command.Execute(null); Assert.AreEqual(2, executeCount); Assert.AreEqual(3, service.ShowCount); }
public void ExecuteAndCommandParameterTest() { var service = new TestMessageBoxService(); object executeCommandParameter = null; object canExecuteCommandParameter = null; DelegateCommand<object> command = new DelegateCommand<object>( x => { executeCommandParameter = x; }, x => { canExecuteCommandParameter = x; return true; }); ConfirmationBehavior b = new ConfirmationBehavior(); b.MessageBoxService = service; Button control = new Button(); Interaction.GetBehaviors(control).Add(b); b.Command = command; object controlCommandParameter = new object(); control.CommandParameter = controlCommandParameter; Assert.IsNull(executeCommandParameter); control.Command.Execute(controlCommandParameter); Assert.AreEqual(controlCommandParameter, executeCommandParameter); Assert.AreEqual(controlCommandParameter, canExecuteCommandParameter); object confirmationBehaviorCommandParameter = new object(); b.CommandParameter = confirmationBehaviorCommandParameter; Assert.AreEqual(controlCommandParameter, executeCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter); control.Command.Execute(controlCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, executeCommandParameter); Assert.AreEqual(confirmationBehaviorCommandParameter, canExecuteCommandParameter); }
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 }