public void Matches_OrStepWithTwoPropertySteps_MatchesIfOneOfThePropertiesMatches() { var selectedProjectStep = CreatePropertyStep((EmployeeVMDescriptor x) => x.SelectedProject); var nameStep = CreatePropertyStep((EmployeeVMDescriptor x) => x.Name); var orStep = new OrStep(selectedProjectStep, nameStep); var definition = PathDefinition .Empty .Append(orStep); var projectVM = new ProjectVM(); var rootVM = new EmployeeVM(); rootVM.SetValue(x => x.SelectedProject, projectVM); var namePath = Path .Empty .Append(rootVM) .Append(EmployeeVM.ClassDescriptor.Name); var match = definition.Matches(namePath); Assert.IsTrue(match.Success); var selectedProjectPath = Path .Empty .Append(rootVM) .Append(EmployeeVM.ClassDescriptor.SelectedProject); match = definition.Matches(namePath); Assert.IsTrue(match.Success); }
public void Matches_ComplexOrStep() { var projectsStep = CreatePropertyStep((EmployeeVMDescriptor x) => x.Projects); var anotherProjects = CreatePropertyStep((EmployeeVMDescriptor x) => x.AnotherProjects); var orStep = new OrStep(projectsStep, anotherProjects); var definition = PathDefinition .Empty .Append(orStep) .Append((ProjectVMDescriptor x) => x.Name); var projectVM1 = new ProjectVM(); var projectVM2 = new ProjectVM(); var rootVM = new EmployeeVM(); rootVM.GetValue(x => x.Projects).Add(projectVM1); rootVM.GetValue(x => x.AnotherProjects).Add(projectVM2); var projectPath = Path .Empty .Append(rootVM) .Append(rootVM.GetValue(x => x.Projects).First()) .Append(ProjectVM.ClassDescriptor.Name); var match = definition.Matches(projectPath); Assert.IsTrue(match.Success); var anotherProjectPath = Path .Empty .Append(rootVM) .Append(rootVM.GetValue(x => x.AnotherProjects).First()) .Append(ProjectVM.ClassDescriptor.Name); match = definition.Matches(anotherProjectPath); Assert.IsTrue(match.Success); }
public OrStepInstance(ProfileInstance profileInstance, StepInstance parentStepInstance, OrStep step) : base(profileInstance, parentStepInstance, step) { const string method = ".ctor"; var currentPercentage = 0; var enabledSteps = 0; foreach (var childStep in step) { currentPercentage += childStep.Percentage * 100; if (childStep.Enabled) { ++enabledSteps; } _percentages.Add(currentPercentage); } // Check the percentages. if (currentPercentage != 10000) { throw new InvalidConfigurationValueException(GetType(), method, "percentage", currentPercentage / 100); } if (enabledSteps == 0) { throw new InvalidConfigurationValueException(GetType(), method, "enabled", false); } }
private StepInstance CreateStepInstance(Profile profile, ProfileCounters counters, StepInstance parentStepInstance, OrStep step) { var stepInstance = new OrStepInstance(this, parentStepInstance, step); CreateChildStepInstances(stepInstance, step, profile, counters); return(stepInstance); }