public void AssertExecutionProgress(IProgressStep step, params Tuple<string, double>[] expectedSequence) { List<StepExecutionChangedEventArgs> changes = this.executionChanges[step]; Assert.IsNotNull(changes, "Cannot find the changes list for the specified step"); Tuple<string, double>[] actualSequence = changes.Where(c => c.State == StepExecutionState.Executing).Select(c => Tuple.Create(c.ProgressDetailText, c.Progress)).ToArray(); VerifyProgressSequence(!step.Indeterminate, expectedSequence, actualSequence); }
private static void VerifyStep(ProgressStepViewModel vm, IProgressStep step) { vm.DisplayText.Should().Be(step.DisplayText, "DisplayText doesn't match"); vm.ExecutionState.Should().Be(step.ExecutionState, "ExecutionState doesn't match"); vm.Progress.Value.Should().Be(step.Progress, "Progress doesn't match"); vm.ProgressDetailText.Should().Be(step.ProgressDetailText, "ProgressDisplayText doesn't match"); vm.Progress.IsIndeterminate.Should().Be(step.Indeterminate, "Indeterminate doesn't match"); }
public void AssertExecutionProgress(IProgressStep step, params Tuple <string, double>[] expectedSequence) { List <StepExecutionChangedEventArgs> changes = this.executionChanges[step]; changes.Should().NotBeNull("Cannot find the changes list for the specified step"); Tuple <string, double>[] actualSequence = changes.Where(c => c.State == StepExecutionState.Executing).Select(c => Tuple.Create(c.ProgressDetailText, c.Progress)).ToArray(); VerifyProgressSequence(!step.Indeterminate, expectedSequence, actualSequence); }
/// <summary> /// The method should be used to constructed the expected groups of steps /// </summary> /// <param name="group">The target group index</param> /// <param name="step">The step to add to a group</param> public void AppendStepToGroup(int group, IProgressStep step) { List <IProgressStep> orderedSteps; if (!this.groups.TryGetValue(group, out orderedSteps)) { this.groups[group] = orderedSteps = new List <IProgressStep>(); } orderedSteps.Add(step); }
/// <summary> /// Returns all the steps which are in the same group as the specified step /// </summary> /// <param name="step">Step to check</param> /// <returns>All the steps in a group with the specified step</returns> private IProgressStep[] GetAllStepsInGroup(IProgressStep step) { foreach (var keyValue in this.groups) { if (keyValue.Value.Contains(step)) { return(keyValue.Value.ToArray()); } } return(null); }
/// <summary> /// Returns whether the specified step is the last in group /// </summary> /// <param name="step">Step to check</param> /// <returns>Whether the specified step is the last in group</returns> private bool IsLastStep(IProgressStep step) { foreach (var keyValue in this.groups) { if (keyValue.Value.IndexOf(step) == keyValue.Value.Count - 1) { return(true); } } return(false); }
public StepExecutionChangedEventArgs(IProgressStep step) { if (step == null) { throw new ArgumentNullException(nameof(step)); } this.Step = step; this.State = step.ExecutionState; this.Progress = step.Progress; this.ProgressDetailText = step.ProgressDetailText; }
public void AssertStepCorrectExecution(IProgressStep step, StepExecutionState finalState) { if (finalState == StepExecutionState.NotStarted) { Assert.IsFalse(this.executionChanges.ContainsKey(step), "Not expecting any changes for a step that was not started"); } else { List<StepExecutionChangedEventArgs> changes = this.executionChanges[step]; Assert.IsNotNull(changes, "Cannot find the changes list for the specified step"); VerifyStateTransitions(changes.Select(e => e.State).ToArray(), finalState); } }
public void AssertStepCorrectExecution(IProgressStep step, StepExecutionState finalState) { if (finalState == StepExecutionState.NotStarted) { this.executionChanges.Should().NotContainKey(step, "Not expecting any changes for a step that was not started"); } else { List <StepExecutionChangedEventArgs> changes = this.executionChanges[step]; changes.Should().NotBeNull("Cannot find the changes list for the specified step"); VerifyStateTransitions(changes.Select(e => e.State).ToArray(), finalState); } }
/// <summary> /// Sets the initial state of a <see cref="ProgressStepViewModel"/> /// </summary> /// <param name="viewModel">The <see cref="ProgressStepViewModel"/> instance to initialize</param> /// <param name="group">The logical group which the <see cref="ProgressStepViewModel"/> represent</param> private static void InitializeStep(ProgressStepViewModel viewModel, ExecutionGroup group) { ThreadHelper.ThrowIfNotOnUIThread(); IProgressStep first = group.Steps.First(); IProgressStep nonHiddenStep = group.Steps.FirstOrDefault(s => !s.Hidden); Debug.Assert(nonHiddenStep != null, "The execution group has no visible steps"); viewModel.DisplayText = nonHiddenStep.DisplayText; viewModel.ExecutionState = first.ExecutionState; viewModel.Progress.SetUpperBoundLimitedValue(first.Progress); viewModel.ProgressDetailText = first.ProgressDetailText; viewModel.Progress.IsIndeterminate = group.Steps.Any(s => s.Indeterminate); }
/// <summary> /// Returns whether the specified step is the last in group /// </summary> /// <param name="step">Step to check</param> /// <returns>Whether the specified step is the last in group</returns> private bool IsLastStep(IProgressStep step) { foreach (var keyValue in this.groups) { if (keyValue.Value.IndexOf(step) == keyValue.Value.Count - 1) { return true; } } return false; }
public void RunAndVerifyExecutingStep(ConfigurableProgressEvents progressEvents, IProgressStep currentStep, int? currentVmIndex) { ProgressStepViewModel currentVM = currentVmIndex.HasValue ? this.visualizer.ViewModel.Steps[currentVmIndex.Value] : null; bool isFinalState = ProgressControllerHelper.IsFinalState(currentStep.ExecutionState) && this.IsLastStep(currentStep); // Trigger the event progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(currentStep)); // Verify if (currentVmIndex.HasValue) { VerifyProgress(this.visualizer, this.ExpectedMainProgress, currentVM, this.ExpectedSubProgress); if (isFinalState) { Assert.IsNull(this.testSubject.CurrentExecutingGroup, "Not expecting any executing group"); } else { IProgressStep[] steps = this.GetAllStepsInGroup(currentStep); if (currentStep.ImpactsProgress) { Assert.IsNotNull(steps, "There should be at least one step in the group"); VerifyExecutionGroup(this.testSubject.CurrentExecutingGroup, steps); } else { Assert.IsNull(steps, "Not expecting any steps in group since not impacting, so there's no group for it"); } } } else { Assert.IsNull(currentVM, "Current VM should be null, since not impacts progress"); Assert.IsTrue(this.testSubject.CurrentExecutingGroup == null || this.testSubject.CurrentExecutingGroup.ExecutingStep == null, "Not expecting any changes for non impacting steps"); } }
/// <summary> /// The method should be used to constructed the expected groups of steps /// </summary> /// <param name="group">The target group index</param> /// <param name="step">The step to add to a group</param> public void AppendStepToGroup(int group, IProgressStep step) { List<IProgressStep> orderedSteps; if (!this.groups.TryGetValue(group, out orderedSteps)) { this.groups[group] = orderedSteps = new List<IProgressStep>(); } orderedSteps.Add(step); }
private static void VerifyStep(ProgressStepViewModel vm, IProgressStep step) { Assert.AreEqual(step.DisplayText, vm.DisplayText, "DisplayText doesn't match"); Assert.AreEqual(step.ExecutionState, vm.ExecutionState, "ExecutionState doesn't match"); Assert.AreEqual(step.Progress, vm.Progress.Value, "Progress doesn't match"); Assert.AreEqual(step.ProgressDetailText, vm.ProgressDetailText, "ProgressDisplayText doesn't match"); Assert.AreEqual(step.Indeterminate, vm.Progress.IsIndeterminate, "Indeterminate doesn't match"); }
public void RunAndVerifyExecutingStep(ConfigurableProgressEvents progressEvents, IProgressStep currentStep, int?currentVmIndex) { ProgressStepViewModel currentVM = currentVmIndex.HasValue ? this.visualizer.ViewModel.Steps[currentVmIndex.Value] : null; bool isFinalState = ProgressControllerHelper.IsFinalState(currentStep.ExecutionState) && this.IsLastStep(currentStep); // Trigger the event progressEvents.InvokeStepExecutionChanged(new StepExecutionChangedEventArgs(currentStep)); // Verify if (currentVmIndex.HasValue) { VerifyProgress(this.visualizer, this.ExpectedMainProgress, currentVM, this.ExpectedSubProgress); if (isFinalState) { Assert.IsNull(this.testSubject.CurrentExecutingGroup, "Not expecting any executing group"); } else { IProgressStep[] steps = this.GetAllStepsInGroup(currentStep); if (currentStep.ImpactsProgress) { Assert.IsNotNull(steps, "There should be at least one step in the group"); VerifyExecutionGroup(this.testSubject.CurrentExecutingGroup, steps); } else { Assert.IsNull(steps, "Not expecting any steps in group since not impacting, so there's no group for it"); } } } else { Assert.IsNull(currentVM, "Current VM should be null, since not impacts progress"); Assert.IsTrue(this.testSubject.CurrentExecutingGroup == null || this.testSubject.CurrentExecutingGroup.ExecutingStep == null, "Not expecting any changes for non impacting steps"); } }
/// <summary> /// Checks the current state of a <see cref="IProgressStep"/> /// </summary> /// <param name="testSubject">The step to check</param> /// <param name="expectedState">The expected state of the step</param> public static void CheckState(IProgressStep testSubject, StepExecutionState expectedState) { testSubject.ExecutionState.Should().Be(expectedState, "Unexpected state"); }
/// <summary> /// Returns all the steps which are in the same group as the specified step /// </summary> /// <param name="step">Step to check</param> /// <returns>All the steps in a group with the specified step</returns> private IProgressStep[] GetAllStepsInGroup(IProgressStep step) { foreach (var keyValue in this.groups) { if (keyValue.Value.Contains(step)) { return keyValue.Value.ToArray(); } } return null; }
/// <summary> /// Checks the current state of a <see cref="IProgressStep"/> /// </summary> /// <param name="testSubject">The step to check</param> /// <param name="expectedState">The expected state of the step</param> public static void CheckState(IProgressStep testSubject, StepExecutionState expectedState) { Assert.AreEqual(expectedState, testSubject.ExecutionState, "Unexpected state"); }