private bool ExecuteChain(Scenario scenario, ScenarioContext storyContext, InvocationChain chain, string line)
        {
            string successPart = "";
            _lastResult = null;
            foreach (var invocation in chain.Invocations)
            {
                try
                {
                    InvokeContextMember(storyContext, invocation);
                    successPart += invocation.MatchedText + " ";
                }
                catch (TargetInvocationException ex)
                {
                    if (ex.InnerException is ScenarioPendingException)
                    {
                        _listener.ScenarioPending(new ScenarioPendingInfo(scenario, line));
                    }
                    else
                    {
                        _listener.ScenarioFailed(new ScenarioFailureInfo(scenario, successPart.Trim(),
                                                                         invocation.MatchedText, GetExceptionMessage(ex)));
                    }

                    return false;
                }
            }

            return true;
        }
Exemplo n.º 2
0
        public bool ExecuteScenario(Scenario scenario, ScenarioContext storyContext)
        {
            _eventBus.Raise(new ScenarioStarting { Scenario = scenario});
            //_scenarioInterpreter.NewScenario();

            foreach (var line in (scenario.Background ?? new ScenarioLine[0]).Union(scenario.Body))
            {
                LineStatus status = _lineExecuter.ExecuteLine(scenario, storyContext, line.Text);
                if (LineStatus.Failed == status)
                {
                    _eventBus.Raise(new ScenarioFinished { Scenario = scenario, Status = ExecutionStatus.Failed });
                    return false;
                }
                if (LineStatus.Pending == status)
                {
                    _eventBus.Raise(new ScenarioFinished { Scenario = scenario, Status = ExecutionStatus.Pending });

                    return true;
                }
            }

            _eventBus.Raise(new ScenarioFinished { Scenario = scenario, Status = ExecutionStatus.Passed});

            //_eventBus.Raise(new ScenarioSucceededEvent { Scenario = scenario });
            return true;
        }
        public LineInfo MapMethod(ScenarioContext scenarioContext, string line)
        {
            var matchingChain = _interpreter.GetChain(scenarioContext, line);

            if (matchingChain == null)
                return null;

            return new LineInfo
                       {
                           Code = ConvertInvocationChainToCSharpCode(matchingChain),
                           Namespaces = GetNamespaces(matchingChain),
                           ImplementingType = matchingChain.Invocations.First().MemberInfo.DeclaringType
                       };
        }
        public bool ExecuteScenario(Scenario scenario, ScenarioContext scenarioContext)
        {
            _eventBus.Raise(new ScenarioStarting { Scenario = scenario});
            //_scenarioInterpreter.NewScenario();

            var result = ExecutionStatus.Passed;

            foreach (var line in (scenario.Background ?? new ScenarioLine[0]).Union(scenario.Body))
            {
                LineStatus status = _lineExecuter.ExecuteLine(scenario, scenarioContext, line.Text);
                if (LineStatus.Failed == status)
                {
                    result = ExecutionStatus.Failed;
                    break;
                }
                if (LineStatus.Pending == status)
                {
                    result = ExecutionStatus.Pending;
                    break;
                }
            }

            if (!TryToDisposeScenarioContext(scenarioContext))
            {
                result = ExecutionStatus.Failed;
            }

            switch (result)
            {
                case ExecutionStatus.Failed:
                {
                    _eventBus.Raise(new ScenarioFailed { Scenario = scenario, ExceptionInfo = _exceptionInfo});
                    return false;
                }
                case ExecutionStatus.Pending:
                {
                    _eventBus.Raise(new ScenarioPending { Scenario = scenario });
                    return true;
                }
                default:
                {
                    _eventBus.Raise(new ScenarioPassed { Scenario = scenario });
                    return true;
                }
            }
        }
        public bool ExecuteScenario(Scenario scenario, ScenarioContext storyContext)
        {
            _listener.ScenarioStarting(scenario);
            _scenarioInterpreter.NewScenario();

            foreach (var line in scenario.Body)
            {
                LineStatus status = _lineExecuter.ExecuteLine(scenario, storyContext, line.Text);
                if (LineStatus.Failed == status)
                    return false;
                if (LineStatus.Pending ==status)
                    return true;
            }

            _listener.ScenarioSucceeded(scenario);
            return true;
        }
        public LineStatus ExecuteLine(Scenario scenario, ScenarioContext storyContext, string line)
        {
            // Debug.WriteLine("SLE: " + line);
            InvocationChain chain = GetMatchingChain(storyContext, line);

            if (chain == null)
            {
                var suggestion = _implementationHelper.Suggest(line);
                _listener.ScenarioPending(new ScenarioPendingInfo(scenario, line, suggestion));
                return LineStatus.Pending;
            }

            if (!ExecuteChain(scenario, storyContext, chain, line))
                return LineStatus.Failed;

            _listener.Success(scenario, line);
            return LineStatus.Passed;
        }
        private InvocationChain GetSelectedChain(ScenarioContext storyContext, string line)
        {
            foreach (var linePermutation in GetPermutations(line))
            {
                foreach (var type in storyContext.ImplementingTypes)
                {
                    var interpreter = _interpreterFactory.GetInterpreterForType(type);

                    InvocationChain chain = interpreter.GetChain(linePermutation);
                    if (chain != null)
                    {
                        DebugTrace.Trace(this.GetType().Name, "found match");
                        return chain;
                    }
                }
            }
            DebugTrace.Trace(this.GetType().Name, "no match: " + line);
            return null;
        }
Exemplo n.º 8
0
        public LineStatus ExecuteLine(Scenario scenario, ScenarioContext storyContext, string line)
        {
            DebugTrace.Trace("ScenarioLineExecter.ExecuteLine", line);
            InvocationChain chain = GetMatchingChain(storyContext, line);

            if (chain == null)
            {
                var suggestion = _implementationHelper.Suggest(line);

                _eventBus.Raise(new LinePending {Scenario = scenario, Line = line, Suggestion = suggestion });
                return LineStatus.Pending;
            }

            if (!ExecuteChain(scenario, storyContext, chain, line))
                return LineStatus.Failed;

            _eventBus.Raise(new LinePassed { Scenario = scenario, Line = line });

            return LineStatus.Passed;
        }
Exemplo n.º 9
0
        public InvocationChain GetChain(ScenarioContext context, string line)
        {
            DebugTrace.Trace("Interpreting", line);
            var chains = (GetSelectedChains(context, line) ?? new InvocationChain[0]).ToArray();
            if (! chains.Any())
                DebugTrace.Trace(GetType().Name, "no match: " + line);

            if (chains.Count() > 1)
            {
                var chain = _resolver.ResolveMatch(line, chains);
                Notify(chain);
                return chain;
            }

            if (chains.Any())
            {
                var chain = chains.FirstOrDefault();
                Notify(chain);
                return chain;
            }

            return null;
        }
Exemplo n.º 10
0
        private bool ExecuteChain(Scenario scenario, ScenarioContext storyContext, InvocationChain chain, string line)
        {
            string successPart = "";
            _lastResult = null;
            foreach (var invocation in chain.Invocations)
            {
                try
                {
                    InvokeContextMember(storyContext, invocation);
                    successPart += invocation.MatchedText + " ";
                }
                catch (TargetInvocationException ex)
                {

                    if (ex.InnerException is ScenarioPendingException)
                    {
                        _eventBus.Raise(new LinePending { Scenario = scenario, Line = line });
                    }
                    else
                    {
                        _eventBus.Raise(new LineFailed
                        {
                            Scenario = scenario,
                            Line = line,
                            SuccessPart = successPart.Trim(),
                            FailedPart = invocation.MatchedText,
                            ExceptionInfo = GetExceptionMessage(ex)
                        });
                    }

                    return false;
                }
            }

            return true;
        }
Exemplo n.º 11
0
        private IEnumerable<InvocationChain> GetSelectedChains(ScenarioContext context, string line)
        {
            foreach (var linePermutation in _languageService.GetPermutations(line))
            {
                foreach (var type in context.ImplementingTypes)
                {
                    var interpreter = _interpreterFactory.GetInterpreterForType(type);

                    IEnumerable<InvocationChain> chains = interpreter.GetChains(linePermutation);
                    foreach (var invocationChain in chains)
                    {
                        yield return invocationChain;
                    }
                }
            }
        }
Exemplo n.º 12
0
 public void SetupContext()
 {
     var mapper = new SessionContext();
     mapper.AddContext<TestMappingContext>();
     mapper.AddContext<DependentMappingContext>();
     StoryContext = mapper.GetContextForStory();
     ScenarioContext = StoryContext.GetScenarioContext();
 }
Exemplo n.º 13
0
        protected IDisposable StartScenario(Story story, Scenario scenario)
        {
            _listener.ScenarioStarting(scenario);
            CurrentScenarioContext = ContextFactory.GetContextForStory(story).GetScenarioContext();
            CurrentScenario = scenario;
            LastStatus = LineStatus.Passed;
            ScenarioInterpreter.NewScenario();

            return CurrentScenarioContext;
        }
Exemplo n.º 14
0
 protected void BeforeEach()
 {
     _scenarioContext = _sessionContext.GetScenarioContext();
     _lastStatus = LineStatus.Passed;
 }
Exemplo n.º 15
0
 public InvocationChain GetChain(ScenarioContext storyContext, string line)
 {
     DebugTrace.Trace("Interpreting", line);
     return GetSelectedChain(storyContext, line);
 }
Exemplo n.º 16
0
        protected IDisposable StartScenario(Story story, Scenario scenario)
        {
            _eventBus.Raise(new ScenarioStarting {Scenario = scenario});
            if (CurrentStoryContext == null)
                CurrentStoryContext = _context.GetContextForStory();

            CurrentScenarioContext = CurrentStoryContext.GetScenarioContext();
            CurrentScenario = scenario;
            LastStatus = LineStatus.Passed;
            //ScenarioInterpreter.NewScenario();

            return CurrentScenarioContext;
        }
 private bool TryToDisposeScenarioContext(ScenarioContext scenarioContext)
 {
     try
     {
         scenarioContext.Dispose();
         return true;
     }
     catch (Exception e)
     {
         _exceptionInfo = e.ToString();
         return false;
     }
 }
Exemplo n.º 18
0
 public Classifier(AssemblyRegistry assemblyRegistry)
 {
     _parser = new StoryParser();
     _scenarioInterpreter = new StandardScenarioInterpreter(assemblyRegistry);
     _context = new SessionContext(assemblyRegistry).GetContextForStory().GetScenarioContext();
 }
Exemplo n.º 19
0
 private void InvokeContextMember(ScenarioContext storyContext, Invocation invocation)
 {
     MemberInfo info = invocation.MemberInfo;
     var declaringType = info.DeclaringType;
     var context = _lastResult ?? storyContext.GetContext(declaringType);
     _lastResult = _memberInvoker.InvokeMember(info, invocation.ParamValues, context);
 }
Exemplo n.º 20
0
        private InvocationChain GetMatchingChain(ScenarioContext storyContext, string line)
        {
            var chain = _scenarioInterpreter.GetChain(storyContext, line);

            return chain;
        }