public void Start () { string[] featureFilepaths = GetFeatureFiles (Directory.GetCurrentDirectory ()); List<MethodInfo> stepMethods = GetStepMethods (Directory.GetCurrentDirectory ()); var parser = new Parser (); foreach (var featureFilepath in featureFilepaths) { var feature = parser.Parse (featureFilepath); _formatter.Log (feature); foreach (Scenario scenario in feature.ScenarioDefinitions) { _formatter.Log (scenario); InvokeScenario (scenario, stepMethods); } } }
public Feature Parse(TextReader featureFileReader) { var language = this.DetermineLanguage(); var gherkinParser = new Gherkin.Parser(); var dialectProvider = this.GetDialectProvider(language); try { Gherkin.Ast.GherkinDocument gherkinDocument = gherkinParser.Parse( new Gherkin.TokenScanner(featureFileReader), new Gherkin.TokenMatcher(dialectProvider)); var languageServices = this.languageServicesRegistry.GetLanguageServicesForLanguage(gherkinDocument.Feature.Language); Feature result = new Mapper(this.configuration, languageServices).MapToFeature(gherkinDocument); result = this.RemoveFeatureWithExcludeTags(result); if (result != null) { this.descriptionProcessor.Process(result); } return(result); } catch (Gherkin.CompositeParserException exception) { throw new FeatureParseException("Unable to parse feature", exception); } }
public void InvokeScenario () { var app = new App (new ConsoleFormatter ()); Scenario scenario = new Parser () .Parse ("root.feature") .ScenarioDefinitions .ToArray ()[0] as Scenario; var expectedResult = @"I have entered 50 into the calculator I have entered 70 into the calculator I press Add The result should be 120"; var availableMethods = typeof(CucunetSpec).GetMethods () .Where (m=>m.GetCustomAttributes <BaseStepAttribute>().Any ()) .ToList (); app.InvokeScenario(scenario, availableMethods); var actualResult = string.Join("\n", CucunetSpec.ExecutedSteps); System.Console.WriteLine (expectedResult); System.Console.WriteLine (actualResult); Assert.AreEqual (expectedResult, actualResult); }
public static IEnumerable<TestCase> GetTests(IEnumerable<string> sourceFiles, ITestCaseDiscoverySink discoverySink, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.IMessageLogger logger) { var tests = new List<TestCase>(); Parallel.ForEach(sourceFiles, s => { var parser = new Parser(); Feature feature; try { using (var reader = File.OpenText(s)) { logger?.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"Parsing: {s}"); feature = parser.Parse(reader); logger?.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Informational, $"Parsed: {s}"); } foreach (var scenario in feature.ScenarioDefinitions) { logger?.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Error, $"Found scenario '{scenario.Name}' in '{feature.Name}'"); var testCase = new TestCase(feature.Name + "." + scenario.Name, CucumberJsTestExecutor.ExecutorUri, s) { CodeFilePath = s, DisplayName = scenario.Name, LineNumber = scenario.Location.Line, }; if (discoverySink != null) { discoverySink.SendTestCase(testCase); } tests.Add(testCase); } } catch (Exception e) { logger?.SendMessage(Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Error, $"Error parsing '{s}': {e.Message} {e.StackTrace}"); } }); return tests; }
public Machine(Parser parser, string name) { this.parser = parser; this.name = name; this.state = name; this.transitionMap = TransitionMap(name); }