public void StopStep_should_map_value_types_to_FlowTemplateStepDto() { var step = new StopStep { Id = 2, Name = "Example StopStep" }; var result = Mapper.Map <FlowTemplateStepDto>(step); Assert.IsType <FlowTemplateStepDto>(result); Assert.Equal(2, result.Id); Assert.Equal("Example StopStep", result.Name); Assert.Equal("StopStep", result.StepTypeName); }
public void Should_map_StopStep_value_typesto_FlowTemplateStep() { var step = new StopStep { Id = 22, Name = "Stop Step 2" }; // Act var result = Mapper.Map <FlowTemplateStep>(step); // Assert Assert.IsType <FlowTemplateStep>(result); Assert.Equal(22, result.Id); Assert.Equal("Stop Step 2", result.Name); Assert.Equal(2, result.StepTypeId); }
private static bool LoadProcessSteps(UserProcess process, List <StepDTO> steps, Dictionary <string, Process> processesByName, List <string> errors) { var stepsById = new Dictionary <string, Step>(); var stepsWithInputs = new List <Tuple <StepDTO, Step, IReadOnlyList <Parameter> > >(); var stepsWithOutputs = new List <Tuple <StepDTO, ReturningStep, IReadOnlyList <Parameter> > >(); int initialErrorCount = errors.Count; foreach (var stepData in steps) { if (stepsById.ContainsKey(stepData.ID)) { errors.Add($"Process \"{process.Name}\" has multiple steps with ID {stepData.ID}"); continue; } switch (stepData.Type) { case "start": { var step = new StartStep(stepData.ID); if (process.FirstStep == null) { process.FirstStep = step; } else { errors.Add($"Process \"{process.Name}\" has multiple start steps"); } stepsWithOutputs.Add(new Tuple <StepDTO, ReturningStep, IReadOnlyList <Parameter> >(stepData, step, process.Inputs)); stepsById.Add(step.ID, step); break; } case "stop": { var step = new StopStep(stepData.ID, stepData.PathName); stepsWithInputs.Add(new Tuple <StepDTO, Step, IReadOnlyList <Parameter> >(stepData, step, process.Outputs)); stepsById.Add(step.ID, step); break; } case "process": { if (!processesByName.TryGetValue(stepData.InnerProcess, out Process innerProcess)) { errors.Add($"Unrecognised process \"{stepData.InnerProcess}\" on step {stepData.ID} in process \"{process.Name}\""); break; } var step = new UserStep(stepData.ID, innerProcess); stepsWithInputs.Add(new Tuple <StepDTO, Step, IReadOnlyList <Parameter> >(stepData, step, innerProcess.Inputs)); stepsWithOutputs.Add(new Tuple <StepDTO, ReturningStep, IReadOnlyList <Parameter> >(stepData, step, innerProcess.Outputs)); stepsById.Add(step.ID, step); break; } default: errors.Add($"Invalid type \"{stepData.Type}\" on step {stepData.ID} in process \"{process.Name}\""); break; } } var variablesByName = process.Variables.ToDictionary(v => v.Name); foreach (var stepInfo in stepsWithInputs) { var stepData = stepInfo.Item1; var step = stepInfo.Item2; var parameters = stepInfo.Item3; if (stepData.Inputs != null) { MapParameters(stepData.Inputs, step, parameters, variablesByName, process, true, errors); } } foreach (var stepInfo in stepsWithOutputs) { var stepData = stepInfo.Item1; var step = stepInfo.Item2; var parameters = stepInfo.Item3; if (stepData.Outputs != null) { MapParameters(stepData.Outputs, step, parameters, variablesByName, process, false, errors); } if (stepData.ReturnPath != null) { if (stepsById.TryGetValue(stepData.ReturnPath, out Step destStep)) { step.DefaultReturnPath = destStep; } else { errors.Add($"Step {step.ID} in process \"{process.Name}\" tries to connect to non-existent step \"{stepData.ReturnPath}\""); } } else if (stepData.ReturnPaths != null && step is UserStep userStep) { var expectedReturnPaths = userStep.ChildProcess.ReturnPaths; var mappedPaths = new HashSet <string>(); foreach (var returnPath in stepData.ReturnPaths) { if (!expectedReturnPaths.Contains(returnPath.Key)) { errors.Add($"Step {step.ID} in process \"{process.Name}\" tries to map unexpected return path \"{returnPath.Key}\""); } else if (stepsById.TryGetValue(returnPath.Value, out Step destStep)) { if (mappedPaths.Contains(returnPath.Key)) { errors.Add($"Step {step.ID} in process \"{process.Name}\" tries to map the \"{returnPath.Key}\" return path multiple times"); continue; } userStep.ReturnPaths[returnPath.Key] = destStep; mappedPaths.Add(returnPath.Key); } else { errors.Add($"Step {step.ID} tries to connect to non-existent step \"{returnPath.Value}\" in process \"{process.Name}\""); } } foreach (var path in expectedReturnPaths) { if (!mappedPaths.Contains(path)) { errors.Add($"Step {step.ID} in process \"{process.Name}\" fails to map the \"{path}\" return path"); } } } } return(errors.Count == initialErrorCount); }