From e235cec8b283e152f9773f762c33e90c2178e6b4 Mon Sep 17 00:00:00 2001 From: jerviscui Date: Wed, 15 Mar 2023 16:20:13 +0800 Subject: [PATCH] Add ConfigureOptions method --- src/RetryCore/RetryBuilder.cs | 17 +++++++++++++++++ src/RetryCore/RetryCore.csproj | 2 +- test/RetryCore.Tests/RetryBuilderTests.cs | 7 ++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/RetryCore/RetryBuilder.cs b/src/RetryCore/RetryBuilder.cs index cff18d8..712c282 100644 --- a/src/RetryCore/RetryBuilder.cs +++ b/src/RetryCore/RetryBuilder.cs @@ -108,6 +108,23 @@ public RetryBuilder ConfigureOptions(Action configureAction) return this; } + /// + /// Configures the RetryOptions. + /// + /// The retry option. + /// + public RetryBuilder ConfigureOptions(RetryOptions option) + { + _configureAction = options => + { + options.MaxTryCount = option.MaxTryCount; + options.MaxTryTime = option.MaxTryTime; + options.RetryInterval = option.RetryInterval; + }; + + return this; + } + /// /// Retry only on exceptions of the type. /// diff --git a/src/RetryCore/RetryCore.csproj b/src/RetryCore/RetryCore.csproj index 44975f8..da488dc 100644 --- a/src/RetryCore/RetryCore.csproj +++ b/src/RetryCore/RetryCore.csproj @@ -8,7 +8,7 @@ True latest - 0.3.1 + 0.3.2 $(AssemblyName) A library for retrying operations. jerviscui diff --git a/test/RetryCore.Tests/RetryBuilderTests.cs b/test/RetryCore.Tests/RetryBuilderTests.cs index 22ef8ac..5ba1638 100644 --- a/test/RetryCore.Tests/RetryBuilderTests.cs +++ b/test/RetryCore.Tests/RetryBuilderTests.cs @@ -78,11 +78,8 @@ public async Task TryFunction_AsAsync_Test() [Fact] public void TryFunction_OverMaxTryTimeException_Test() { - var r = RetryBuilder.Default.ConfigureOptions(options => - { - options.MaxTryCount = int.MaxValue; - options.MaxTryTime = TimeSpan.FromSeconds(1); - }).Build(() => + var options = new RetryOptions { MaxTryCount = int.MaxValue, MaxTryTime = TimeSpan.FromSeconds(1) }; + var r = RetryBuilder.Default.ConfigureOptions(options).Build(() => { throw new Exception(); return 1;