From c4060cee31cf419a9cddc9aa78b2e5bfd8a6eeb0 Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 4 Oct 2023 02:00:06 +0700 Subject: [PATCH 1/3] allure-xunit: provide default config when allureConfig.json is missing Fixes #381 --- Allure.XUnit/AllureXunitConfiguration.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Allure.XUnit/AllureXunitConfiguration.cs b/Allure.XUnit/AllureXunitConfiguration.cs index b3409e17..9c71b47c 100644 --- a/Allure.XUnit/AllureXunitConfiguration.cs +++ b/Allure.XUnit/AllureXunitConfiguration.cs @@ -1,10 +1,9 @@ -using Allure.Net.Commons; +using System; +using System.Collections.Generic; +using Allure.Net.Commons; using Allure.Net.Commons.Configuration; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.IO; #nullable enable @@ -16,9 +15,9 @@ internal class AllureXunitConfiguration : AllureConfiguration [JsonConstructor] protected AllureXunitConfiguration( - string title, - string directory, - HashSet links + string? title, + string? directory, + HashSet? links ) : base(title, directory, links) { } @@ -34,8 +33,6 @@ static readonly Lazy currentConfig static AllureXunitConfiguration ParseCurrentConfig() => JObject.Parse( AllureLifecycle.Instance.JsonConfiguration )["allure"]?.ToObject() - ?? throw new FileNotFoundException( - "allureConfig.json not found" - ); + ?? new AllureXunitConfiguration(null, null, null); } } From be4a4c58150685664d3806e09eda0403a8ee167d Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 4 Oct 2023 04:24:32 +0700 Subject: [PATCH 2/3] Fix async step/fixture wrapper functions - make async Step, Before and After obey .NET's ExecutionContext capturing rules - refactor CoreStepsHelper to be more testable - write tests for CoreStepsHelper's Step, Before and After More tests are needed to fully cover CoreStepsHelper. Fixes #383 Fixed #388 --- Allure.Net.Commons.Tests/StepFunctionTests.cs | 378 ++++++++++++++++++ Allure.Net.Commons/Steps/CoreStepsHelper.cs | 248 ++++++++---- 2 files changed, 541 insertions(+), 85 deletions(-) create mode 100644 Allure.Net.Commons.Tests/StepFunctionTests.cs diff --git a/Allure.Net.Commons.Tests/StepFunctionTests.cs b/Allure.Net.Commons.Tests/StepFunctionTests.cs new file mode 100644 index 00000000..7c46d9fc --- /dev/null +++ b/Allure.Net.Commons.Tests/StepFunctionTests.cs @@ -0,0 +1,378 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Allure.Net.Commons.Steps; +using NUnit.Framework; + +namespace Allure.Net.Commons.Tests; + +class StepAndFixtureFunctionTests +{ + AllureLifecycle lifecycle; + + static readonly Action errorAction = () => throw new Exception(); + static readonly Func errorFunc = () => throw new Exception(); + static readonly Func asyncErrorAction + = async () => await Task.FromException(new Exception()); + static readonly Func> asyncErrorFunc + = async () => await Task.FromException(new Exception()); + + [SetUp] + public void SetUp() + { + this.lifecycle = new AllureLifecycle(); + CoreStepsHelper.CurrentLifecycle = this.lifecycle; + } + + [Test] + public void ActionCanBeConvertedToBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + CoreStepsHelper.Before("My fixture", () => { }); + + this.AssertBeforeFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void ActionCanBeConvertedToFailedBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.Before("My fixture", errorAction), + Throws.Exception + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public void FuncCanBeConvertedToBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + var result = CoreStepsHelper.Before("My fixture", () => 0); + + Assert.That(result, Is.Zero); + this.AssertBeforeFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void FuncCanBeConvertedToFailedBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.Before("My fixture", errorFunc), + Throws.Exception + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public async Task AsyncActionCanBeConvertedToBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + await CoreStepsHelper.Before( + "My fixture", + async () => await Task.CompletedTask + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void AsyncActionCanBeConvertedToFailedBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.Before( + "My fixture", + asyncErrorAction + ), + Throws.Exception + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public async Task AsyncFuncCanBeConvertedToBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + await CoreStepsHelper.Before( + "My fixture", + async () => await Task.FromResult(0) + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void AsyncFuncCanBeConvertedToFailedBeforeFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.Before( + "My fixture", + asyncErrorFunc + ), + Throws.Exception + ); + + this.AssertBeforeFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public void ActionCanBeConvertedToAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + CoreStepsHelper.After("My fixture", () => { }); + + this.AssertAfterFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void ActionCanBeConvertedToFailedAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.After("My fixture", errorAction), + Throws.Exception + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public void FuncCanBeConvertedToAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + var result = CoreStepsHelper.After("My fixture", () => 0); + + Assert.That(result, Is.Zero); + this.AssertAfterFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void FuncCanBeConvertedToFailedAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.After("My fixture", errorFunc), + Throws.Exception + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public async Task AsyncActionCanBeConvertedToAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + await CoreStepsHelper.After( + "My fixture", + async () => await Task.CompletedTask + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void AsyncActionCanBeConvertedToFailedAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.After( + "My fixture", + asyncErrorAction + ), + Throws.Exception + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public async Task AsyncFuncCanBeConvertedToAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + await CoreStepsHelper.After( + "My fixture", + async () => await Task.FromResult(0) + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.passed); + } + + [Test] + public void AsyncFuncCanBeConvertedToFailedAfterFixture() + { + this.lifecycle.StartTestContainer(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.After( + "My fixture", + asyncErrorFunc + ), + Throws.Exception + ); + + this.AssertAfterFixtureCompleted("My fixture", Status.failed); + } + + [Test] + public void StepWithNoActionCanBeCreated() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + CoreStepsHelper.Step("My step"); + + this.AssertStepCompleted("My step", Status.passed); + } + + [Test] + public void ActionCanBeConvertedToStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + CoreStepsHelper.Step("My step", () => { }); + + this.AssertStepCompleted("My step", Status.passed); + } + + [Test] + public void ActionCanBeConvertedToFailedStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.Step("My step", errorAction), + Throws.Exception + ); + + this.AssertStepCompleted("My step", Status.failed); + } + + [Test] + public void FuncCanBeConvertedToStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + var result = CoreStepsHelper.Step("My step", () => 0); + + Assert.That(result, Is.Zero); + this.AssertStepCompleted("My step", Status.passed); + } + + [Test] + public void FuncCanBeConvertedToFailedStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + Assert.That( + () => CoreStepsHelper.Step("My step", errorFunc), + Throws.Exception + ); + + this.AssertStepCompleted("My step", Status.failed); + } + + [Test] + public async Task AsyncActionCanBeConvertedToStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + await CoreStepsHelper.Step( + "My step", + async () => await Task.CompletedTask + ); + + this.AssertStepCompleted("My step", Status.passed); + } + + [Test] + public void AsyncActionCanBeConvertedToFailedStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.Step("My step", asyncErrorAction), + Throws.Exception + ); + + this.AssertStepCompleted("My step", Status.failed); + } + + [Test] + public async Task AsyncFuncCanBeConvertedToStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + await CoreStepsHelper.Step( + "My step", + async () => await Task.FromResult(0) + ); + + this.AssertStepCompleted("My step", Status.passed); + } + + [Test] + public void AsyncFuncCanBeConvertedToFailedStep() + { + this.lifecycle.StartTestCase(new() { uuid = "uuid" }); + + Assert.That( + async () => await CoreStepsHelper.Step("My step", asyncErrorFunc), + Throws.Exception + ); + + this.AssertStepCompleted("My step", Status.failed); + } + + void AssertBeforeFixtureCompleted(string name, Status status) => + this.AssertFixtureCompleted(tc => tc.befores, name, status); + + void AssertAfterFixtureCompleted(string name, Status status) => + this.AssertFixtureCompleted(tc => tc.afters, name, status); + + void AssertFixtureCompleted( + Func> getFixtures, + string name, + Status status + ) + { + Assert.That(this.lifecycle.Context.HasFixture, Is.False); + Assert.That(this.lifecycle.Context.HasContainer); + var fixtures = getFixtures(this.lifecycle.Context.CurrentContainer); + Assert.That(fixtures, Has.Count.EqualTo(1)); + var fixture = fixtures.First(); + Assert.That(fixture.name, Is.EqualTo(name)); + Assert.That(fixture.status, Is.EqualTo(status)); + } + + void AssertStepCompleted(string name, Status status) + { + Assert.That(this.lifecycle.Context.HasStep, Is.False); + Assert.That(this.lifecycle.Context.HasTest); + var steps = this.lifecycle.Context.CurrentTest.steps; + Assert.That(steps, Has.Count.EqualTo(1)); + var fixture = steps.First(); + Assert.That(fixture.name, Is.EqualTo(name)); + Assert.That(fixture.status, Is.EqualTo(status)); + } +} diff --git a/Allure.Net.Commons/Steps/CoreStepsHelper.cs b/Allure.Net.Commons/Steps/CoreStepsHelper.cs index 8673446b..64f2bc7d 100644 --- a/Allure.Net.Commons/Steps/CoreStepsHelper.cs +++ b/Allure.Net.Commons/Steps/CoreStepsHelper.cs @@ -9,27 +9,77 @@ namespace Allure.Net.Commons.Steps; public class CoreStepsHelper { + static AllureLifecycle? lifecycleInstance; + + internal static AllureLifecycle CurrentLifecycle + { + get => lifecycleInstance ?? AllureLifecycle.Instance; + set => lifecycleInstance = value; + } + public static IStepLogger? StepLogger { get; set; } #region Fixtures public static void StartBeforeFixture(string name) { - AllureLifecycle.Instance.StartBeforeFixture(new() { name = name }); + CurrentLifecycle.StartBeforeFixture(new() { name = name }); StepLogger?.BeforeStarted?.Log(name); } public static void StartAfterFixture(string name) { - AllureLifecycle.Instance.StartAfterFixture(new() { name = name }); + CurrentLifecycle.StartAfterFixture(new() { name = name }); StepLogger?.AfterStarted?.Log(name); } + public static void PassFixture() => CurrentLifecycle.StopFixture( + result => + { + result.status = Status.passed; + StepLogger?.StepPassed?.Log(result.name); + } + ); + + public static void PassFixture(Action updateResults) + { + CurrentLifecycle.UpdateFixture(updateResults); + PassFixture(); + } + + public static void FailFixture() => CurrentLifecycle.StopFixture( + result => + { + result.status = Status.failed; + StepLogger?.StepFailed?.Log(result.name); + } + ); + + public static void FailFixture(Action updateResults) + { + CurrentLifecycle.UpdateFixture(updateResults); + FailFixture(); + } + + public static void BrokeFixture() => CurrentLifecycle.StopFixture( + result => + { + result.status = Status.broken; + StepLogger?.StepBroken?.Log(result.name); + } + ); + + public static void BrokeFixture(Action updateResults) + { + CurrentLifecycle.UpdateFixture(updateResults); + BrokeFixture(); + } + public static void StopFixture(Action updateResults) => - AllureLifecycle.Instance.StopFixture(updateResults); + CurrentLifecycle.StopFixture(updateResults); public static void StopFixture() => - AllureLifecycle.Instance.StopFixture(); + CurrentLifecycle.StopFixture(); #endregion @@ -37,17 +87,17 @@ public static void StopFixture() => public static void StartStep(string name) { - AllureLifecycle.Instance.StartStep(new() { name = name }); + CurrentLifecycle.StartStep(new() { name = name }); StepLogger?.StepStarted?.Log(name); } public static void StartStep(string name, Action updateResults) { StartStep(name); - AllureLifecycle.Instance.UpdateStep(updateResults); + CurrentLifecycle.UpdateStep(updateResults); } - public static void PassStep() => AllureLifecycle.Instance.StopStep( + public static void PassStep() => CurrentLifecycle.StopStep( result => { result.status = Status.passed; @@ -57,11 +107,11 @@ public static void PassStep() => AllureLifecycle.Instance.StopStep( public static void PassStep(Action updateResults) { - AllureLifecycle.Instance.UpdateStep(updateResults); + CurrentLifecycle.UpdateStep(updateResults); PassStep(); } - public static void FailStep() => AllureLifecycle.Instance.StopStep( + public static void FailStep() => CurrentLifecycle.StopStep( result => { result.status = Status.failed; @@ -71,11 +121,11 @@ public static void FailStep() => AllureLifecycle.Instance.StopStep( public static void FailStep(Action updateResults) { - AllureLifecycle.Instance.UpdateStep(updateResults); + CurrentLifecycle.UpdateStep(updateResults); FailStep(); } - public static void BrokeStep() => AllureLifecycle.Instance.StopStep( + public static void BrokeStep() => CurrentLifecycle.StopStep( result => { result.status = Status.broken; @@ -85,7 +135,7 @@ public static void BrokeStep() => AllureLifecycle.Instance.StopStep( public static void BrokeStep(Action updateResults) { - AllureLifecycle.Instance.UpdateStep(updateResults); + CurrentLifecycle.UpdateStep(updateResults); BrokeStep(); } @@ -94,136 +144,164 @@ public static void BrokeStep(Action updateResults) #region Misc public static void UpdateTestResult(Action update) => - AllureLifecycle.Instance.UpdateTestCase(update); + CurrentLifecycle.UpdateTestCase(update); #endregion - public static Task Step(string name, Func> action) - { - StartStep(name); - return Execute(action); - } + public static async Task Step(string name, Func> action) => + await ExecuteStep(name, action); - public static T Step(string name, Func action) - { - StartStep(name); - return Execute(name, action); - } + public static T Step(string name, Func action) => + ExecuteStep(name, action); public static void Step(string name, Action action) { - Step(name, (Func)(() => + ExecuteStep(name, () => { action(); - return null; - })); + return null as object; + }); } - public static Task Step(string name, Func action) - { - return Step(name, async () => + public static async Task Step(string name, Func action) => + await ExecuteStep(name, async () => { await action(); return Task.FromResult(null); }); - } - public static void Step(string name) - { + public static void Step(string name) => Step(name, () => { }); - } - public static Task Before(string name, Func> action) - { - StartBeforeFixture(name); - return Execute(action); - } + public static async Task Before(string name, Func> action) => + await ExecuteFixture(name, StartBeforeFixture, action); - public static T Before(string name, Func action) - { - StartBeforeFixture(name); - return Execute(name, action); - } + public static T Before(string name, Func action) => + ExecuteFixture(name, StartBeforeFixture, action); - public static void Before(string name, Action action) - { - Before(name, (Func)(() => + public static void Before(string name, Action action) => + Before(name, () => { action(); - return null; - })); - } + return null as object; + }); - public static Task Before(string name, Func action) - { - return Before(name, async () => + public static async Task Before(string name, Func action) => + await ExecuteFixture(name, StartBeforeFixture, async () => { await action(); return Task.FromResult(null); }); - } - public static Task After(string name, Func> action) - { - StartAfterFixture(name); - return Execute(action); - } + public static async Task After(string name, Func> action) => + await ExecuteFixture(name, StartAfterFixture, action); - public static T After(string name, Func action) - { - StartAfterFixture(name); - return Execute(name, action); - } + public static T After(string name, Func action) => + ExecuteFixture(name, StartAfterFixture, action); - public static void After(string name, Action action) - { - After(name, (Func)(() => + public static void After(string name, Action action) => + After(name, () => { action(); - return null; - })); - } + return null as object; + }); - public static Task After(string name, Func action) - { - return After(name, async () => + public static async Task After(string name, Func action) => + await ExecuteFixture(name, StartAfterFixture, async () => { await action(); return Task.FromResult(null); }); - } - private static async Task Execute(Func> action) + static T ExecuteStep(string name, Func action) => + ExecuteAction( + name, + StartStep, + action, + PassStep, + FailStep + ); + + static async Task ExecuteStep( + string name, + Func> action + ) => + await ExecuteAction( + () => StartStep(name), + action, + PassStep, + FailStep + ); + + static T ExecuteFixture( + string name, + Action start, + Func action + ) => + ExecuteAction( + name, + start, + action, + PassFixture, + FailFixture + ); + + static async Task ExecuteFixture( + string name, + Action startFixture, + Func> action + ) => + await ExecuteAction( + () => startFixture(name), + action, + PassFixture, + FailFixture + ); + + private static async Task ExecuteAction( + Action start, + Func> action, + Action pass, + Action fail + ) { T result; + start(); try { result = await action(); } catch (Exception) { - FailStep(); + fail(); throw; } - PassStep(); + pass(); return result; } - private static T Execute(string name, Func action) + private static T ExecuteAction( + string name, + Action start, + Func action, + Action pass, + Action fail + ) { T result; + start(name); try { result = action(); } catch (Exception e) { - FailStep(); + fail(); throw new StepFailedException(name, e); } - PassStep(); + pass(); return result; } @@ -259,13 +337,13 @@ public static void PassStep( Action? updateResults = null ) { - AllureLifecycle.Instance.UpdateStep(uuid, result => + CurrentLifecycle.UpdateStep(uuid, result => { result.status = Status.passed; updateResults?.Invoke(result); StepLogger?.StepPassed?.Log(result.name); }); - AllureLifecycle.Instance.StopStep(uuid); + CurrentLifecycle.StopStep(uuid); } [Obsolete(AllureLifecycle.EXPLICIT_STATE_MGMT_OBSOLETE)] @@ -275,13 +353,13 @@ public static void FailStep( Action? updateResults = null ) { - AllureLifecycle.Instance.UpdateStep(uuid, result => + CurrentLifecycle.UpdateStep(uuid, result => { result.status = Status.failed; updateResults?.Invoke(result); StepLogger?.StepFailed?.Log(result.name); }); - AllureLifecycle.Instance.StopStep(uuid); + CurrentLifecycle.StopStep(uuid); } [Obsolete(AllureLifecycle.EXPLICIT_STATE_MGMT_OBSOLETE)] @@ -291,13 +369,13 @@ public static void BrokeStep( Action? updateResults = null ) { - AllureLifecycle.Instance.UpdateStep(uuid, result => + CurrentLifecycle.UpdateStep(uuid, result => { result.status = Status.broken; updateResults?.Invoke(result); StepLogger?.StepBroken?.Log(result.name); }); - AllureLifecycle.Instance.StopStep(uuid); + CurrentLifecycle.StopStep(uuid); } #endregion From 09abb08860fb45182337a6daf89a81bf0ff5a6cb Mon Sep 17 00:00:00 2001 From: Maksim Stepanov <17935127+delatrie@users.noreply.github.com> Date: Wed, 11 Oct 2023 02:22:08 +0700 Subject: [PATCH 3/3] Add async suffix to private step methods This helps to make distinction more clear to a reader. --- Allure.Net.Commons/Steps/CoreStepsHelper.cs | 52 ++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Allure.Net.Commons/Steps/CoreStepsHelper.cs b/Allure.Net.Commons/Steps/CoreStepsHelper.cs index 64f2bc7d..46951c07 100644 --- a/Allure.Net.Commons/Steps/CoreStepsHelper.cs +++ b/Allure.Net.Commons/Steps/CoreStepsHelper.cs @@ -148,11 +148,8 @@ public static void UpdateTestResult(Action update) => #endregion - public static async Task Step(string name, Func> action) => - await ExecuteStep(name, action); - - public static T Step(string name, Func action) => - ExecuteStep(name, action); + public static void Step(string name) => + Step(name, () => { }); public static void Step(string name, Action action) { @@ -163,21 +160,18 @@ public static void Step(string name, Action action) }); } + public static T Step(string name, Func action) => + ExecuteStep(name, action); + public static async Task Step(string name, Func action) => - await ExecuteStep(name, async () => + await ExecuteStepAsync(name, async () => { await action(); return Task.FromResult(null); }); - public static void Step(string name) => - Step(name, () => { }); - - public static async Task Before(string name, Func> action) => - await ExecuteFixture(name, StartBeforeFixture, action); - - public static T Before(string name, Func action) => - ExecuteFixture(name, StartBeforeFixture, action); + public static async Task Step(string name, Func> action) => + await ExecuteStepAsync(name, action); public static void Before(string name, Action action) => Before(name, () => @@ -186,18 +180,18 @@ public static void Before(string name, Action action) => return null as object; }); + public static T Before(string name, Func action) => + ExecuteFixture(name, StartBeforeFixture, action); + public static async Task Before(string name, Func action) => - await ExecuteFixture(name, StartBeforeFixture, async () => + await ExecuteFixtureAsync(name, StartBeforeFixture, async () => { await action(); return Task.FromResult(null); }); - public static async Task After(string name, Func> action) => - await ExecuteFixture(name, StartAfterFixture, action); - - public static T After(string name, Func action) => - ExecuteFixture(name, StartAfterFixture, action); + public static async Task Before(string name, Func> action) => + await ExecuteFixtureAsync(name, StartBeforeFixture, action); public static void After(string name, Action action) => After(name, () => @@ -206,13 +200,19 @@ public static void After(string name, Action action) => return null as object; }); + public static T After(string name, Func action) => + ExecuteFixture(name, StartAfterFixture, action); + public static async Task After(string name, Func action) => - await ExecuteFixture(name, StartAfterFixture, async () => + await ExecuteFixtureAsync(name, StartAfterFixture, async () => { await action(); return Task.FromResult(null); }); + public static async Task After(string name, Func> action) => + await ExecuteFixtureAsync(name, StartAfterFixture, action); + static T ExecuteStep(string name, Func action) => ExecuteAction( name, @@ -222,11 +222,11 @@ static T ExecuteStep(string name, Func action) => FailStep ); - static async Task ExecuteStep( + static async Task ExecuteStepAsync( string name, Func> action ) => - await ExecuteAction( + await ExecuteActionAsync( () => StartStep(name), action, PassStep, @@ -246,19 +246,19 @@ Func action FailFixture ); - static async Task ExecuteFixture( + static async Task ExecuteFixtureAsync( string name, Action startFixture, Func> action ) => - await ExecuteAction( + await ExecuteActionAsync( () => startFixture(name), action, PassFixture, FailFixture ); - private static async Task ExecuteAction( + private static async Task ExecuteActionAsync( Action start, Func> action, Action pass,