Best Gherkin-dotnet code snippet using Gherkin.Ast.Scenario
ScenarioOutlineExecutorTests.cs
Source:ScenarioOutlineExecutorTests.cs
...8using Xunit.Abstractions;9using Xunit.Gherkin.Quick;10namespace UnitTests11{12 public sealed class ScenarioOutlineExecutorTests13 {14 private readonly Mock<IFeatureFileRepository> _featureFileRepository = new Mock<IFeatureFileRepository>();15 private readonly ScenarioOutlineExecutor _sut;16 public ScenarioOutlineExecutorTests()17 {18 _sut = new ScenarioOutlineExecutor(_featureFileRepository.Object);19 }20 [Fact]21 public async Task ExecuteScenarioOutlineAsync_Requires_FeatureInstance()22 {23 //act / assert.24 await Assert.ThrowsAsync<ArgumentNullException>(async () => await _sut.ExecuteScenarioOutlineAsync(null, "scenario name", "example name", 0));25 }26 [Theory]27 [InlineData(null, "example name", 0, typeof(ArgumentNullException))]28 [InlineData("", "example name", 0, typeof(ArgumentNullException))]29 [InlineData(" ", "example name", 0, typeof(ArgumentNullException))]30 [InlineData("scenario name", "example name", -1, typeof(ArgumentException))]31 public async Task ExecuteScenarioOutlineAsync_Requires_Arguments(32 string scenarioOutlineName,33 string exampleName,34 int exampleRowIndex,35 Type expectedExceptionType)36 {37 //arrange.38 var featureInstance = new FeatureForNullArgumentTests();39 //act / assert.40 await Assert.ThrowsAsync(expectedExceptionType, async () => await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioOutlineName, exampleName, exampleRowIndex));41 }42 private sealed class FeatureForNullArgumentTests : Feature43 { }44 [Fact]45 public async Task ScenarioOutline_Runs_Background_Steps_First()46 {47 var feature = new GherkinFeatureBuilder()48 .WithBackground(sb => sb49 .Given("background", null))50 .WithScenarioOutline("test outline", sb => sb51 .Given("I chose <a> as first number", null)52 .And("I chose <b> as second number", null)53 .When("I press add", null)54 .Then("the result should be <sum> on the screen", null),55 eb => eb56 .WithExampleHeadings("a", "b", "sum")57 .WithExamples("", db => db.WithData("1", "2", "3")))58 .Build();59 60 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithScenarioSteps)}.feature"))61 .Returns(new FeatureFile(new Gherkin.Ast.GherkinDocument(feature, new Gherkin.Ast.Comment[0])))62 .Verifiable();63 var featureInstance = new FeatureWithScenarioSteps();64 var output = new Mock<ITestOutputHelper>();65 featureInstance.InternalOutput = output.Object;66 67 await _sut.ExecuteScenarioOutlineAsync(featureInstance, "test outline", "", 0);68 _featureFileRepository.Verify();69 Assert.Equal(5, featureInstance.CallStack.Count);70 Assert.Equal(nameof(FeatureWithScenarioSteps.BackgroundStep), featureInstance.CallStack[0].Key);71 }72 [Theory]73 [InlineData("", 0, 0, 1, 1)]74 [InlineData("", 1, 1, 9, 10)]75 [InlineData("of bigger numbers", 0, 99, 1, 100)]76 [InlineData("of bigger numbers", 1, 100, 200, 300)]77 [InlineData("of large numbers", 0, 999, 1, 1000)]78 [InlineData("of large numbers", 1, 9999, 1, 10000)]79 public async Task ExecuteScenarioOutlineAsync_Executes_All_Scenario_Steps(80 string exampleName,81 int exampleRowIndex,82 int a,83 int b,84 int sum85 )86 {87 //arrange.88 var step1Text = "Given " + FeatureWithScenarioSteps.ScenarioStep1Text.Replace(@"(\d+)", $"{a}", StringComparison.InvariantCultureIgnoreCase);89 var step2Text = "And " + FeatureWithScenarioSteps.ScenarioStep2Text.Replace(@"(\d+)", $"{b}", StringComparison.InvariantCultureIgnoreCase);90 var step3Text = "When " + FeatureWithScenarioSteps.ScenarioStep3Text;91 var step4Text = "Then " + FeatureWithScenarioSteps.ScenarioStep4Text.Replace(@"(\d+)", $"{sum}", StringComparison.InvariantCultureIgnoreCase);92 var scenarioOutlineName = "scenario 12345";93 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithScenarioSteps)}.feature"))94 .Returns(new FeatureFile(CreateGherkinDocument(scenarioOutlineName)))95 .Verifiable();96 var featureInstance = new FeatureWithScenarioSteps();97 var output = new Mock<ITestOutputHelper>();98 featureInstance.InternalOutput = output.Object;99 //act.100 await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioOutlineName, exampleName, exampleRowIndex);101 //assert.102 _featureFileRepository.Verify();103 Assert.Equal(4, featureInstance.CallStack.Count);104 Assert.Equal(nameof(FeatureWithScenarioSteps.ScenarioStep1), featureInstance.CallStack[0].Key);105 Assert.NotNull(featureInstance.CallStack[0].Value);106 Assert.Single(featureInstance.CallStack[0].Value);107 Assert.Equal(a, featureInstance.CallStack[0].Value[0]);108 output.Verify(o => o.WriteLine($"{step1Text}: PASSED"), Times.Once);109 Assert.Equal(nameof(FeatureWithScenarioSteps.ScenarioStep2), featureInstance.CallStack[1].Key);110 Assert.NotNull(featureInstance.CallStack[1].Value);111 Assert.Single(featureInstance.CallStack[1].Value);112 Assert.Equal(b, featureInstance.CallStack[1].Value[0]);113 output.Verify(o => o.WriteLine($"{step2Text}: PASSED"), Times.Once);114 Assert.Equal(nameof(FeatureWithScenarioSteps.ScenarioStep3), featureInstance.CallStack[2].Key);115 Assert.Null(featureInstance.CallStack[2].Value);116 output.Verify(o => o.WriteLine($"{step3Text}: PASSED"), Times.Once);117 Assert.Equal(nameof(FeatureWithScenarioSteps.ScenarioStep4), featureInstance.CallStack[3].Key);118 Assert.NotNull(featureInstance.CallStack[3].Value);119 Assert.Single(featureInstance.CallStack[3].Value);120 Assert.Equal(sum, featureInstance.CallStack[3].Value[0]);121 output.Verify(o => o.WriteLine($"{step4Text}: PASSED"), Times.Once);122 }123 private static Gherkin.Ast.GherkinDocument CreateGherkinDocument(124 string outlineName,125 Gherkin.Ast.StepArgument stepArgument = null)126 {127 return new Gherkin.Ast.GherkinDocument(128 new GherkinFeatureBuilder() 129 .WithScenarioOutline(outlineName, sb => sb130 .Given("I chose <a> as first number", stepArgument)131 .And("I chose <b> as second number", stepArgument)132 .When("I press add", stepArgument)133 .Then("the result should be <sum> on the screen", stepArgument),134 eb => eb135 .WithExampleHeadings("a", "b", "sum")136 .WithExamples("", db => db137 .WithData(0, 1, 1)138 .WithData(1, 9, 10))139 .WithExamples("of bigger numbers", db => db140 .WithData(99, 1, 100)141 .WithData(100, 200, 300))142 .WithExamples("of large numbers", db => db143 .WithData(999, 1, 1000)144 .WithData(9999, 1, 10000)))145 .Build(), 146 new Gherkin.Ast.Comment[0]);147 }148 private sealed class FeatureWithScenarioSteps : Feature149 {150 public List<KeyValuePair<string, object[]>> CallStack { get; } = new List<KeyValuePair<string, object[]>>();151 [Given("background")]152 public void BackgroundStep()153 {154 CallStack.Add(new KeyValuePair<string, object[]>(nameof(BackgroundStep), null));155 }156 [Given("Non matching given")]157 public void NonMatchingStep1_before()158 {159 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_before), null));160 }161 public const string ScenarioStep1Text = @"I chose (\d+) as first number";162 [Given(ScenarioStep1Text)]163 public void ScenarioStep1(int firstNumber)164 {165 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep1), new object[] { firstNumber }));166 }167 [Given("Non matching given")]168 public void NonMatchingStep1_after()169 {170 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_after), null));171 }172 [And("Non matching and")]173 public void NonMatchingStep2_before()174 {175 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_before), null));176 }177 public const string ScenarioStep2Text = @"I chose (\d+) as second number";178 [And(ScenarioStep2Text)]179 public void ScenarioStep2(int secondNumber)180 {181 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep2), new object[] { secondNumber }));182 }183 [And("Non matching and")]184 public void NonMatchingStep2_after()185 {186 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_after), null));187 }188 [When("Non matching when")]189 public void NonMatchingStep3_before()190 {191 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_before), null));192 }193 public const string ScenarioStep3Text = "I press add";194 [When(ScenarioStep3Text)]195 public void ScenarioStep3()196 {197 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep3), null));198 }199 [When("Non matching when")]200 public void NonMatchingStep3_after()201 {202 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_after), null));203 }204 [Then("Non matching then")]205 public void NonMatchingStep4_before()206 {207 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_before), null));208 }209 public const string ScenarioStep4Text = @"the result should be (\d+) on the screen";210 [Then(ScenarioStep4Text)]211 public void ScenarioStep4(int result)212 {213 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep4), new object[] { result }));214 }215 [Then("Non matching then")]216 public void NonMatchingStep4_after()217 {218 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_after), null));219 }220 }221 [Theory]222 [InlineData("", 0, 0, 1, 1)]223 [InlineData("", 1, 1, 9, 10)]224 [InlineData("of bigger numbers", 0, 99, 1, 100)]225 [InlineData("of bigger numbers", 1, 100, 200, 300)]226 [InlineData("of large numbers", 0, 999, 1, 1000)]227 [InlineData("of large numbers", 1, 9999, 1, 10000)]228 public async Task ExecuteScenarioOutlineAsync_Executes_Successful_Scenario_Steps_And_Skips_The_Rest(229 string exampleName,230 int exampleRowIndex,231 int a,232 int b,233 int sum234 )235 {236 //arrange.237 var step1Text = "Given " + FeatureWithScenarioSteps_And_Throwing.ScenarioStep1Text.Replace(@"(\d+)", $"{a}", StringComparison.InvariantCultureIgnoreCase);238 var step2Text = "And " + FeatureWithScenarioSteps_And_Throwing.ScenarioStep2Text.Replace(@"(\d+)", $"{b}", StringComparison.InvariantCultureIgnoreCase);239 var step3Text = "When " + FeatureWithScenarioSteps_And_Throwing.ScenarioStep3Text;240 var step4Text = "Then " + FeatureWithScenarioSteps_And_Throwing.ScenarioStep4Text.Replace(@"(\d+)", $"{sum}", StringComparison.InvariantCultureIgnoreCase);241 var outlineName = "scenario 12345";242 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithScenarioSteps_And_Throwing)}.feature"))243 .Returns(new FeatureFile(CreateGherkinDocument(outlineName)))244 .Verifiable();245 var featureInstance = new FeatureWithScenarioSteps_And_Throwing();246 var output = new Mock<ITestOutputHelper>();247 featureInstance.InternalOutput = output.Object;248 //act.249 var exceptiion = await Assert.ThrowsAsync<TargetInvocationException>(async () => await _sut.ExecuteScenarioOutlineAsync(featureInstance, outlineName, exampleName, exampleRowIndex));250 Assert.IsType<InvalidOperationException>(exceptiion.InnerException);251 //assert.252 _featureFileRepository.Verify();253 Assert.Equal(2, featureInstance.CallStack.Count);254 Assert.Equal(nameof(FeatureWithScenarioSteps_And_Throwing.ScenarioStep1), featureInstance.CallStack[0].Key);255 Assert.NotNull(featureInstance.CallStack[0].Value);256 Assert.Single(featureInstance.CallStack[0].Value);257 Assert.Equal(a, featureInstance.CallStack[0].Value[0]);258 output.Verify(o => o.WriteLine($"{step1Text}: PASSED"), Times.Once);259 Assert.Equal(nameof(FeatureWithScenarioSteps_And_Throwing.ScenarioStep2), featureInstance.CallStack[1].Key);260 Assert.NotNull(featureInstance.CallStack[1].Value);261 Assert.Single(featureInstance.CallStack[1].Value);262 Assert.Equal(b, featureInstance.CallStack[1].Value[0]);263 output.Verify(o => o.WriteLine($"{step2Text}: FAILED"), Times.Once);264 output.Verify(o => o.WriteLine($"{step3Text}: SKIPPED"), Times.Once);265 output.Verify(o => o.WriteLine($"{step4Text}: SKIPPED"), Times.Once);266 }267 private sealed class FeatureWithScenarioSteps_And_Throwing : Feature268 {269 public List<KeyValuePair<string, object[]>> CallStack { get; } = new List<KeyValuePair<string, object[]>>();270 [Given("Non matching given")]271 public void NonMatchingStep1_before()272 {273 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_before), null));274 }275 public const string ScenarioStep1Text = @"I chose (\d+) as first number";276 [Given(ScenarioStep1Text)]277 public void ScenarioStep1(int firstNumber)278 {279 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep1), new object[] { firstNumber }));280 }281 [Given("Non matching given")]282 public void NonMatchingStep1_after()283 {284 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_after), null));285 }286 [And("Non matching and")]287 public void NonMatchingStep2_before()288 {289 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_before), null));290 }291 public const string ScenarioStep2Text = @"I chose (\d+) as second number";292 [And(ScenarioStep2Text)]293 public void ScenarioStep2(int secondNumber)294 {295 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep2), new object[] { secondNumber }));296 throw new InvalidOperationException("Some exception to stop execution of next steps.");297 }298 [And("Non matching and")]299 public void NonMatchingStep2_after()300 {301 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_after), null));302 }303 [When("Non matching when")]304 public void NonMatchingStep3_before()305 {306 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_before), null));307 }308 public const string ScenarioStep3Text = "I press add";309 [When(ScenarioStep3Text)]310 public void ScenarioStep3()311 {312 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep3), null));313 }314 [When("Non matching when")]315 public void NonMatchingStep3_after()316 {317 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_after), null));318 }319 [Then("Non matching then")]320 public void NonMatchingStep4_before()321 {322 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_before), null));323 }324 public const string ScenarioStep4Text = @"the result should be (\d+) on the screen";325 [Then(ScenarioStep4Text)]326 public void ScenarioStep4(int result)327 {328 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep4), new object[] { result }));329 }330 [Then("Non matching then")]331 public void NonMatchingStep4_after()332 {333 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_after), null));334 }335 }336 [Theory]337 [InlineData("", 0)]338 [InlineData("", 1)]339 [InlineData("of bigger numbers", 0)]340 [InlineData("of bigger numbers", 1)]341 [InlineData("of large numbers", 0)]342 [InlineData("of large numbers", 1)]343 public async Task ExecuteScenarioOutlineAsync_Executes_ScenarioStep_With_DataTable(344 string exampleName,345 int exampleRowIndex)346 {347 //arrange.348 var scenarioName = "scenario123";349 var featureInstance = new FeatureWithDataTableScenarioStep();350 var output = new Mock<ITestOutputHelper>();351 featureInstance.InternalOutput = output.Object;352 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDataTableScenarioStep)}.feature"))353 .Returns(new FeatureFile(FeatureWithDataTableScenarioStep.CreateGherkinDocument(scenarioName,354 new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]355 {356 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]357 {358 new Gherkin.Ast.TableCell(null, "First argument"),359 new Gherkin.Ast.TableCell(null, "Second argument"),360 new Gherkin.Ast.TableCell(null, "Result"),361 }),362 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]363 {364 new Gherkin.Ast.TableCell(null, "1"),365 new Gherkin.Ast.TableCell(null, "2"),366 new Gherkin.Ast.TableCell(null, "3"),367 }),368 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]369 {370 new Gherkin.Ast.TableCell(null, "a"),371 new Gherkin.Ast.TableCell(null, "b"),372 new Gherkin.Ast.TableCell(null, "c"),373 })374 }))))375 .Verifiable();376 //act.377 await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioName, exampleName, exampleRowIndex);378 //assert.379 _featureFileRepository.Verify();380 Assert.NotNull(featureInstance.ReceivedDataTable);381 Assert.Equal(3, featureInstance.ReceivedDataTable.Rows.Count());382 AssertDataTableCell(0, 0, "First argument");383 AssertDataTableCell(0, 1, "Second argument");384 AssertDataTableCell(0, 2, "Result");385 AssertDataTableCell(1, 0, "1");386 AssertDataTableCell(1, 1, "2");387 AssertDataTableCell(1, 2, "3");388 AssertDataTableCell(2, 0, "a");389 AssertDataTableCell(2, 1, "b");390 AssertDataTableCell(2, 2, "c");391 void AssertDataTableCell(int rowIndex, int cellIndex, string value)392 {393 Assert.True(featureInstance.ReceivedDataTable.Rows.Count() > rowIndex);394 Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex));395 Assert.True(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.Count() > cellIndex);396 Assert.NotNull(featureInstance.ReceivedDataTable.Rows.ElementAt(rowIndex).Cells.ElementAt(cellIndex));397 Assert.Equal("First argument", featureInstance.ReceivedDataTable.Rows.ElementAt(0).Cells.ElementAt(0).Value);398 }399 }400 private sealed class FeatureWithDataTableScenarioStep : Feature401 {402 public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }403 public const string Steptext = @"Step text 1212121";404 [Given(Steptext)]405 public void When_DataTable_Is_Expected(Gherkin.Ast.DataTable dataTable)406 {407 ReceivedDataTable = dataTable;408 }409 public static Gherkin.Ast.GherkinDocument CreateGherkinDocument(410 string outlineName,411 Gherkin.Ast.StepArgument stepArgument = null)412 {413 return new Gherkin.Ast.GherkinDocument(414 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]415 {416 new Gherkin.Ast.ScenarioOutline(417 new Gherkin.Ast.Tag[0],418 null,419 null,420 outlineName,421 null,422 new Gherkin.Ast.Step[]423 {424 new Gherkin.Ast.Step(null, "Given", Steptext, stepArgument)425 },426 new Gherkin.Ast.Examples[]427 {428 new Gherkin.Ast.Examples(null, null, null, "", null,429 new Gherkin.Ast.TableRow(null,430 new Gherkin.Ast.TableCell[]431 {432 new Gherkin.Ast.TableCell(null, "a"),433 new Gherkin.Ast.TableCell(null, "b"),434 new Gherkin.Ast.TableCell(null, "sum"),435 }),436 new Gherkin.Ast.TableRow[]437 {438 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]439 {440 new Gherkin.Ast.TableCell(null, "0"),441 new Gherkin.Ast.TableCell(null, "1"),442 new Gherkin.Ast.TableCell(null, "1")443 }),444 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]445 {446 new Gherkin.Ast.TableCell(null, "1"),447 new Gherkin.Ast.TableCell(null, "9"),448 new Gherkin.Ast.TableCell(null, "10")449 })450 }),451 new Gherkin.Ast.Examples(null, null, null, "of bigger numbers", null,452 new Gherkin.Ast.TableRow(null,453 new Gherkin.Ast.TableCell[]454 {455 new Gherkin.Ast.TableCell(null, "a"),456 new Gherkin.Ast.TableCell(null, "b"),457 new Gherkin.Ast.TableCell(null, "sum"),458 }),459 new Gherkin.Ast.TableRow[]460 {461 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]462 {463 new Gherkin.Ast.TableCell(null, "99"),464 new Gherkin.Ast.TableCell(null, "1"),465 new Gherkin.Ast.TableCell(null, "100")466 }),467 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]468 {469 new Gherkin.Ast.TableCell(null, "100"),470 new Gherkin.Ast.TableCell(null, "200"),471 new Gherkin.Ast.TableCell(null, "300")472 })473 }),474 new Gherkin.Ast.Examples(null, null, null, "of large numbers", null,475 new Gherkin.Ast.TableRow(null,476 new Gherkin.Ast.TableCell[]477 {478 new Gherkin.Ast.TableCell(null, "a"),479 new Gherkin.Ast.TableCell(null, "b"),480 new Gherkin.Ast.TableCell(null, "sum"),481 }),482 new Gherkin.Ast.TableRow[]483 {484 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]485 {486 new Gherkin.Ast.TableCell(null, "999"),487 new Gherkin.Ast.TableCell(null, "1"),488 new Gherkin.Ast.TableCell(null, "1000")489 }),490 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]491 {492 new Gherkin.Ast.TableCell(null, "9999"),493 new Gherkin.Ast.TableCell(null, "1"),494 new Gherkin.Ast.TableCell(null, "10000")495 })496 })497 })498 }),499 new Gherkin.Ast.Comment[0]);500 }501 }502 [Theory]503 [InlineData("", 0)]504 [InlineData("", 1)]505 [InlineData("of bigger numbers", 0)]506 [InlineData("of bigger numbers", 1)]507 [InlineData("of large numbers", 0)]508 [InlineData("of large numbers", 1)]509 public async Task ExecuteScenarioOutlineAsync_Executes_ScenarioStep_With_DocString(510 string exampleName,511 int exampleRowIndex)512 {513 //arrange.514 var scenarioName = "scenario123";515 var featureInstance = new FeatureWithDocStringScenarioStep();516 var output = new Mock<ITestOutputHelper>();517 featureInstance.InternalOutput = output.Object;518 var docStringContent = "some content" + Environment.NewLine +519"+++" + Environment.NewLine +520"with multi lines" + Environment.NewLine +521"---" + Environment.NewLine +522"in it";523 _featureFileRepository.Setup(r => r.GetByFilePath($"{nameof(FeatureWithDocStringScenarioStep)}.feature"))524 .Returns(new FeatureFile(FeatureWithDocStringScenarioStep.CreateGherkinDocument(scenarioName,525 new Gherkin.Ast.DocString(null, null, docStringContent))))526 .Verifiable();527 //act.528 await _sut.ExecuteScenarioOutlineAsync(featureInstance, scenarioName, exampleName, exampleRowIndex);529 //assert.530 _featureFileRepository.Verify();531 Assert.NotNull(featureInstance.ReceivedDocString);532 Assert.Equal(docStringContent, featureInstance.ReceivedDocString.Content);533 }534 private sealed class FeatureWithDocStringScenarioStep : Feature535 {536 public Gherkin.Ast.DocString ReceivedDocString { get; private set; }537 public const string Steptext = @"Step text 1212121";538 [Given(Steptext)]539 public void When_DocString_Is_Expected(Gherkin.Ast.DocString docString)540 {541 ReceivedDocString = docString;542 }543 public static Gherkin.Ast.GherkinDocument CreateGherkinDocument(544 string outlineName,545 Gherkin.Ast.StepArgument stepArgument = null)546 {547 return new Gherkin.Ast.GherkinDocument(548 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]549 {550 new Gherkin.Ast.ScenarioOutline(551 new Gherkin.Ast.Tag[0],552 null,553 null,554 outlineName,555 null,556 new Gherkin.Ast.Step[]557 {558 new Gherkin.Ast.Step(null, "Given", Steptext, stepArgument)559 },560 new Gherkin.Ast.Examples[]561 {562 new Gherkin.Ast.Examples(null, null, null, "", null,563 new Gherkin.Ast.TableRow(null,564 new Gherkin.Ast.TableCell[]...
GherkinFeatureTests.cs
Source:GherkinFeatureTests.cs
...5namespace UnitTests6{7 public sealed class GherkinFeatureTests8 {9 public static object[][] DataFor_Feature_And_Scenario_Null_Arguments10 {11 get12 {13 return new object[][] 14 {15 new object[]{ new Gherkin.Ast.Feature(null, null, null, null, null, null, null), null },16 new object[]{ null, "scenario name" }17 };18 }19 }20 [Theory]21 [MemberData(nameof(DataFor_Feature_And_Scenario_Null_Arguments))]22 public void GetScenarioTags_Requires_Arguments(23 Gherkin.Ast.Feature feature,24 string scenarioName25 )26 {27 //act / assert.28 Assert.Throws<ArgumentNullException>(() => feature.GetScenarioTags(scenarioName));29 }30 [Fact]31 public void GetScenarioTags_Retrieves_Tags_Of_Feature_And_Scenario_Combined()32 {33 //arrange.34 var featureTags = new Gherkin.Ast.Tag[] 35 {36 new Gherkin.Ast.Tag(null, "featuretag-1"),37 new Gherkin.Ast.Tag(null, "featuretag-2")38 };39 var scenarioTags = new Gherkin.Ast.Tag[] 40 {41 new Gherkin.Ast.Tag(null, "scenarioTag-1"),42 new Gherkin.Ast.Tag(null, "scenarioTag-2"),43 new Gherkin.Ast.Tag(null, "scenarioTag-3")44 };45 var scenarioName = "scenario name 123";46 var feature = new Gherkin.Ast.Feature(47 featureTags, null, null, null, null, null,48 new Gherkin.Ast.ScenarioDefinition[] 49 {50 new Gherkin.Ast.Scenario(scenarioTags, null, null, scenarioName, null, null)51 });52 //act.53 var scenarioTagNames = feature.GetScenarioTags(scenarioName);54 //assert.55 Assert.NotNull(scenarioTagNames);56 var expectedTagNames = featureTags.Union(scenarioTags).Select(t => t.Name);57 Assert.Equal(expectedTagNames, scenarioTagNames);58 }59 60 [Theory]61 [MemberData(nameof(DataFor_Feature_And_Scenario_Null_Arguments))]62 public void IsScenarioIgnored_Requires_Arguments(63 Gherkin.Ast.Feature feature,64 string scenarioName65 )66 {67 //act / assert.68 Assert.Throws<ArgumentNullException>(() => feature.IsScenarioIgnored(scenarioName));69 }70 [Fact]71 public void IsScenarioIgnored_Does_Not_Treat_Ignored_If_No_Ignore_Tag()72 {73 //arrange.74 var featureTags = new Gherkin.Ast.Tag[]75 {76 new Gherkin.Ast.Tag(null, "featuretag-1"),77 new Gherkin.Ast.Tag(null, "featuretag-2")78 };79 var scenarioTags = new Gherkin.Ast.Tag[]80 {81 new Gherkin.Ast.Tag(null, "scenarioTag-1"),82 new Gherkin.Ast.Tag(null, "scenarioTag-2"),83 new Gherkin.Ast.Tag(null, "scenarioTag-3")84 };85 var scenarioName = "scenario name 123";86 var feature = new Gherkin.Ast.Feature(87 featureTags, null, null, null, null, null,88 new Gherkin.Ast.ScenarioDefinition[]89 {90 new Gherkin.Ast.Scenario(scenarioTags, null, null, scenarioName, null, null)91 });92 //act.93 var isIgnored = feature.IsScenarioIgnored(scenarioName);94 //assert.95 Assert.False(isIgnored);96 }97 [Fact]98 public void IsScenarioIgnored_Treats_Ignored_If_Feature_Is_Ignored()99 {100 //arrange.101 var featureTags = new Gherkin.Ast.Tag[]102 {103 new Gherkin.Ast.Tag(null, "featuretag-1"),104 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag)105 };106 var scenarioTags = new Gherkin.Ast.Tag[]107 {108 new Gherkin.Ast.Tag(null, "scenarioTag-1"),109 new Gherkin.Ast.Tag(null, "scenarioTag-2"),110 new Gherkin.Ast.Tag(null, "scenarioTag-3")111 };112 var scenarioName = "scenario name 123";113 var feature = new Gherkin.Ast.Feature(114 featureTags, null, null, null, null, null,115 new Gherkin.Ast.ScenarioDefinition[]116 {117 new Gherkin.Ast.Scenario(scenarioTags, null, null, scenarioName, null, null)118 });119 //act.120 var isIgnored = feature.IsScenarioIgnored(scenarioName);121 //assert.122 Assert.True(isIgnored);123 }124 [Fact]125 public void IsScenarioIgnored_Treats_Ignored_If_Scenario_Is_Ignored()126 {127 //arrange.128 var featureTags = new Gherkin.Ast.Tag[]129 {130 new Gherkin.Ast.Tag(null, "featuretag-1"),131 new Gherkin.Ast.Tag(null, "featuretag-2")132 };133 var scenarioTags = new Gherkin.Ast.Tag[]134 {135 new Gherkin.Ast.Tag(null, "scenarioTag-1"),136 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag),137 new Gherkin.Ast.Tag(null, "scenarioTag-3")138 };139 var scenarioName = "scenario name 123";140 var feature = new Gherkin.Ast.Feature(141 featureTags, null, null, null, null, null,142 new Gherkin.Ast.ScenarioDefinition[]143 {144 new Gherkin.Ast.Scenario(scenarioTags, null, null, scenarioName, null, null)145 });146 //act.147 var isIgnored = feature.IsScenarioIgnored(scenarioName);148 //assert.149 Assert.True(isIgnored);150 }151 public static object[][] DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments152 {153 get154 {155 return new object[][]156 {157 new object[]{ null, "scenario outline name", "examples name" },158 new object[]{ new Gherkin.Ast.Feature(null, null, null, null, null, null, null), null, "examples name" },159 new object[]{ new Gherkin.Ast.Feature(null, null, null, null, null, null, null), "scenario outline name", null }160 };161 }162 }163 [Theory]164 [MemberData(nameof(DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments))]165 public void GetExamplesTags_Requires_Arguments(166 Gherkin.Ast.Feature feature,167 string scenarioOutlineName,168 string examplesName169 )170 {171 //act / assert.172 Assert.Throws<ArgumentNullException>(() => feature.GetExamplesTags(173 scenarioOutlineName,174 examplesName));175 }176 [Fact]177 public void GetExamplesTags_Retrieves_Tags_Of_Feature_And_OutLine_And_Examples_Combined()178 {179 //arrange.180 var featureTags = new Gherkin.Ast.Tag[]181 {182 new Gherkin.Ast.Tag(null, "featuretag-1"),183 new Gherkin.Ast.Tag(null, "featuretag-2")184 };185 var outlineTags = new Gherkin.Ast.Tag[]186 {187 new Gherkin.Ast.Tag(null, "outlinetag-1"),188 new Gherkin.Ast.Tag(null, "outlinetag-2"),189 new Gherkin.Ast.Tag(null, "outlinetag-3")190 };191 var examplesTags = new Gherkin.Ast.Tag[]192 {193 new Gherkin.Ast.Tag(null, "examplestag-1"),194 new Gherkin.Ast.Tag(null, "examplestag-2"),195 new Gherkin.Ast.Tag(null, "examplestag-2"),196 new Gherkin.Ast.Tag(null, "examplestag-3")197 };198 var scenarioOutlineName = "scenario name 123";199 var examplesName = "examples name 123";200 var feature = new Gherkin.Ast.Feature(201 featureTags, null, null, null, null, null,202 new Gherkin.Ast.ScenarioDefinition[]203 {204 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,205 new Gherkin.Ast.Examples[]206 {207 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)208 })209 });210 //act.211 var examplesTagNames = feature.GetExamplesTags(scenarioOutlineName, examplesName);212 //assert.213 Assert.NotNull(examplesTagNames);214 var expectedTagNames = featureTags.Union(outlineTags).Union(examplesTags).Select(t => t.Name);215 Assert.Equal(expectedTagNames, examplesTagNames);216 }217 [Theory]218 [MemberData(nameof(DataFor_Feature_And_ScenarioOutline_And_Examples_Null_Arguments))]219 public void IsExamplesIgnored_Requires_Arguments(220 Gherkin.Ast.Feature feature,221 string scenarioOutlineName,222 string examplesName223 )224 {225 //act / assert.226 Assert.Throws<ArgumentNullException>(() => feature.IsExamplesIgnored(scenarioOutlineName, examplesName));227 }228 [Fact]229 public void IsExamplesIgnored_Does_Not_Treat_Ignored_If_No_Ignore_Tag()230 {231 //arrange.232 var featureTags = new Gherkin.Ast.Tag[]233 {234 new Gherkin.Ast.Tag(null, "featuretag-1"),235 new Gherkin.Ast.Tag(null, "featuretag-2")236 };237 var outlineTags = new Gherkin.Ast.Tag[]238 {239 new Gherkin.Ast.Tag(null, "outlinetag-1"),240 new Gherkin.Ast.Tag(null, "outlinetag-2"),241 new Gherkin.Ast.Tag(null, "outlinetag-3")242 };243 var examplesTags = new Gherkin.Ast.Tag[]244 {245 new Gherkin.Ast.Tag(null, "examplestag-1"),246 new Gherkin.Ast.Tag(null, "examplestag-2"),247 new Gherkin.Ast.Tag(null, "examplestag-2"),248 new Gherkin.Ast.Tag(null, "examplestag-3")249 };250 var scenarioOutlineName = "scenario name 123";251 var examplesName = "examples name 123";252 var feature = new Gherkin.Ast.Feature(253 featureTags, null, null, null, null, null,254 new Gherkin.Ast.ScenarioDefinition[]255 {256 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,257 new Gherkin.Ast.Examples[]258 {259 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)260 })261 });262 //act.263 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);264 //assert.265 Assert.False(isIgnored);266 }267 [Fact]268 public void IsExamplesIgnored_Treats_Ignored_If_Feature_Is_Ignored()269 {270 //arrange.271 var featureTags = new Gherkin.Ast.Tag[]272 {273 new Gherkin.Ast.Tag(null, "featuretag-1"),274 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag)275 };276 var outlineTags = new Gherkin.Ast.Tag[]277 {278 new Gherkin.Ast.Tag(null, "outlinetag-1"),279 new Gherkin.Ast.Tag(null, "outlinetag-2"),280 new Gherkin.Ast.Tag(null, "outlinetag-3")281 };282 var examplesTags = new Gherkin.Ast.Tag[]283 {284 new Gherkin.Ast.Tag(null, "examplestag-1"),285 new Gherkin.Ast.Tag(null, "examplestag-2"),286 new Gherkin.Ast.Tag(null, "examplestag-2"),287 new Gherkin.Ast.Tag(null, "examplestag-3")288 };289 var scenarioOutlineName = "scenario name 123";290 var examplesName = "examples name 123";291 var feature = new Gherkin.Ast.Feature(292 featureTags, null, null, null, null, null,293 new Gherkin.Ast.ScenarioDefinition[]294 {295 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,296 new Gherkin.Ast.Examples[]297 {298 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)299 })300 });301 //act.302 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);303 //assert.304 Assert.True(isIgnored);305 }306 [Fact]307 public void IsExamplesIgnored_Treats_Ignored_If_ScenarioOutline_Is_Ignored()308 {309 //arrange.310 var featureTags = new Gherkin.Ast.Tag[]311 {312 new Gherkin.Ast.Tag(null, "featuretag-1"),313 new Gherkin.Ast.Tag(null, "featuretag-1")314 };315 var outlineTags = new Gherkin.Ast.Tag[]316 {317 new Gherkin.Ast.Tag(null, "outlinetag-1"),318 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag),319 new Gherkin.Ast.Tag(null, "outlinetag-3")320 };321 var examplesTags = new Gherkin.Ast.Tag[]322 {323 new Gherkin.Ast.Tag(null, "examplestag-1"),324 new Gherkin.Ast.Tag(null, "examplestag-2"),325 new Gherkin.Ast.Tag(null, "examplestag-2"),326 new Gherkin.Ast.Tag(null, "examplestag-3")327 };328 var scenarioOutlineName = "scenario name 123";329 var examplesName = "examples name 123";330 var feature = new Gherkin.Ast.Feature(331 featureTags, null, null, null, null, null,332 new Gherkin.Ast.ScenarioDefinition[]333 {334 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,335 new Gherkin.Ast.Examples[]336 {337 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)338 })339 });340 //act.341 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);342 //assert.343 Assert.True(isIgnored);344 }345 [Fact]346 public void IsExamplesIgnored_Treats_Ignored_If_Examples_Is_Ignored()347 {348 //arrange.349 var featureTags = new Gherkin.Ast.Tag[]350 {351 new Gherkin.Ast.Tag(null, "featuretag-1"),352 new Gherkin.Ast.Tag(null, "featuretag-2")353 };354 var outlineTags = new Gherkin.Ast.Tag[]355 {356 new Gherkin.Ast.Tag(null, "outlinetag-1"),357 new Gherkin.Ast.Tag(null, "outlinetag-2"),358 new Gherkin.Ast.Tag(null, "outlinetag-3")359 };360 var examplesTags = new Gherkin.Ast.Tag[]361 {362 new Gherkin.Ast.Tag(null, "examplestag-1"),363 new Gherkin.Ast.Tag(null, "examplestag-2"),364 new Gherkin.Ast.Tag(null, GherkinFeatureExtensions.IgnoreTag),365 new Gherkin.Ast.Tag(null, "examplestag-3")366 };367 var scenarioOutlineName = "scenario name 123";368 var examplesName = "examples name 123";369 var feature = new Gherkin.Ast.Feature(370 featureTags, null, null, null, null, null,371 new Gherkin.Ast.ScenarioDefinition[]372 {373 new Gherkin.Ast.ScenarioOutline(outlineTags, null, null, scenarioOutlineName, null, null,374 new Gherkin.Ast.Examples[]375 {376 new Gherkin.Ast.Examples(examplesTags, null, null, examplesName, null, null, null)377 })378 });379 //act.380 var isIgnored = feature.IsExamplesIgnored(scenarioOutlineName, examplesName);381 //assert.382 Assert.True(isIgnored);383 }384 }385}...
FeatureClassTests.cs
Source:FeatureClassTests.cs
...54 await Task.CompletedTask;55 }56 }57 [Fact]58 public void ExtractScenario_Extracts_Scenario_Without_Background()59 {60 //arrange.61 var scenarioName = "some scenario name 123";62 var featureInstance = new FeatureWithMatchingScenarioStepsToExtract();63 var sut = FeatureClass.FromFeatureInstance(featureInstance);64 var gherkinScenario = CreateGherkinDocument(scenarioName,65 new string[]66 {67 "Given " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep1Text.Replace(@"(\d+)", "12", StringComparison.InvariantCultureIgnoreCase),68 "And " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep2Text.Replace(@"(\d+)", "15", StringComparison.InvariantCultureIgnoreCase),69 "When " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep3Text,70 "Then " + FeatureWithMatchingScenarioStepsToExtract.ScenarioStep4Text.Replace(@"(\d+)", "27", StringComparison.InvariantCultureIgnoreCase)71 }).Feature.Children.First() as Gherkin.Ast.Scenario;72 //act.73 var scenario = sut.ExtractScenario(gherkinScenario);74 //assert.75 Assert.NotNull(scenario);76 } 77 private static Gherkin.Ast.GherkinDocument CreateGherkinDocument(78 string scenario,79 string[] steps,80 Gherkin.Ast.StepArgument stepArgument = null,81 string[] backgroundSteps = null)82 {83 var definitions = new List<global::Gherkin.Ast.ScenarioDefinition>84 {85 new Gherkin.Ast.Scenario(86 new Gherkin.Ast.Tag[0],87 null,88 null,89 scenario,90 null,91 steps.Select(s =>92 {93 var spaceIndex = s.IndexOf(' ');94 return new Gherkin.Ast.Step(95 null,96 s.Substring(0, spaceIndex).Trim(),97 s.Substring(spaceIndex).Trim(),98 stepArgument);99 }).ToArray())100 };101 if(backgroundSteps != null)102 {103 definitions.Add(104 new Gherkin.Ast.Background(105 null,106 null,107 "background",108 null,109 backgroundSteps.Select(s =>110 {111 var spaceIndex = s.IndexOf(' ');112 return new Gherkin.Ast.Step(113 null,114 s.Substring(0, spaceIndex).Trim(),115 s.Substring(spaceIndex).Trim(),116 stepArgument);117 }).ToArray()));118 }119 return new Gherkin.Ast.GherkinDocument(120 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, definitions.ToArray()),121 new Gherkin.Ast.Comment[0]);122 }123 private sealed class FeatureWithMatchingScenarioStepsToExtract : Feature124 {125 public List<KeyValuePair<string, object[]>> CallStack { get; } = new List<KeyValuePair<string, object[]>>();126 [Given("a background step")]127 public void GivenBackground()128 {129 CallStack.Add(new KeyValuePair<string, object[]>(nameof(GivenBackground), null));130 }131 [Given("Non matching given")]132 public void NonMatchingStep1_before()133 {134 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_before), null));135 }136 public const string ScenarioStep1Text = @"I chose (\d+) as first number";137 [Given(ScenarioStep1Text)]138 public void ScenarioStep1(int firstNumber)139 {140 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep1), new object[] { firstNumber }));141 }142 [Given("Non matching given")]143 public void NonMatchingStep1_after()144 {145 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep1_after), null));146 }147 [And("Non matching and")]148 public void NonMatchingStep2_before()149 {150 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_before), null));151 }152 public const string ScenarioStep2Text = @"I chose (\d+) as second number";153 [And(ScenarioStep2Text)]154 public void ScenarioStep2(int secondNumber)155 {156 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep2), new object[] { secondNumber }));157 }158 [And("Non matching and")]159 public void NonMatchingStep2_after()160 {161 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep2_after), null));162 }163 [When("Non matching when")]164 public void NonMatchingStep3_before()165 {166 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_before), null));167 }168 public const string ScenarioStep3Text = "I press add";169 [When(ScenarioStep3Text)]170 public void ScenarioStep3()171 {172 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep3), null));173 }174 [When("Non matching when")]175 public void NonMatchingStep3_after()176 {177 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep3_after), null));178 }179 [Then("Non matching then")]180 public void NonMatchingStep4_before()181 {182 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_before), null));183 }184 public const string ScenarioStep4Text = @"the result should be (\d+) on the screen";185 [Then(ScenarioStep4Text)]186 public void ScenarioStep4(int result)187 {188 CallStack.Add(new KeyValuePair<string, object[]>(nameof(ScenarioStep4), new object[] { result }));189 }190 [Then("Non matching then")]191 public void NonMatchingStep4_after()192 {193 CallStack.Add(new KeyValuePair<string, object[]>(nameof(NonMatchingStep4_after), null));194 }195 }196 [Fact]197 public void ExtractScnario_Extracts_Scenario_With_DataTable()198 {199 //arrange.200 var scenarioName = "scenario213";201 var featureInstance = new FeatureWithDataTableScenarioStep();202 var sut = FeatureClass.FromFeatureInstance(featureInstance);203 var gherknScenario = CreateGherkinDocument(scenarioName,204 new string[]205 {206 "When " + FeatureWithDataTableScenarioStep.Steptext207 },208 new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]209 {210 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]211 {212 new Gherkin.Ast.TableCell(null, "First argument"),213 new Gherkin.Ast.TableCell(null, "Second argument"),214 new Gherkin.Ast.TableCell(null, "Result"),215 }),216 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]217 {218 new Gherkin.Ast.TableCell(null, "1"),219 new Gherkin.Ast.TableCell(null, "2"),220 new Gherkin.Ast.TableCell(null, "3"),221 }),222 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]223 {224 new Gherkin.Ast.TableCell(null, "a"),225 new Gherkin.Ast.TableCell(null, "b"),226 new Gherkin.Ast.TableCell(null, "c"),227 })228 })).Feature.Children.First() as Gherkin.Ast.Scenario;229 //act.230 var scenario = sut.ExtractScenario(gherknScenario);231 //assert.232 Assert.NotNull(scenario);233 }234 private sealed class FeatureWithDataTableScenarioStep : Feature235 {236 public Gherkin.Ast.DataTable ReceivedDataTable { get; private set; }237 public const string Steptext = "Some step text";238 [When(Steptext)]239 public void When_DataTable_Is_Expected(Gherkin.Ast.DataTable dataTable)240 {241 ReceivedDataTable = dataTable;242 }243 }244 [Fact]245 public void ExtractScenario_Extracts_Scenario_With_DocString()246 {247 //arrange.248 var featureInstance = new FeatureWithDocStringScenarioStep();249 var sut = FeatureClass.FromFeatureInstance(featureInstance);250 var scenarioName = "scenario-121kh2";251 var docStringContent = @"some content252 +++253 with multi lines254 ---255 in it";256 var gherkinScenario = CreateGherkinDocument(scenarioName,257 new string[] { "Given " + FeatureWithDocStringScenarioStep.StepWithDocStringText },258 new Gherkin.Ast.DocString(null, null, docStringContent))259 .Feature.Children.First() as Gherkin.Ast.Scenario;260 //act.261 var scenario = sut.ExtractScenario(gherkinScenario);262 //assert.263 Assert.NotNull(scenario);264 }265 private sealed class FeatureWithDocStringScenarioStep : Feature266 {267 public Gherkin.Ast.DocString ReceivedDocString { get; private set; }268 public const string StepWithDocStringText = "Step with docstirng";269 [Given(StepWithDocStringText)]270 public void Step_With_DocString_Argument(Gherkin.Ast.DocString docString)271 {272 ReceivedDocString = docString;273 }274 }275 [Fact]276 public void ExtractScenario_Extracts_Steps_With_Multiple_Patterns()277 {278 //arrange.279 var sut = FeatureClass.FromFeatureInstance(new FeatureWithMultipleStepPatterns());280 //act.281 var scenario = sut.ExtractScenario(CreateGherkinDocument("scenario 123", new string[]282 {283 "Given something else"284 }).Feature.Children.OfType<Gherkin.Ast.Scenario>().First());285 //assert.286 Assert.NotNull(scenario);287 }288 private sealed class FeatureWithMultipleStepPatterns : Feature289 {290 [Given("something")]291 [Given("something else")]292 [And("something")]293 [And("something else")]294 [When("something")]295 [When("something else")]296 [And("something")]297 [And("something else")]298 [But("something")]...
GherkinScenarioOutlineTests.cs
Source:GherkinScenarioOutlineTests.cs
...4using Xunit;5using Xunit.Gherkin.Quick;6namespace UnitTests7{8 public sealed class GherkinScenarioOutlineTests9 {10 [Theory]11 [InlineData("non-existing example", 0)]12 [InlineData("existing example", 1)]13 public void ApplyExampleRow_Throws_Error_When_Example_Not_Found(14 string exampleName,15 int exampleRowIndex16 )17 {18 //arrange.19 var sut = new Gherkin.Ast.ScenarioOutline(20 null,21 null,22 null,23 "outline123",24 null,25 new Gherkin.Ast.Step[] { },26 new Gherkin.Ast.Examples[] 27 {28 new Gherkin.Ast.Examples(29 null,30 null,31 null,32 "existing example",33 null,34 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]{ }),35 new Gherkin.Ast.TableRow[]36 {37 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]{ })38 })39 });40 //act / assert.41 Assert.Throws<InvalidOperationException>(() => sut.ApplyExampleRow(exampleName, exampleRowIndex));42 }43 [Fact]44 public void ApplyExampleRow_Digests_Row_Values_Into_Scenario()45 {46 //arrange.47 var sut = new Gherkin.Ast.ScenarioOutline(48 null,49 null,50 null,51 "outline123",52 null,53 new Gherkin.Ast.Step[] 54 {55 new Gherkin.Ast.Step(null, "Given", "I chose <a> as first number", null),56 new Gherkin.Ast.Step(null, "And", "I chose <b> as second number", null),57 new Gherkin.Ast.Step(null, "When", "I press add", null),58 new Gherkin.Ast.Step(null, "Then", "the result should be <sum> on the screen", null),59 },60 new Gherkin.Ast.Examples[]61 {62 new Gherkin.Ast.Examples(63 null,64 null,65 null,66 "existing example",67 null,68 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]69 {70 new Gherkin.Ast.TableCell(null, "a"),71 new Gherkin.Ast.TableCell(null, "b"),72 new Gherkin.Ast.TableCell(null, "sum")73 }),74 new Gherkin.Ast.TableRow[]75 {76 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]77 {78 new Gherkin.Ast.TableCell(null, "1"),79 new Gherkin.Ast.TableCell(null, "2"),80 new Gherkin.Ast.TableCell(null, "3")81 })82 })83 });84 //act.85 var scenario = sut.ApplyExampleRow("existing example", 0);86 //assert.87 Assert.NotNull(scenario);88 Assert.Equal(sut.Name, scenario.Name);89 Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());90 Assert.Equal(4, scenario.Steps.Count());91 var sutSteps = sut.Steps.ToList();92 var scenarioSteps = scenario.Steps.ToList();93 ValidateStep(scenarioSteps[0], "Given", "I chose 1 as first number", sutSteps[0]);94 ValidateStep(scenarioSteps[1], "And", "I chose 2 as second number", sutSteps[1]);95 ValidateStep(scenarioSteps[2], "When", "I press add", sutSteps[2]);96 ValidateStep(scenarioSteps[3], "Then", "the result should be 3 on the screen", sutSteps[3]);97 void ValidateStep(Gherkin.Ast.Step step, string keyword, string text,98 Gherkin.Ast.Step other)99 {100 Assert.NotSame(other, step);101 Assert.Equal(keyword, step.Keyword);102 Assert.Equal(text, step.Text);103 }104 }105 [Fact]106 public void ApplyExampleRow_Digests_Row_Values_Into_Scenario_With_Multiple_Placeholders_Per_Step()107 {108 //arrange.109 var sut = new Gherkin.Ast.ScenarioOutline(110 null,111 null,112 null,113 "outline123",114 null,115 new Gherkin.Ast.Step[]116 {117 new Gherkin.Ast.Step(null, "Given", "I chose <a> as first number and <b> as second number", null),118 new Gherkin.Ast.Step(null, "When", "I press add", null),119 new Gherkin.Ast.Step(null, "Then", "the result should be <sum> on the screen", null),120 },121 new Gherkin.Ast.Examples[]122 {123 new Gherkin.Ast.Examples(124 null,125 null,126 null,127 "existing example",128 null,129 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]130 {131 new Gherkin.Ast.TableCell(null, "a"),132 new Gherkin.Ast.TableCell(null, "b"),133 new Gherkin.Ast.TableCell(null, "sum")134 }),135 new Gherkin.Ast.TableRow[]136 {137 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]138 {139 new Gherkin.Ast.TableCell(null, "1"),140 new Gherkin.Ast.TableCell(null, "2"),141 new Gherkin.Ast.TableCell(null, "3")142 })143 })144 });145 //act.146 var scenario = sut.ApplyExampleRow("existing example", 0);147 //assert.148 Assert.NotNull(scenario);149 Assert.Equal(sut.Name, scenario.Name);150 Assert.Equal(sut.Steps.Count(), scenario.Steps.Count());151 Assert.Equal(3, scenario.Steps.Count());152 var sutSteps = sut.Steps.ToList();153 var scenarioSteps = scenario.Steps.ToList();154 ValidateStep(scenarioSteps[0], "Given", "I chose 1 as first number and 2 as second number", sutSteps[0]);155 ValidateStep(scenarioSteps[1], "When", "I press add", sutSteps[1]);156 ValidateStep(scenarioSteps[2], "Then", "the result should be 3 on the screen", sutSteps[2]);157 void ValidateStep(Gherkin.Ast.Step step, string keyword, string text,158 Gherkin.Ast.Step other)159 {160 Assert.NotSame(other, step);161 Assert.Equal(keyword, step.Keyword);162 Assert.Equal(text, step.Text);163 }164 }165 [Fact]166 public void ApplyExampleRow_Digests_Row_Values_Into_Scenario_With_DataTable_In_Step()167 {168 //arrange.169 var sut = new Gherkin.Ast.ScenarioOutline(170 null,171 null,172 null,173 "outline123",174 null,175 new Gherkin.Ast.Step[]176 {177 new Gherkin.Ast.Step(null, "Given", "I pass a datatable with tokens", new DataTable(new []178 {179 new TableRow(null, new[] { new TableCell(null, "Column1"), new TableCell(null, "Column2") }),180 new TableRow(null, new[] { new TableCell(null, "<a>"), new TableCell(null, "data with <b> in the middle") }),181 new TableRow(null, new[] { new TableCell(null, "<b>"), new TableCell(null, "<a>") })182 })),183 new Gherkin.Ast.Step(null, "When", "I apply a sample row", null),...
FeatureFileTests.cs
Source:FeatureFileTests.cs
...15 //assert.16 Assert.Same(gherkinDocument, sut.GherkinDocument);17 }18 [Fact]19 public void GetScenario_Retrieves_If_Found()20 {21 //arrange.22 var scenarioName = "name exists";23 var sut = new FeatureFile(CreateGherkinDocumentWithScenario(scenarioName));24 //act.25 var scenario = sut.GetScenario(scenarioName);26 //assert.27 Assert.NotNull(scenario);28 Assert.Same(sut.GherkinDocument.Feature.Children.First(), scenario);29 }30 [Fact]31 public void GetScenario_Gives_Null_If_Not_Found()32 {33 //arrange.34 var sut = new FeatureFile(CreateGherkinDocumentWithScenario("existing"));35 //act.36 var scenario = sut.GetScenario("non-existing");37 //assert.38 Assert.Null(scenario);39 }40 [Fact]41 public void GetScenarioOutline_Retrieves_If_Found()42 {43 //arrange.44 var scenarioName = "name exists";45 var sut = new FeatureFile(CreateGherkinDocumentWithScenarioOutline(scenarioName));46 //act.47 var scenario = sut.GetScenarioOutline(scenarioName);48 //assert.49 Assert.NotNull(scenario);50 Assert.Same(sut.GherkinDocument.Feature.Children.First(), scenario);51 }52 [Fact]53 public void GetScenarioOutline_Gives_Null_If_Not_Found()54 {55 //arrange.56 var sut = new FeatureFile(CreateGherkinDocumentWithScenarioOutline("existing"));57 //act.58 var scenario = sut.GetScenarioOutline("non-existing");59 //assert.60 Assert.Null(scenario);61 }62 [Fact]63 public void GetBackground_Retrieves_If_Present()64 {65 var sut = new FeatureFile(CreateGherkinDocumentWithBackground());66 var background = sut.GetBackground();67 Assert.NotNull(background);68 }69 [Fact]70 public void GetBackground_Gives_Null_If_Not_Present()71 {72 var sut = new FeatureFile(CreateGherkinDocumentWithScenario("test"));73 var background = sut.GetBackground();74 Assert.Null(background);75 }76 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithScenario(77 string scenario,78 Gherkin.Ast.StepArgument stepArgument = null)79 {80 return new Gherkin.Ast.GherkinDocument(81 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]82 {83 new Gherkin.Ast.Scenario(84 new Gherkin.Ast.Tag[0],85 null,86 null,87 scenario,88 null,89 new Gherkin.Ast.Step[]{ })90 }),91 new Gherkin.Ast.Comment[0]);92 }93 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithBackground()94 {95 return new Gherkin.Ast.GherkinDocument(96 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]97 {98 new Gherkin.Ast.Background(99 null,100 null,101 null,102 null,103 new Gherkin.Ast.Step[]{ })104 }),105 new Gherkin.Ast.Comment[0]);106 }107 private static Gherkin.Ast.GherkinDocument CreateGherkinDocumentWithScenarioOutline(108 string scenario,109 Gherkin.Ast.StepArgument stepArgument = null)110 {111 return new Gherkin.Ast.GherkinDocument(112 new Gherkin.Ast.Feature(new Gherkin.Ast.Tag[0], null, null, null, null, null, new Gherkin.Ast.ScenarioDefinition[]113 {114 new Gherkin.Ast.ScenarioOutline(115 new Gherkin.Ast.Tag[0],116 null,117 null,118 scenario,119 null,120 new Gherkin.Ast.Step[]{ },121 new Gherkin.Ast.Examples[]{ })122 }),123 new Gherkin.Ast.Comment[0]);124 }125 }126}...
DataTableArgumentTests.cs
Source:DataTableArgumentTests.cs
...6{7 public sealed class DataTableArgumentTests8 {9 [Fact]10 public void DigestScenarioStepValues_Throws_Error_If_No_Arguments_And_No_DataTable()11 {12 //arrange.13 var sut = new DataTableArgument();14 //act / assert.15 Assert.Throws<InvalidOperationException>(() => sut.DigestScenarioStepValues(new string[0], null));16 }17 [Fact]18 public void DigestScenarioStepValues_Throws_Error_If_Arguments_Present_But_No_DataTable()19 {20 //arrange.21 var sut = new DataTableArgument();22 //act / assert.23 Assert.Throws<InvalidOperationException>(() => sut.DigestScenarioStepValues(new string[] { "1", "2", "3" }, null));24 }25 [Fact]26 public void DigestScenarioStepValues_Sets_Value_As_DataTable_When_Only_DataTable()27 {28 //arrange.29 var sut = new DataTableArgument();30 var dataTable = new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]31 {32 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]33 {34 new Gherkin.Ast.TableCell(null, "First argument"),35 new Gherkin.Ast.TableCell(null, "Second argument"),36 new Gherkin.Ast.TableCell(null, "Result"),37 }),38 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]39 {40 new Gherkin.Ast.TableCell(null, "1"),41 new Gherkin.Ast.TableCell(null, "2"),42 new Gherkin.Ast.TableCell(null, "3"),43 }),44 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]45 {46 new Gherkin.Ast.TableCell(null, "a"),47 new Gherkin.Ast.TableCell(null, "b"),48 new Gherkin.Ast.TableCell(null, "c"),49 })50 });51 //act.52 sut.DigestScenarioStepValues(new string[0], dataTable);53 //assert.54 Assert.Same(dataTable, sut.Value);55 }56 [Fact]57 public void DigestScenarioStepValues_Sets_Value_As_DataTable_When_DataTable_And_Other_Args_Present()58 {59 //arrange.60 var sut = new DataTableArgument();61 var dataTable = new Gherkin.Ast.DataTable(new Gherkin.Ast.TableRow[]62 {63 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]64 {65 new Gherkin.Ast.TableCell(null, "First argument"),66 new Gherkin.Ast.TableCell(null, "Second argument"),67 new Gherkin.Ast.TableCell(null, "Result"),68 }),69 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]70 {71 new Gherkin.Ast.TableCell(null, "1"),72 new Gherkin.Ast.TableCell(null, "2"),73 new Gherkin.Ast.TableCell(null, "3"),74 }),75 new Gherkin.Ast.TableRow(null, new Gherkin.Ast.TableCell[]76 {77 new Gherkin.Ast.TableCell(null, "a"),78 new Gherkin.Ast.TableCell(null, "b"),79 new Gherkin.Ast.TableCell(null, "c"),80 })81 });82 //act.83 sut.DigestScenarioStepValues(new string[] { "1", "2", "3" }, dataTable);84 //assert.85 Assert.Same(dataTable, sut.Value);86 }87 88 [Fact]89 public void IsSameAs_Identifies_Similar_Instances()90 {91 //arrange.92 var sut = new DataTableArgument();93 var other = new DataTableArgument();94 //act.95 var same = sut.IsSameAs(other);96 //assert.97 Assert.True(same);...
GherkinScenarioDefinitionTests.cs
Source:GherkinScenarioDefinitionTests.cs
...4using Xunit;5using Xunit.Gherkin.Quick;6namespace UnitTests7{8 public class GherkinScenarioTests9 {10 [Fact]11 public void ApplyBackground_WithNoBackground_ThrowsArgumentNullException()12 {13 var scenario = CreateTestScenario();14 Assert.Throws<ArgumentNullException>(() => scenario.ApplyBackground(null));15 }16 [Fact]17 public void ApplyBackground_WithBackground_PrependsBackgroundSteps()18 { 19 var scenario = CreateTestScenario();20 var backgroundSteps = new Gherkin.Ast.Step[] { new Gherkin.Ast.Step(null, null, "background", null) };21 var background = new Gherkin.Ast.Background(null, null, null, null, backgroundSteps);22 var modified = scenario.ApplyBackground(background);23 24 Assert.Equal(scenario.Location, modified.Location);25 Assert.Equal(scenario.Keyword, modified.Keyword);26 Assert.Equal(scenario.Name, modified.Name);27 Assert.Equal(scenario.Description, modified.Description);28 29 Assert.Equal(2, modified.Steps.Count());30 Assert.Equal("background", modified.Steps.ElementAt(0).Text);31 Assert.Equal("step", modified.Steps.ElementAt(1).Text);32 } 33 private static Gherkin.Ast.Scenario CreateTestScenario()34 {35 var tags = new Gherkin.Ast.Tag[] { new Gherkin.Ast.Tag(null, "test") };36 var location = new Gherkin.Ast.Location(1, 1);37 var steps = new Gherkin.Ast.Step[] { new Gherkin.Ast.Step(null, null, "step", null) };38 return new Gherkin.Ast.Scenario(tags, location, "keyword", "name", "description", steps); 39 }40 }41}...
FeatureFile.cs
Source:FeatureFile.cs
...8 public FeatureFile(GherkinDocument gherkinDocument)9 {10 GherkinDocument = gherkinDocument ?? throw new System.ArgumentNullException(nameof(gherkinDocument));11 }12 public global::Gherkin.Ast.Scenario GetScenario(string scenarioName)13 {14 return GherkinDocument.Feature.Children.FirstOrDefault(s => s.Name == scenarioName) as global::Gherkin.Ast.Scenario;15 }16 public global::Gherkin.Ast.Background GetBackground()17 {18 return GherkinDocument.Feature.Children.OfType<global::Gherkin.Ast.Background>().SingleOrDefault();19 }20 internal ScenarioOutline GetScenarioOutline(string scenarioOutlineName)21 {22 return GherkinDocument.Feature.Children.FirstOrDefault(s => s.Name == scenarioOutlineName) as global::Gherkin.Ast.ScenarioOutline;23 }24 }25}...
Scenario
Using AI Code Generation
1using Gherkin.Ast;2using Gherkin.Ast;3using Gherkin.Ast;4using Gherkin.Ast;5using Gherkin.Ast;6using Gherkin.Ast;7using Gherkin.Ast;8using Gherkin.Ast;9using Gherkin.Ast;10using Gherkin.Ast;11using Gherkin.Ast;12using Gherkin.Ast;13using Gherkin.Ast;14using Gherkin.Ast;15using Gherkin.Ast;16using Gherkin.Ast;17using Gherkin.Ast;18using Gherkin.Ast;19using Gherkin.Ast;20using Gherkin.Ast;21using Gherkin.Ast;22using Gherkin.Ast;23using Gherkin.Ast;
Scenario
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7{8 {9 static void Main(string[] args)10 {11 Scenario scenario = new Scenario("Scenario", "Scenario1", "Description", new List<Step>(), new List<Tag>(), new List<Comment>());12 Console.WriteLine(scenario.GetType());13 Console.ReadLine();14 }15 }16}17using System;18using System.Collections.Generic;19using System.Linq;20using System.Text;21using System.Threading.Tasks;22using Gherkin.Ast;23{24 {25 static void Main(string[] args)26 {27 ScenarioOutline scenarioOutline = new ScenarioOutline("Scenario Outline", "ScenarioOutline1", "Description", new List<Step>(), new List<Tag>(), new List<Comment>());28 Console.WriteLine(scenarioOutline.GetType());29 Console.ReadLine();30 }31 }32}33using System;34using System.Collections.Generic;35using System.Linq;36using System.Text;37using System.Threading.Tasks;38using Gherkin.Ast;39{40 {41 static void Main(string[] args)42 {43 Step step = new Step("Given", "Step1", new List<DataTableRow>(), new List<DocString>(), new List<Comment>());44 Console.WriteLine(step.GetType());45 Console.ReadLine();46 }47 }48}49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54using Gherkin.Ast;55{56 {57 static void Main(string[] args)58 {59 Tag tag = new Tag("@Tag1");60 Console.WriteLine(tag.GetType());61 Console.ReadLine();62 }63 }64}
Scenario
Using AI Code Generation
1using Gherkin.Ast;2using Gherkin.Ast;3using Gherkin.Ast;4using Gherkin.Ast;5using Gherkin.Ast;6using Gherkin.Ast;7using Gherkin.Ast;8using Gherkin.Ast;9using Gherkin.Ast;10using Gherkin.Ast;11using Gherkin.Ast;12using Gherkin.Ast;13using Gherkin.Ast;14using Gherkin.Ast;15using Gherkin.Parser;16using Gherkin.Parser;17using Gherkin.TokenMatcher;18using Gherkin.TokenMatcher;19using Gherkin.TokenMatcher;20using Gherkin.TokenMatcher;21{22 {23 using Gherkin.Dialects;24 using Gherkin.Dialects;
Scenario
Using AI Code Generation
1using Gherkin.Ast;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var parser = new Parser();12 var feature = parser.Parse("Feature: Test Feature 1 Scenario: Test Scenario 1 Given I have entered 50 into the calculator When I press add Then the result should be 100 on the screen");13 var scenario = feature.Children[0] as Scenario;14 Console.WriteLine(scenario.Name);15 Console.ReadLine();16 }17 }18}
Scenario
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using TechTalk.SpecFlow;7{8 {9 private readonly ScenarioContext _scenarioContext;10 public StepDefinition1(ScenarioContext scenarioContext)11 {12 _scenarioContext = scenarioContext;13 }14 [Given(@"I have entered (.*) into the calculator")]15 public void GivenIHaveEnteredIntoTheCalculator(int number)16 {17 _scenarioContext["number"] = number;18 }19 [When(@"I press add")]20 public void WhenIPressAdd()21 {22 int number = (int)_scenarioContext["number"];23 _scenarioContext["result"] = number + 1;24 }25 [Then(@"the result should be (.*) on the screen")]26 public void ThenTheResultShouldBeOnTheScreen(int result)27 {28 Assert.AreEqual(result, _scenarioContext["result"]);29 }30 }31}32using System;33using System.Collections.Generic;34using System.Linq;35using System.Text;36using System.Threading.Tasks;37using TechTalk.SpecFlow;38{39 {40 private readonly ScenarioContext _scenarioContext;41 public StepDefinition2(ScenarioContext scenarioContext)42 {43 _scenarioContext = scenarioContext;44 }45 [Given(@"I have entered (.*) into the calculator")]46 public void GivenIHaveEnteredIntoTheCalculator(int number)47 {48 _scenarioContext["number"] = number;49 }50 [When(@"I press add")]51 public void WhenIPressAdd()52 {53 int number = (int)_scenarioContext["number"];54 _scenarioContext["result"] = number + 1;55 }56 [Then(@"the result should be (.*) on the screen")]57 public void ThenTheResultShouldBeOnTheScreen(int result)58 {59 Assert.AreEqual(result, _scenarioContext["result"]);60 }61 }62}63using System;64using System.Collections.Generic;65using System.Linq;66using System.Text;67using System.Threading.Tasks;68using TechTalk.SpecFlow;
Scenario
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Gherkin.Ast;7using TechTalk.SpecFlow;8{9 {10 private Scenario _scenario;11 public StepDefinitions1(Scenario scenario)12 {13 _scenario = scenario;14 }15 [Given(@"I have entered (.*) into the calculator")]16 public void GivenIHaveEnteredIntoTheCalculator(int p0)17 {18 }19 }20}21using System;22using System.Collections.Generic;23using System.Linq;24using System.Text;25using System.Threading.Tasks;26using TechTalk.SpecFlow;27{28 {29 private ScenarioContext _scenarioContext;30 public StepDefinitions2(ScenarioContext scenarioContext)31 {32 _scenarioContext = scenarioContext;33 }34 [Given(@"I have entered (.*) into the calculator")]35 public void GivenIHaveEnteredIntoTheCalculator(int p0)36 {37 }38 }39}40using System;41using System.Collections.Generic;42using System.Linq;43using System.Text;44using System.Threading.Tasks;45using TechTalk.SpecFlow;46{47 {48 private ScenarioContext _scenarioContext;49 public StepDefinitions3(ScenarioContext scenarioContext)50 {51 _scenarioContext = scenarioContext;52 }53 [Given(@"I have entered (.*) into the calculator")]54 public void GivenIHaveEnteredIntoTheCalculator(int p0)55 {56 }57 }58}59using System;60using System.Collections.Generic;61using System.Linq;62using System.Text;63using System.Threading.Tasks;64using TechTalk.SpecFlow;65{66 {67 private ScenarioContext _scenarioContext;68 public StepDefinitions4(ScenarioContext scenarioContext
Scenario
Using AI Code Generation
1using Gherkin.Ast;2{3 {4 public string Name { get; set; }5 public string Description { get; set; }6 public string Keyword { get; set; }7 public int Line { get; set; }8 public string Id { get; set; }9 public List<Step> Steps { get; set; }10 public List<Tag> Tags { get; set; }11 }12}13using Gherkin.Ast;14{15 {16 public string Keyword { get; set; }17 public string Name { get; set; }18 public int Line { get; set; }19 public List<DataTableRow> DataTable { get; set; }20 public List<DocString> DocString { get; set; }21 }22}23using Gherkin.Ast;24{25 {26 public List<string> Cells { get; set; }27 public int Line { get; set; }28 }29}30using Gherkin.Ast;31{32 {33 public string ContentType { get; set; }34 public string Content { get; set; }35 public int Line { get; set; }36 }37}38using Gherkin.Ast;39{40 {41 public string Name { get; set; }42 public int Line { get; set; }43 }44}45using Gherkin;46{47 {48 public GherkinDialect GetDialect(string language, string location)49 {50 return null;51 }52 }53}
Scenario
Using AI Code Generation
1using Gherkin.Ast;2{3 {4 static void Main(string[] args)5 {6 var feature = new Feature("Feature", "Feature description", new List<Tag>(), new List<ScenarioDefinition>()7 {8 new Scenario(new List<Tag>(), "Scenario 1", "Scenario 1 description", new List<Step>()9 {10 new Step("Given", "Given step", 1, null, null),11 new Step("When", "When step", 2, null, null),12 new Step("Then", "Then step", 3, null, null)13 })14 });15 var featureFile = new GherkinDocument(new Language("en", "English"), new FeatureChild[] { feature }, null);16 var serializer = new Serializer();17 var serializedFeatureFile = serializer.Serialize(featureFile);18 Console.WriteLine(serializedFeatureFile);19 }20 }21}22using Gherkin.Ast;23{24 {25 static void Main(string[] args)26 {27 var feature = new Feature("Feature", "Feature description", new List<Tag>(), new List<ScenarioDefinition>()28 {29 new ScenarioOutline(new List<Tag>(), "Scenario Outline 1", "Scenario Outline 1 description", new List<Step>()30 {31 new Step("Given", "Given step", 1, null, null),32 new Step("When", "When step", 2, null, null),33 new Step("Then", "Then step", 3, null, null)34 }, new List<Examples>()35 {36 new Examples(new List<Tag>(), "Examples 1", "Examples 1 description", new List<TableRow>()37 {38 new TableRow(new List<TableCell>()39 {40 new TableCell("key 1", 1),41 new TableCell("key 2", 2)42 }, 1),43 new TableRow(new List<TableCell>()44 {45 new TableCell("value 1", 1),46 new TableCell("value 2", 2)47 }, 2)48 })49 })50 });51 var featureFile = new GherkinDocument(new Language("en", "English"), new FeatureChild[] { feature }, null);52 var serializer = new Serializer();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!