示例#1
0
 protected void Add(IScenarioStep step)
 {
     ++scenarioSteps;
     if (null != currentScenario)
     {
         this.currentScenario.Add(() => step.SetUp(), () => step.ExecuteStep(), () => step.CleanUp(), () => step.EndRunCleanUp());
     }
     else
     {
         currentScenario = new Scenario(() => step.SetUp(), () => step.ExecuteStep(), () => step.CleanUp(), () => step.EndRunCleanUp());
         scenarios.Add(currentScenario);
     }
 }
示例#2
0
    public void OnStepExecuted(IScenarioStep step)
    {
        // Step step = GetStep(stepObject);
        int currIdx = GetStepIndex(step);

        if (currIdx == currentHighestStepIndex - 1)
        {
            Debug.Log(currIdx);
            Debug.Log("previous step");
        }
        else if (currIdx == currentHighestStepIndex)
        {
            if (!downfall)
            {
                // steps[currIdx].step.DeactivateStep();
                steps[currIdx].onDeactivate.Invoke();
            }
            int idx = currentHighestStepIndex + 1;
            if (steps.Count > idx)
            {
                currentHighestStepIndex = idx;
                steps[currentHighestStepIndex].step.ActivateStep();
                steps[currentHighestStepIndex].onActivate.Invoke();
            }
            else
            {
                Debug.Log("scenario ended");
                ScenarioEnded.Invoke();
            }
        }
        else if (currIdx < currentHighestStepIndex)
        {
            for (int i = currentHighestStepIndex; i > currIdx; i--)
            {
                // steps[i].step.DeactivateStep();
                steps[i].onDeactivate.Invoke();
            }
            currentHighestStepIndex = currIdx + 1;
            steps[currentHighestStepIndex].step.ActivateStep(); //possible bug
            steps[currentHighestStepIndex].onActivate.Invoke();
        }
    }
        /**
         * Attaching observer to steams
         *
         * @param responseObserver
         * @return
         */
        public override async Task Register(IAsyncStreamReader <ChaincodeMessage> requestStream, IServerStreamWriter <ChaincodeMessage> responseStream, ServerCallContext context)
        {
            try
            {
                writer = responseStream;
                while (await requestStream.MoveNext().ConfigureAwait(false))
                {
                    ChaincodeMessage chaincodeMessage = requestStream.Current;
                    logger.Information("Mock peer => Got message: " + chaincodeMessage);
                    lastMessageRcvd = chaincodeMessage;
                    if (scenario.Count > 0)
                    {
                        IScenarioStep step = scenario[0];
                        scenario.RemoveAt(0);
                        if (step.Expected(chaincodeMessage))
                        {
                            List <ChaincodeMessage> nextSteps = step.Next();
                            foreach (ChaincodeMessage m in nextSteps)
                            {
                                lastMessageSend = m;
                                logger.Information("Mock peer => Sending response message: " + m);
                                await responseStream.WriteAsync(m).ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            logger.Warning($"Non expected message rcvd in step {step.GetType().Name}");
                        }

                        lastExecutedStepNumber++;
                    }
                }
            }
            catch (Exception)
            {
                //Ignored
            }
        }
示例#4
0
 internal void AddStep(IScenarioStep step)
 {
     _steps.Add(step);
 }
示例#5
0
 private Step GetStep(IScenarioStep step)
 {
     return(steps.SingleOrDefault(x => x.step == step));
 }
示例#6
0
    private int GetStepIndex(IScenarioStep step)
    {
        var item = GetStep(step);

        return(steps.IndexOf(item));
    }
示例#7
0
 public void Add(IScenarioStep scenarioStep)
 {
     toExec.Add(new ScenarioItem(() => scenarioStep.CleanUp(), () => scenarioStep.ExecuteStep(), () => scenarioStep.CleanUp(), () => scenarioStep.EndRunCleanUp()));
 }
示例#8
0
 public void ASimpleScenario()
 {
     subject = Scenario.Given(() => { });
 }
示例#9
0
 internal void AddStep(IScenarioStep step)
 {
     _steps.Add(step);
 }
示例#10
0
 public static void Execute(this IScenarioStep currentStep)
 {
     ((Scenario.ScenarioRunner)currentStep).Execute();
 }
示例#11
0
 public static IScenarioStep But <T1, T2>(this IScenarioStep currentStep, Action <T1, T2> stepAction, T1 param1, T2 param2)
 {
     ((Scenario.ScenarioRunner)currentStep).AddStep(" but", stepAction, param1, param2);
     return(currentStep);
 }
示例#12
0
 public static IScenarioStep But(this IScenarioStep currentStep, Action stepAction)
 {
     ((Scenario.ScenarioRunner)currentStep).AddStep(" but", stepAction);
     return(currentStep);
 }
示例#13
0
 public static IScenarioStep And <T>(this IScenarioStep currentStep, Action <T> stepAction, T param1)
 {
     ((Scenario.ScenarioRunner)currentStep).AddStep(" and", stepAction, param1);
     return(currentStep);
 }
示例#14
0
 public void ASimpleScenario()
 {
     subject = Scenario.Given(() => { });
 }