private Mock <IActionRunner> CreateStep(TestHostContext hc, TaskResult result, string condition, Boolean continueOnError = false, MappingToken env = null, string name = "Test", bool setOutput = false, string contextName = null) { // Setup the step. var step = new Mock <IActionRunner>(); step.Setup(x => x.Condition).Returns(condition); step.Setup(x => x.ContinueOnError).Returns(new BooleanToken(null, null, null, continueOnError)); step.Setup(x => x.Action) .Returns(new DistributedTask.Pipelines.ActionStep() { Name = name, Id = Guid.NewGuid(), Environment = env, ContextName = contextName ?? "Test" }); // Setup the step execution context. var stepContext = new Mock <IExecutionContext>(); stepContext.SetupAllProperties(); stepContext.Setup(x => x.Global).Returns(() => _ec.Object.Global); var expressionValues = new DictionaryContextData(); foreach (var pair in _ec.Object.ExpressionValues) { expressionValues[pair.Key] = pair.Value; } stepContext.Setup(x => x.ExpressionValues).Returns(expressionValues); stepContext.Setup(x => x.ExpressionFunctions).Returns(new List <IFunctionInfo>()); stepContext.Setup(x => x.JobContext).Returns(_jobContext); stepContext.Setup(x => x.ContextName).Returns(step.Object.Action.ContextName); stepContext.Setup(x => x.Complete(It.IsAny <TaskResult?>(), It.IsAny <string>(), It.IsAny <string>())) .Callback((TaskResult? r, string currentOperation, string resultCode) => { if (r != null) { stepContext.Object.Result = r; } _stepContext.SetOutcome("", stepContext.Object.ContextName, (stepContext.Object.Outcome ?? stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult()); _stepContext.SetConclusion("", stepContext.Object.ContextName, (stepContext.Object.Result ?? TaskResult.Succeeded).ToActionResult()); }); var trace = hc.GetTrace(); stepContext.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); }); stepContext.Object.Result = result; step.Setup(x => x.ExecutionContext).Returns(stepContext.Object); if (setOutput) { step.Setup(x => x.RunAsync()).Callback(() => { _stepContext.SetOutput(null, name, "test", "something", out string reference); }).Returns(Task.CompletedTask); } else { step.Setup(x => x.RunAsync()).Returns(Task.CompletedTask); } return(step); }
private Mock <IActionRunner> CreateStep(TestHostContext hc, TaskResult result, string condition, Boolean continueOnError = false, MappingToken env = null, string name = "Test", bool setOutput = false) { // Setup the step. var step = new Mock <IActionRunner>(); step.Setup(x => x.Condition).Returns(condition); step.Setup(x => x.ContinueOnError).Returns(new BooleanToken(null, null, null, continueOnError)); step.Setup(x => x.Action) .Returns(new DistributedTask.Pipelines.ActionStep() { Name = name, Id = Guid.NewGuid(), Environment = env }); // Setup the step execution context. var stepContext = new Mock <IExecutionContext>(); stepContext.SetupAllProperties(); stepContext.Setup(x => x.WriteDebug).Returns(true); stepContext.Setup(x => x.Variables).Returns(_variables); stepContext.Setup(x => x.EnvironmentVariables).Returns(_env); stepContext.Setup(x => x.ExpressionValues).Returns(_contexts); stepContext.Setup(x => x.JobContext).Returns(_jobContext); stepContext.Setup(x => x.StepsContext).Returns(_stepContext); stepContext.Setup(x => x.Complete(It.IsAny <TaskResult?>(), It.IsAny <string>(), It.IsAny <string>())) .Callback((TaskResult? r, string currentOperation, string resultCode) => { if (r != null) { stepContext.Object.Result = r; } }); var trace = hc.GetTrace(); stepContext.Setup(x => x.Write(It.IsAny <string>(), It.IsAny <string>())).Callback((string tag, string message) => { trace.Info($"[{tag}]{message}"); }); stepContext.Object.Result = result; step.Setup(x => x.ExecutionContext).Returns(stepContext.Object); if (setOutput) { step.Setup(x => x.RunAsync()).Callback(() => { _stepContext.SetOutput(null, name, "test", "something", out string reference); }).Returns(Task.CompletedTask); } else { step.Setup(x => x.RunAsync()).Returns(Task.CompletedTask); } return(step); }