diff --git a/Behaviours/Synergy.Behaviours.Testing/FeatureGenerator.cs b/Behaviours/Synergy.Behaviours.Testing/FeatureGenerator.cs index 93650cb..110971c 100644 --- a/Behaviours/Synergy.Behaviours.Testing/FeatureGenerator.cs +++ b/Behaviours/Synergy.Behaviours.Testing/FeatureGenerator.cs @@ -6,17 +6,18 @@ namespace Synergy.Behaviours.Testing; public static class FeatureGenerator { + // TODO: Marcin Celej [from: Marcin Celej on: 03-05-2023]: Add way to generate non-fluent implementation of the methods + public static void Generate( this TBehaviour feature, string from, string to, - bool withMoreover = false, string[]? include = null, string[]? exclude = null, [CallerFilePath] string callerFilePath = "" ) { - var code = feature.Generate(from, withMoreover, include, exclude, callerFilePath); + var code = feature.Generate(from, include, exclude, callerFilePath); var destinationFilePath = Path.Combine(Path.GetDirectoryName(callerFilePath), to); File.WriteAllText(destinationFilePath, code.ToString()); } @@ -24,7 +25,6 @@ public static void Generate( public static string Generate( this TBehaviour featureClass, string from, - bool withMoreover = false, string[]? include = null, string[]? exclude = null, [CallerFilePath] string callerFilePath = "" @@ -238,10 +238,14 @@ void CloseScenario() { if (scenarioMethod != null) { - if (withMoreover) - code.AppendLine($" .Moreover().After{scenarioMethod}();"); - else - code.AppendLine($" ;"); + code.AppendLine($" .Moreover().After{scenarioMethod}();"); + code.AppendLine(); + code.AppendLine( + $" partial void After{scenarioMethod}(" + + // "[CallerMemberName] string callerMemberName = \"\", " + + // "[CallerFilePath] string callerFilePath = \"\"" + + ");" + ); code.AppendLine(); } diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Feature.verified.cs b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Feature.verified.cs index 2beb0ce..5a726f4 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Feature.verified.cs +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Feature.verified.cs @@ -20,7 +20,9 @@ public void AddTwoNumbers() // Scenario: Add two numbers .And().TheSecondNumberIs70() // And the second number is 70 .When().TheTwoNumbersAreAdded() // When the two numbers are added .Then().TheResultShouldBe120() // Then the result should be 120 - ; + .Moreover().AfterAddTwoNumbers(); + + partial void AfterAddTwoNumbers(); [Xunit.Fact] // @Add @@ -31,7 +33,9 @@ public void AddTwoNumbersInDifferentWay() // Scenario: Add two numbers in differ .And().TheSecondNumberIs70() // * the second number is 70 .When().TheTwoNumbersAreAdded() // When the two numbers are added .Then().TheResultShouldBe120() // Then the result should be 120 - ; + .Moreover().AfterAddTwoNumbersInDifferentWay(); + + partial void AfterAddTwoNumbersInDifferentWay(); // Rule: Subtracting numbers diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Steps.cs b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Steps.cs index 0707108..d55cde2 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Steps.cs +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.Steps.cs @@ -1,4 +1,5 @@ -using Synergy.Behaviours.Testing; +using System.Runtime.CompilerServices; +using Synergy.Behaviours.Testing; namespace Synergy.Behaviours.Tests.Samples; @@ -16,35 +17,33 @@ public async Task GenerateFeature() await Verifier .Verify(code, "cs") - .UseFileName("Calculator.Feature"); + .UseFileName("Calculator.Feature") + .AutoVerify(); } + private Calculator _calculator; private CalculatorFeature UserOpenedCalculator() { + this._calculator = new Calculator(); return this; } - private int _firstNumber; - private CalculatorFeature TheFirstNumberIs50() { - this._firstNumber = 50; + this._calculator.FirstNumber = 50; return this; } - private int _secondNumber; - private CalculatorFeature TheSecondNumberIs70() { - this._secondNumber = 70; + this._calculator.SecondNumber = 70; return this; } private int _result; private CalculatorFeature TheTwoNumbersAreAdded() { - var calculator = new Calculator { FirstNumber = this._firstNumber, SecondNumber = this._secondNumber }; - this._result = calculator.Add(); + this._result = this._calculator.Add(); return this; } @@ -54,9 +53,11 @@ private CalculatorFeature TheResultShouldBe120() return this; } - private CalculatorFeature VerifyAddTwoNumbers() + partial void AfterAddTwoNumbers() { - return this; + Verifier.Verify(this._calculator) + .UseDirectory("Snapshots") + .GetAwaiter().GetResult(); } private CalculatorFeature TwoNumbers() diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.feature b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.feature index ed30981..ba48d0b 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.feature +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/Calculator.feature @@ -3,9 +3,6 @@ Feature: Calculator ![Calculator](https://specflow.org/wp-content/uploads/2020/09/calculator.png) Simple calculator for performing calculations on **two** numbers - - Link to a feature: [Calculator](SpecFlowCalculator.Specs/Features/Calculator.feature) - ***Further read***: **[Learn more about how to generate Living Documentation](https://docs.specflow.org/projects/specflow-livingdoc/en/latest/LivingDocGenerator/Generating-Documentation.html)** Background: Given User opened calculator diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.verified.cs b/Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.cs similarity index 90% rename from Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.verified.cs rename to Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.cs index c329dfb..3fbab43 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.verified.cs +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/New.Feature.cs @@ -1,4 +1,4 @@ -// +// using System.CodeDom.Compiler; namespace Synergy.Behaviours.Tests.Samples; diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/New.Steps.cs b/Behaviours/Synergy.Behaviours.Tests/Samples/New.Steps.cs index 003942e..dc9de7d 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Samples/New.Steps.cs +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/New.Steps.cs @@ -6,15 +6,11 @@ namespace Synergy.Behaviours.Tests.Samples; public partial class NewFeature : Feature { [Fact] - public async Task GenerateFeature() + public void GenerateFeature() { - var code = this.Generate( - from: "New.feature" + this.Generate( + from: "New.feature", + to: "New.Feature.cs" ); - - await Verifier - .Verify(code, "cs") - .UseFileName("New.Feature") - .AutoVerify(); } } \ No newline at end of file diff --git a/Behaviours/Synergy.Behaviours.Tests/Samples/Snapshots/CalculatorFeature.AddTwoNumbers.verified.txt b/Behaviours/Synergy.Behaviours.Tests/Samples/Snapshots/CalculatorFeature.AddTwoNumbers.verified.txt new file mode 100644 index 0000000..8f1289d --- /dev/null +++ b/Behaviours/Synergy.Behaviours.Tests/Samples/Snapshots/CalculatorFeature.AddTwoNumbers.verified.txt @@ -0,0 +1,4 @@ +{ + FirstNumber: 50, + SecondNumber: 70 +} \ No newline at end of file diff --git a/Behaviours/Synergy.Behaviours.Tests/Synergy.Behaviours.Tests.csproj b/Behaviours/Synergy.Behaviours.Tests/Synergy.Behaviours.Tests.csproj index e53582a..889b03b 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Synergy.Behaviours.Tests.csproj +++ b/Behaviours/Synergy.Behaviours.Tests/Synergy.Behaviours.Tests.csproj @@ -37,10 +37,10 @@ Calculator.feature - + New.feature - + New.feature diff --git a/Behaviours/Synergy.Behaviours.Tests/Todos/Todos.Technical.Debt.verified.md b/Behaviours/Synergy.Behaviours.Tests/Todos/Todos.Technical.Debt.verified.md index d1321d2..2bed4cd 100644 --- a/Behaviours/Synergy.Behaviours.Tests/Todos/Todos.Technical.Debt.verified.md +++ b/Behaviours/Synergy.Behaviours.Tests/Todos/Todos.Technical.Debt.verified.md @@ -1,3 +1,9 @@ # Technical Debt for Synergy.Contracts -Total: 0 +Total: 2 + +## [FeatureGenerator.cs](../../Synergy.Behaviours.Testing/FeatureGenerator.cs) +- TODO: Marcin Celej [from: Marcin Celej on: 03-05-2023]: Add way to generate non-fluent implementation of the methods + +## [New.feature](../Samples/New.feature) +- TODO: Provide scenarios here, check the sample down here