diff --git a/src/Wolfgang.TryPattern/Try.cs b/src/Wolfgang.TryPattern/Try.cs index 614ff0d..3e53957 100644 --- a/src/Wolfgang.TryPattern/Try.cs +++ b/src/Wolfgang.TryPattern/Try.cs @@ -38,38 +38,6 @@ public static Result Run(Action action) - /// - /// Executes the specified action asynchronously, catching any exception that may occur. - /// - /// The action to execute. - /// The CancellationToken to monitor. - /// - /// A of representing the asynchronous operation. - /// - public static async Task RunAsync(Action action, CancellationToken token = default) - { - if (action == null) - { - throw new ArgumentNullException(nameof(action)); - } - - try - { - await Task.Run(action, token).ConfigureAwait(false); - return Result.Success(); - } - catch (OperationCanceledException) - { - throw; - } - catch (Exception ex) - { - return Result.Failure(ex.Message); - } - } - - - /// /// Executes the specified function, catching any exception that may occur. /// @@ -117,6 +85,38 @@ public static Result Run(Func? function) + /// + /// Executes the specified action asynchronously, catching any exception that may occur. + /// + /// The action to execute. + /// The CancellationToken to monitor. + /// + /// A of representing the asynchronous operation. + /// + public static async Task RunAsync(Action action, CancellationToken token = default) + { + if (action == null) + { + throw new ArgumentNullException(nameof(action)); + } + + try + { + await Task.Run(action, token).ConfigureAwait(false); + return Result.Success(); + } + catch (OperationCanceledException) + { + throw; + } + catch (Exception ex) + { + return Result.Failure(ex.Message); + } + } + + + /// /// Executes the specified function, catching any exception that may occur. /// diff --git a/tests/Wolfgang.TryPattern.Tests/ResultTests.cs b/tests/Wolfgang.TryPattern.Tests/ResultTests.cs index 3b5bc2b..da329fd 100644 --- a/tests/Wolfgang.TryPattern.Tests/ResultTests.cs +++ b/tests/Wolfgang.TryPattern.Tests/ResultTests.cs @@ -49,10 +49,8 @@ public void Ctor_when_passed_false_and_no_message_throw_InvalidOperationExceptio - [Theory] - [InlineData(true)] - [InlineData(false)] - public void Success_sets_properties_correctly(bool succeeded) + [Fact] + public void Success_sets_properties_correctly() { // Act var result = Result.Success();