public void ExecutionPanel_StopExecutionCommand_CanExecute_WithContext() { ExecutionPanel panel = new ExecutionPanel { ExecutionContext = new ExecutionContext(Mock.Of <GeneticAlgorithm>()) }; foreach (ExecutionState enumVal in Enum.GetValues(typeof(ExecutionState))) { panel.ExecutionContext.ExecutionState = enumVal; bool result = ExecutionPanel.StopExecutionCommand.CanExecute(null, panel); switch (enumVal) { case ExecutionState.Running: case ExecutionState.Paused: Assert.True(result); break; default: Assert.False(result); break; } } }
public void ExecutionPanel_StopExecutionCommand_CanExecute_NoContext() { ExecutionPanel panel = new ExecutionPanel(); bool result = ExecutionPanel.StopExecutionCommand.CanExecute(null, panel); Assert.False(result); }
public void ExecutionPanel_StopExecutionCommand_Execute_FromPaused() { ExecutionPanel panel = new ExecutionPanel { ExecutionContext = new ExecutionContext(Mock.Of <GeneticAlgorithm>()) }; panel.ExecutionContext.ExecutionState = ExecutionState.Paused; panel.ViewModel.StopExecution(); Assert.Equal(ExecutionState.Idle, panel.ExecutionContext.ExecutionState); }
public void ExecutionPanel_PauseExecutionCommand_Execute() { ExecutionPanel panel = new ExecutionPanel { ExecutionContext = new ExecutionContext(Mock.Of <GeneticAlgorithm>()) }; panel.ExecutionContext.ExecutionState = ExecutionState.Running; panel.ViewModel.PauseExecution(); Assert.Equal(ExecutionState.PausePending, panel.ExecutionContext.ExecutionState); }
public void ExecutionPanel_StartExecutionCommand_Execute() { ExecutionPanel panel = new ExecutionPanel { ExecutionContext = new ExecutionContext(CreateTestAlgorithm(true)) }; ExecutionPanel.StartExecutionCommand.Execute(null, panel); DispatcherHelper.DoEvents(); TestHelper.WaitForResult(ExecutionState.Running, () => panel.ExecutionContext.ExecutionState); // Trigger the algorithm to complete ((TestTerminator)panel.ExecutionContext.GeneticAlgorithm.Terminator).IsCompleteValue = true; }
public void ExecutionPanel_ExecutionContext_Overwrite() { ExecutionPanel panel = new ExecutionPanel(); GeneticAlgorithm algorithm = CreateTestAlgorithm(runsInfinitely: true); ExecutionContext context = new ExecutionContext(algorithm); panel.ExecutionContext = context; // Start execution to force event handlers to be added in order to // verify they are removed when replacing the ExecutionContext. ExecutionPanel.StartExecutionCommand.Execute(null, panel); DispatcherHelper.DoEvents(); TestHelper.WaitForResult(ExecutionState.Running, () => panel.ExecutionContext.ExecutionState); Mock <GeneticAlgorithm> algorithmMock2 = new Mock <GeneticAlgorithm>(); ExecutionContext context2 = new ExecutionContext(algorithmMock2.Object) { ExecutionState = ExecutionState.Running }; panel.ExecutionContext = context2; Assert.False(panel.CanStart); Assert.True(panel.CanStop); Assert.True(panel.CanPause); // Verify the panel does not respond to the original context changing context.ExecutionState = ExecutionState.Idle; Assert.False(panel.CanStart); Assert.True(panel.CanStop); Assert.True(panel.CanPause); // Verify the panel does respond to the new context changing context2.ExecutionState = ExecutionState.Idle; Assert.True(panel.CanStart); Assert.False(panel.CanStop); Assert.False(panel.CanPause); }
public void ExecutionPanel_ExecutionContext() { ExecutionPanel panel = new ExecutionPanel(); ExecutionContext context = new ExecutionContext(Mock.Of <GeneticAlgorithm>()) { ExecutionState = ExecutionState.Running }; panel.ExecutionContext = context; Assert.False(panel.CanStart); Assert.True(panel.CanStop); Assert.True(panel.CanPause); // Verify an event handler was added to respond to the context changing its ExecutionState context.ExecutionState = ExecutionState.Idle; Assert.True(panel.CanStart); Assert.False(panel.CanStop); Assert.False(panel.CanPause); }
public void ExecutionPanel_Ctor() { ExecutionPanel panel = new ExecutionPanel(); Assert.Equal(4, panel.CommandBindings.Count); Assert.Equal( new RoutedCommand[] { ExecutionPanel.StartExecutionCommand, ExecutionPanel.StepExecutionCommand, ExecutionPanel.PauseExecutionCommand, ExecutionPanel.StopExecutionCommand, } .OrderBy(c => c.Name), panel.CommandBindings .Cast <CommandBinding>() .Select(c => c.Command) .Cast <RoutedCommand>() .OrderBy(c => c.Name) .ToList()); }
public void ExecutionPanel_StepExecutionCommand_Execute() { using SemaphoreSlim algorithmPausedSemaphore = new SemaphoreSlim(0); Dispatcher.CurrentDispatcher.Invoke(async() => { ExecutionPanel panel = new ExecutionPanel { ExecutionContext = new ExecutionContext(CreateTestAlgorithm(true)) }; using var algorithmPausedObservable = Observable .FromEventPattern <PropertyChangedEventHandler, PropertyChangedEventArgs>( ev => panel.ExecutionContext.PropertyChanged += ev, ev => panel.ExecutionContext.PropertyChanged -= ev) .Where(eventPattern => ((ExecutionContext)eventPattern.Sender).ExecutionState == ExecutionState.Paused) .Subscribe(_ => algorithmPausedSemaphore.Release()); await panel.ViewModel.StepExecutionAsync(); }); DispatcherHelper.DoEvents(); Assert.True(algorithmPausedSemaphore.Wait(TimeSpan.FromSeconds(10))); }