From be3d50201924e356ed014b1e02f66c591800b9ca Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Tue, 26 May 2026 11:59:39 +0100 Subject: [PATCH 1/4] avoid calling _createTitle function multiple times. --- src/TestStack.BDDfy/StepTitle.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TestStack.BDDfy/StepTitle.cs b/src/TestStack.BDDfy/StepTitle.cs index d3e8daec..79721b2a 100644 --- a/src/TestStack.BDDfy/StepTitle.cs +++ b/src/TestStack.BDDfy/StepTitle.cs @@ -5,11 +5,9 @@ namespace TestStack.BDDfy public class StepTitle { private readonly Func _createTitle; + private string _title; - public StepTitle(string title) - { - _createTitle = () => title; - } + public StepTitle(string title) => _createTitle = () => _title = title; public StepTitle(Func createTitle) { @@ -23,7 +21,7 @@ public static implicit operator string(StepTitle title) public override string ToString() { - return _createTitle(); + return _title ??= _createTitle(); } } } \ No newline at end of file From 97c09bf37ef4e4066a8b44054568de0534d754d9 Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Tue, 26 May 2026 12:11:01 +0100 Subject: [PATCH 2/4] cache step title text once generated --- src/TestStack.BDDfy/Step.cs | 12 ++++++------ src/TestStack.BDDfy/StepTitle.cs | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/TestStack.BDDfy/Step.cs b/src/TestStack.BDDfy/Step.cs index ac331ede..1f667a7f 100644 --- a/src/TestStack.BDDfy/Step.cs +++ b/src/TestStack.BDDfy/Step.cs @@ -6,11 +6,11 @@ namespace TestStack.BDDfy { public class Step { - private readonly StepTitle _title; - + private readonly StepTitle _stepTitle; + private string _title; public Step( Func action, - StepTitle title, + StepTitle stepTitle, bool asserts, ExecutionOrder executionOrder, bool shouldReport, @@ -23,13 +23,13 @@ public Step( Result = Result.NotExecuted; Action = action; Arguments = arguments; - _title = title; + _stepTitle = stepTitle; } public Step(Step step) { Id = step.Id; - _title = step._title; + _stepTitle = step._stepTitle; Asserts = step.Asserts; ExecutionOrder = step.ExecutionOrder; ShouldReport = step.ShouldReport; @@ -46,7 +46,7 @@ public string Title { get { - return _title.ToString(); + return _title??= _stepTitle.ToString(); } } diff --git a/src/TestStack.BDDfy/StepTitle.cs b/src/TestStack.BDDfy/StepTitle.cs index 79721b2a..64250e57 100644 --- a/src/TestStack.BDDfy/StepTitle.cs +++ b/src/TestStack.BDDfy/StepTitle.cs @@ -5,9 +5,8 @@ namespace TestStack.BDDfy public class StepTitle { private readonly Func _createTitle; - private string _title; - public StepTitle(string title) => _createTitle = () => _title = title; + public StepTitle(string title) => _createTitle = () => title; public StepTitle(Func createTitle) { @@ -21,7 +20,7 @@ public static implicit operator string(StepTitle title) public override string ToString() { - return _title ??= _createTitle(); + return _createTitle(); } } } \ No newline at end of file From 8f6ff5e6878ea9d6b2bd9e5c64eb307312f16fd6 Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Tue, 26 May 2026 12:16:48 +0100 Subject: [PATCH 3/4] simplify property definition --- src/TestStack.BDDfy/Step.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/TestStack.BDDfy/Step.cs b/src/TestStack.BDDfy/Step.cs index 1f667a7f..b2111df2 100644 --- a/src/TestStack.BDDfy/Step.cs +++ b/src/TestStack.BDDfy/Step.cs @@ -42,16 +42,8 @@ public Step(Step step) internal Func Action { get; set; } public bool Asserts { get; private set; } public bool ShouldReport { get; private set; } - public string Title - { - get - { - return _title??= _stepTitle.ToString(); - } - } - + public string Title => _title??= _stepTitle.ToString(); public ExecutionOrder ExecutionOrder { get; private set; } - public Result Result { get; set; } public Exception Exception { get; set; } public int ExecutionSubOrder { get; set; } From 896582d16319e0fce1cf03665f1c91f568cff952 Mon Sep 17 00:00:00 2001 From: Gurpreet Singh Date: Tue, 26 May 2026 12:18:16 +0100 Subject: [PATCH 4/4] use implicit string conversion --- src/TestStack.BDDfy/Step.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestStack.BDDfy/Step.cs b/src/TestStack.BDDfy/Step.cs index b2111df2..444af43c 100644 --- a/src/TestStack.BDDfy/Step.cs +++ b/src/TestStack.BDDfy/Step.cs @@ -42,7 +42,7 @@ public Step(Step step) internal Func Action { get; set; } public bool Asserts { get; private set; } public bool ShouldReport { get; private set; } - public string Title => _title??= _stepTitle.ToString(); + public string Title => _title??= _stepTitle; public ExecutionOrder ExecutionOrder { get; private set; } public Result Result { get; set; } public Exception Exception { get; set; }