From 01ccd495a61507ba527c7cffbd961fc961967708 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 13 Feb 2026 17:01:33 +0000 Subject: [PATCH 01/15] Update to .NET 11 preview 1 - Build with the .NET 11 preview 1 SDK. - Test with `net11.0`. - Drop testing with `net8.0` and `net9.0`. - Fix new code analysis warnings. --- Directory.Packages.props | 18 +++++-- bench/Polly.Benchmarks/Cache.cs | 4 +- .../Polly.Benchmarks/Polly.Benchmarks.csproj | 4 +- .../Polly.Core.Benchmarks.csproj | 2 +- bench/benchmarks.ps1 | 2 +- eng/Common.props | 2 +- eng/stryker-config.json | 1 + global.json | 2 +- samples/Chaos/Chaos.csproj | 2 +- .../DependencyInjection.csproj | 2 +- samples/Extensibility/Extensibility.csproj | 2 +- .../GenericPipelines/GenericPipelines.csproj | 2 +- samples/Intro.FSharp/Intro.FSharp.fsproj | 2 +- .../Intro.VisualBasic.vbproj | 2 +- samples/Intro/Intro.csproj | 2 +- samples/Retries/Retries.csproj | 2 +- src/Polly/AsyncPolicy.ExecuteOverloads.cs | 24 ++++----- .../AsyncPolicy.TResult.ExecuteOverloads.cs | 12 ++--- src/Polly/Context.Dictionary.cs | 2 +- src/Polly/Policy.ExecuteOverloads.cs | 16 +++--- src/Polly/Policy.TResult.ExecuteOverloads.cs | 8 +-- src/Snippets/Snippets.csproj | 2 +- test/Polly.AotTest/Polly.AotTest.csproj | 2 +- test/Polly.Core.Tests/Polly.Core.Tests.csproj | 4 +- .../Polly.Core.Tests/Utils/ObjectPoolTests.cs | 2 +- .../Polly.Extensions.Tests.csproj | 2 +- .../Telemetry/TelemetryListenerImplTests.cs | 2 +- .../Polly.RateLimiting.Tests.csproj | 2 +- .../Bulkhead/BulkheadAsyncSpecs.cs | 2 +- test/Polly.Specs/Bulkhead/BulkheadSpecs.cs | 2 +- .../Bulkhead/BulkheadTResultAsyncSpecs.cs | 2 +- .../Bulkhead/BulkheadTResultSpecs.cs | 2 +- test/Polly.Specs/Caching/AbsoluteTtlSpecs.cs | 6 +-- test/Polly.Specs/Caching/CacheAsyncSpecs.cs | 52 +++++++++---------- test/Polly.Specs/Caching/CacheSpecs.cs | 52 +++++++++---------- .../Caching/CacheTResultAsyncSpecs.cs | 38 +++++++------- test/Polly.Specs/Caching/CacheTResultSpecs.cs | 40 +++++++------- .../Polly.Specs/Caching/ContextualTtlSpecs.cs | 2 +- .../Caching/DefaultCacheKeyStrategySpecs.cs | 2 +- .../Caching/GenericCacheProviderAsyncSpecs.cs | 4 +- .../Caching/GenericCacheProviderSpecs.cs | 4 +- test/Polly.Specs/Caching/RelativeTtlSpecs.cs | 4 +- test/Polly.Specs/Caching/ResultTtlSpecs.cs | 6 +-- test/Polly.Specs/Caching/SlidingTtlSpecs.cs | 2 +- test/Polly.Specs/ContextSpecs.cs | 6 +-- test/Polly.Specs/PolicyAsyncSpecs.cs | 6 +-- test/Polly.Specs/PolicyKeyAsyncSpecs.cs | 4 +- test/Polly.Specs/PolicyKeySpecs.cs | 4 +- test/Polly.Specs/PolicySpecs.cs | 6 +-- test/Polly.Specs/PolicyTResultAsyncSpecs.cs | 6 +-- .../Polly.Specs/PolicyTResultKeyAsyncSpecs.cs | 2 +- test/Polly.Specs/PolicyTResultKeySpecs.cs | 2 +- test/Polly.Specs/PolicyTResultSpecs.cs | 6 +-- test/Polly.Specs/Polly.Specs.csproj | 2 +- test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs | 4 +- test/Polly.Specs/Timeout/TimeoutSpecs.cs | 4 +- .../Timeout/TimeoutTResultAsyncSpecs.cs | 4 +- .../Timeout/TimeoutTResultSpecs.cs | 4 +- test/Polly.TestUtils/Polly.TestUtils.csproj | 2 +- .../Polly.Testing.Tests.csproj | 2 +- 60 files changed, 211 insertions(+), 202 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 28ccaf70c0f..f3e46470df4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,12 +13,12 @@ - - + + - - - + + + @@ -66,4 +66,12 @@ + + + + + + + + diff --git a/bench/Polly.Benchmarks/Cache.cs b/bench/Polly.Benchmarks/Cache.cs index 2ec48d559ed..328cb5681fb 100644 --- a/bench/Polly.Benchmarks/Cache.cs +++ b/bench/Polly.Benchmarks/Cache.cs @@ -14,8 +14,8 @@ public class Cache private static readonly Policy SyncPolicyHit = Policy.Cache(CacheProvider, TimeSpan.MaxValue); private static readonly AsyncPolicy AsyncPolicyHit = Policy.CacheAsync(CacheProvider, TimeSpan.MaxValue); - private static readonly Context HitContext = new(nameof(HitContext)); - private static readonly Context MissContext = new(nameof(MissContext)); + private static readonly Context HitContext = [with(nameof(HitContext))]; + private static readonly Context MissContext = [with(nameof(MissContext))]; [GlobalSetup] public Task GlobalSetup() diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index 62f767f7684..14b10c53e41 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -2,7 +2,7 @@ false Exe - net10.0;net9.0;net8.0 + net11.0;net10.0 enable Benchmark $(NoWarn);CA1822;IDE0060 @@ -13,7 +13,7 @@ - + diff --git a/bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj b/bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj index d629c8db68d..e90b23d5335 100644 --- a/bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj +++ b/bench/Polly.Core.Benchmarks/Polly.Core.Benchmarks.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 Polly true Benchmark diff --git a/bench/benchmarks.ps1 b/bench/benchmarks.ps1 index 0932369625d..524c8e305e0 100644 --- a/bench/benchmarks.ps1 +++ b/bench/benchmarks.ps1 @@ -20,6 +20,6 @@ if ($Interactive -ne $true) { $project = Join-Path "Polly.Core.Benchmarks" "Polly.Core.Benchmarks.csproj" -dotnet run --configuration $Configuration --framework net10.0 --project $project $additionalArgs +dotnet run --configuration $Configuration --framework net11.0 --project $project $additionalArgs exit $LASTEXITCODE diff --git a/eng/Common.props b/eng/Common.props index bf90aaa13dc..bf4cf8420b8 100644 --- a/eng/Common.props +++ b/eng/Common.props @@ -3,7 +3,7 @@ true $(MSBuildThisFileDirectory)..\Polly.snk enable - latest + preview direct true 0024000004800000940000000602000000240000525341310004000001000100150819e3494f97263a3abdd18e5e0c47b04e6c0ede44a6c51d50b545d403ceeb7cbb32d18dbbbcdd1d88a87d7b73206b126be134b0609c36aa3cb31dd2e47e393293102809b8d77f192f3188618a42e651c14ebf05f8f5b76aa91b431642b23497ed82b65d63791cdaa31d4282a2d6cbabc3fe0745b6b6690c417cabf6a1349c diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 8113fef7a0f..37906bb49c2 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -22,6 +22,7 @@ "concurrency": 4, "configuration": "Debug", "language-version": "Preview", + "_comment": "TODO Update to net11.0 when Stryker supports it", "target-framework": "net10.0", "thresholds": { "high": 100, diff --git a/global.json b/global.json index 1d8b12934fe..f711fcfb06c 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.103", + "version": "11.0.100-preview.1.26104.118", "allowPrerelease": false, "rollForward": "latestMinor" }, diff --git a/samples/Chaos/Chaos.csproj b/samples/Chaos/Chaos.csproj index 3166caa94a0..2229b12a9bd 100644 --- a/samples/Chaos/Chaos.csproj +++ b/samples/Chaos/Chaos.csproj @@ -1,7 +1,7 @@ - net10.0 + net11.0 Chaos diff --git a/samples/DependencyInjection/DependencyInjection.csproj b/samples/DependencyInjection/DependencyInjection.csproj index d136db346b8..0ae185705a2 100644 --- a/samples/DependencyInjection/DependencyInjection.csproj +++ b/samples/DependencyInjection/DependencyInjection.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/Extensibility/Extensibility.csproj b/samples/Extensibility/Extensibility.csproj index f12bcc31035..de611ca35ad 100644 --- a/samples/Extensibility/Extensibility.csproj +++ b/samples/Extensibility/Extensibility.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/GenericPipelines/GenericPipelines.csproj b/samples/GenericPipelines/GenericPipelines.csproj index 861604f1783..1435bdca1e1 100644 --- a/samples/GenericPipelines/GenericPipelines.csproj +++ b/samples/GenericPipelines/GenericPipelines.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/Intro.FSharp/Intro.FSharp.fsproj b/samples/Intro.FSharp/Intro.FSharp.fsproj index f88a1c3415f..5b56c764a59 100644 --- a/samples/Intro.FSharp/Intro.FSharp.fsproj +++ b/samples/Intro.FSharp/Intro.FSharp.fsproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/Intro.VisualBasic/Intro.VisualBasic.vbproj b/samples/Intro.VisualBasic/Intro.VisualBasic.vbproj index f12bcc31035..de611ca35ad 100644 --- a/samples/Intro.VisualBasic/Intro.VisualBasic.vbproj +++ b/samples/Intro.VisualBasic/Intro.VisualBasic.vbproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/Intro/Intro.csproj b/samples/Intro/Intro.csproj index f12bcc31035..de611ca35ad 100644 --- a/samples/Intro/Intro.csproj +++ b/samples/Intro/Intro.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/samples/Retries/Retries.csproj b/samples/Retries/Retries.csproj index f12bcc31035..de611ca35ad 100644 --- a/samples/Retries/Retries.csproj +++ b/samples/Retries/Retries.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net11.0 diff --git a/src/Polly/AsyncPolicy.ExecuteOverloads.cs b/src/Polly/AsyncPolicy.ExecuteOverloads.cs index 39da8ec96d1..b0a65d714ed 100644 --- a/src/Polly/AsyncPolicy.ExecuteOverloads.cs +++ b/src/Polly/AsyncPolicy.ExecuteOverloads.cs @@ -21,7 +21,7 @@ public Task ExecuteAsync(Func action) => /// A which completes when is registered. [DebuggerStepThrough] public Task ExecuteAsync(Func action, IDictionary contextData) => - ExecuteAsync((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken, DefaultContinueOnCapturedContext); + ExecuteAsync((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy. @@ -52,7 +52,7 @@ public Task ExecuteAsync(Func action, CancellationToken /// A which completes when is registered. [DebuggerStepThrough] public Task ExecuteAsync(Func action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy. @@ -88,7 +88,7 @@ public Task ExecuteAsync(Func action, CancellationToken /// A which completes when is registered. [DebuggerStepThrough] public Task ExecuteAsync(Func action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy. @@ -131,7 +131,7 @@ public Task ExecuteAsync(Func> action) => /// The value returned by the action. [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData) => - ExecuteAsync((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken, DefaultContinueOnCapturedContext); + ExecuteAsync((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -165,7 +165,7 @@ public Task ExecuteAsync(Func /// The value returned by the action. [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -204,7 +204,7 @@ public Task ExecuteAsync(Func /// Thrown when is . [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -251,7 +251,7 @@ public Task ExecuteAndCaptureAsync(Func action) => /// Thrown when is . [DebuggerStepThrough] public Task ExecuteAndCaptureAsync(Func action, IDictionary contextData) => - ExecuteAndCaptureAsync((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the captured result. @@ -283,7 +283,7 @@ public Task ExecuteAndCaptureAsync(Func a /// Thrown when is . [DebuggerStepThrough] public Task ExecuteAndCaptureAsync(Func action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the captured result. @@ -319,7 +319,7 @@ public Task ExecuteAndCaptureAsync(Func a /// Thrown when is . [DebuggerStepThrough] public Task ExecuteAndCaptureAsync(Func action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the captured result. @@ -363,7 +363,7 @@ public Task> ExecuteAndCaptureAsync(FuncThrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData) => - ExecuteAndCaptureAsync((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -398,7 +398,7 @@ public Task> ExecuteAndCaptureAsync(FuncThrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -437,7 +437,7 @@ public Task> ExecuteAndCaptureAsync(FuncThrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. diff --git a/src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs b/src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs index 5d103f32f74..3727bc080e2 100644 --- a/src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs +++ b/src/Polly/AsyncPolicy.TResult.ExecuteOverloads.cs @@ -21,7 +21,7 @@ public Task ExecuteAsync(Func> action) => /// The value returned by the action. [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData) => - ExecuteAsync((ctx, _) => action(ctx), new Context(contextData), CancellationToken.None, DefaultContinueOnCapturedContext); + ExecuteAsync((ctx, _) => action(ctx), [with(contextData)], CancellationToken.None, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -64,7 +64,7 @@ public Task ExecuteAsync(Func> action, /// The value returned by the action. [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -88,7 +88,7 @@ public Task ExecuteAsync(Func /// Thrown when is . [DebuggerStepThrough] public Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -132,7 +132,7 @@ public Task> ExecuteAndCaptureAsync(Func> ac /// Thrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData) => - ExecuteAndCaptureAsync((ctx, _) => action(ctx), new Context(contextData), CancellationToken.None, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync((ctx, _) => action(ctx), [with(contextData)], CancellationToken.None, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -176,7 +176,7 @@ public Task> ExecuteAndCaptureAsync(FuncThrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, DefaultContinueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, DefaultContinueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -200,7 +200,7 @@ public Task> ExecuteAndCaptureAsync(FuncThrown when is . [DebuggerStepThrough] public Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext) => - ExecuteAndCaptureAsync(action, new Context(contextData), cancellationToken, continueOnCapturedContext); + ExecuteAndCaptureAsync(action, [with(contextData)], cancellationToken, continueOnCapturedContext); /// /// Executes the specified asynchronous action within the policy and returns the result. diff --git a/src/Polly/Context.Dictionary.cs b/src/Polly/Context.Dictionary.cs index fc43e1df132..6407762c897 100644 --- a/src/Polly/Context.Dictionary.cs +++ b/src/Polly/Context.Dictionary.cs @@ -36,7 +36,7 @@ internal Context(IDictionary contextData) throw new ArgumentNullException(nameof(contextData)); } - WrappedDictionary = new Dictionary(contextData); + WrappedDictionary = [with(contextData)]; } #region IDictionary implementation diff --git a/src/Polly/Policy.ExecuteOverloads.cs b/src/Polly/Policy.ExecuteOverloads.cs index 103d2d4d7c2..de2b98e62b3 100644 --- a/src/Polly/Policy.ExecuteOverloads.cs +++ b/src/Polly/Policy.ExecuteOverloads.cs @@ -19,7 +19,7 @@ public void Execute(Action action) => /// Arbitrary data that is passed to the exception policy. [DebuggerStepThrough] public void Execute(Action action, IDictionary contextData) => - Execute((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + Execute((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy. @@ -48,7 +48,7 @@ public void Execute(Action action, CancellationToken cancella /// Thrown when is . [DebuggerStepThrough] public void Execute(Action action, IDictionary contextData, CancellationToken cancellationToken) => - Execute(action, new Context(contextData), cancellationToken); + Execute(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy. @@ -98,7 +98,7 @@ public TResult Execute(Func action) => /// Thrown when is . [DebuggerStepThrough] public TResult Execute(Func action, IDictionary contextData) => - Execute((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + Execute((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy and returns the result. @@ -134,7 +134,7 @@ public TResult Execute(Func action, Cancell /// Thrown when is . [DebuggerStepThrough] public TResult Execute(Func action, IDictionary contextData, CancellationToken cancellationToken) => - Execute(action, new Context(contextData), cancellationToken); + Execute(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy and returns the result. @@ -188,7 +188,7 @@ public PolicyResult ExecuteAndCapture(Action action) => /// Thrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Action action, IDictionary contextData) => - ExecuteAndCapture((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + ExecuteAndCapture((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy and returns the captured result. @@ -220,7 +220,7 @@ public PolicyResult ExecuteAndCapture(Action action, Cancella /// Thrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Action action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCapture(action, new Context(contextData), cancellationToken); + ExecuteAndCapture(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy and returns the captured result. @@ -272,7 +272,7 @@ public PolicyResult ExecuteAndCapture(Func action) => /// Thrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Func action, IDictionary contextData) => - ExecuteAndCapture((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + ExecuteAndCapture((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy and returns the captured result. @@ -307,7 +307,7 @@ public PolicyResult ExecuteAndCapture(FuncThrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Func action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCapture(action, new Context(contextData), cancellationToken); + ExecuteAndCapture(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy and returns the captured result. diff --git a/src/Polly/Policy.TResult.ExecuteOverloads.cs b/src/Polly/Policy.TResult.ExecuteOverloads.cs index 4f2b7a93f5f..08b8e3308cb 100644 --- a/src/Polly/Policy.TResult.ExecuteOverloads.cs +++ b/src/Polly/Policy.TResult.ExecuteOverloads.cs @@ -22,7 +22,7 @@ public TResult Execute(Func action) => /// Thrown when is . [DebuggerStepThrough] public TResult Execute(Func action, IDictionary contextData) => - Execute((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + Execute((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy and returns the result. @@ -55,7 +55,7 @@ public TResult Execute(Func action, CancellationToke /// Thrown when is . [DebuggerStepThrough] public TResult Execute(Func action, IDictionary contextData, CancellationToken cancellationToken) => - Execute(action, new Context(contextData), cancellationToken); + Execute(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy and returns the result. @@ -106,7 +106,7 @@ public PolicyResult ExecuteAndCapture(Func action) => /// Thrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Func action, IDictionary contextData) => - ExecuteAndCapture((ctx, _) => action(ctx), new Context(contextData), DefaultCancellationToken); + ExecuteAndCapture((ctx, _) => action(ctx), [with(contextData)], DefaultCancellationToken); /// /// Executes the specified action within the policy and returns the captured result. @@ -139,7 +139,7 @@ public PolicyResult ExecuteAndCapture(Func /// Thrown when is . [DebuggerStepThrough] public PolicyResult ExecuteAndCapture(Func action, IDictionary contextData, CancellationToken cancellationToken) => - ExecuteAndCapture(action, new Context(contextData), cancellationToken); + ExecuteAndCapture(action, [with(contextData)], cancellationToken); /// /// Executes the specified action within the policy and returns the captured result. diff --git a/src/Snippets/Snippets.csproj b/src/Snippets/Snippets.csproj index f9743050c13..58ebe2819e1 100644 --- a/src/Snippets/Snippets.csproj +++ b/src/Snippets/Snippets.csproj @@ -15,7 +15,7 @@ Library Snippets false - net10.0 + net11.0 diff --git a/test/Polly.AotTest/Polly.AotTest.csproj b/test/Polly.AotTest/Polly.AotTest.csproj index bf9bd32369c..462ee1c5286 100644 --- a/test/Polly.AotTest/Polly.AotTest.csproj +++ b/test/Polly.AotTest/Polly.AotTest.csproj @@ -5,7 +5,7 @@ true true true - net10.0 + net11.0 diff --git a/test/Polly.Core.Tests/Polly.Core.Tests.csproj b/test/Polly.Core.Tests/Polly.Core.Tests.csproj index 5105ea208e1..825558018a1 100644 --- a/test/Polly.Core.Tests/Polly.Core.Tests.csproj +++ b/test/Polly.Core.Tests/Polly.Core.Tests.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 false Test @@ -20,7 +20,7 @@ - + diff --git a/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs b/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs index a08e275f734..fb698d00356 100644 --- a/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs +++ b/test/Polly.Core.Tests/Utils/ObjectPoolTests.cs @@ -102,7 +102,7 @@ private static List GetStoreReturn(ObjectPool pool, int? count = private class ListPolicy { - public static List Create() => new(17); + public static List Create() => [with(17)]; public static bool Return(List obj) => obj.Capacity == 17; } diff --git a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj index 344d5001a12..35ea725064c 100644 --- a/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj +++ b/test/Polly.Extensions.Tests/Polly.Extensions.Tests.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 Test enable diff --git a/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs b/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs index dc1c8dbcebc..d50e065383b 100644 --- a/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/TelemetryListenerImplTests.cs @@ -12,7 +12,7 @@ public class TelemetryListenerImplTests : IDisposable { private readonly FakeLogger _logger; private readonly ILoggerFactory _loggerFactory; - private readonly List _events = new(1024); + private readonly List _events = [with(1024)]; private Action>? _onEvent; public TelemetryListenerImplTests() => _loggerFactory = TestUtilities.CreateLoggerFactory(out _logger); diff --git a/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj b/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj index 88fd0658026..604b8a25419 100644 --- a/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj +++ b/test/Polly.RateLimiting.Tests/Polly.RateLimiting.Tests.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 Test enable diff --git a/test/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs index 3b943eb8505..47f8371c6f0 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs @@ -90,7 +90,7 @@ public void Should_throw_when_onBulkheadRejected_is_null() public async Task Should_call_onBulkheadRejected_with_passed_context() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnRejected = null; Func onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; }; diff --git a/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs index 123c36de6e7..2129d908222 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadSpecs.cs @@ -92,7 +92,7 @@ public void Should_throw_when_onBulkheadRejected_is_null() public async Task Should_call_onBulkheadRejected_with_passed_context() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnRejected = null; Action onRejected = ctx => { contextPassedToOnRejected = ctx; }; diff --git a/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs index 86959396d5d..450cdb3b45e 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs @@ -88,7 +88,7 @@ public void Should_not_throw_when_arguments_valid() public async Task Should_call_onBulkheadRejected_with_passed_context() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnRejected = null; Func onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; }; diff --git a/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs b/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs index 3018b6d523b..a68964aaa05 100644 --- a/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs +++ b/test/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs @@ -91,7 +91,7 @@ public void Should_throw_when_onBulkheadRejected_is_null() public async Task Should_call_onBulkheadRejected_with_passed_context() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnRejected = null; Action onRejected = ctx => contextPassedToOnRejected = ctx; diff --git a/test/Polly.Specs/Caching/AbsoluteTtlSpecs.cs b/test/Polly.Specs/Caching/AbsoluteTtlSpecs.cs index 7256e7628cb..7a3bf95cedd 100644 --- a/test/Polly.Specs/Caching/AbsoluteTtlSpecs.cs +++ b/test/Polly.Specs/Caching/AbsoluteTtlSpecs.cs @@ -32,7 +32,7 @@ public void Should_return_zero_ttl_if_configured_to_expire_in_past() { AbsoluteTtl ttlStrategy = new AbsoluteTtl(SystemClock.DateTimeOffsetUtcNow().Subtract(TimeSpan.FromTicks(1))); - var actual = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + var actual = ttlStrategy.GetTtl([with("someOperationKey")], null); actual.Timespan.ShouldBe(TimeSpan.Zero); actual.SlidingExpiration.ShouldBeFalse(); @@ -47,7 +47,7 @@ public void Should_return_timespan_reflecting_time_until_expiry() AbsoluteTtl ttlStrategy = new AbsoluteTtl(tomorrow); SystemClock.DateTimeOffsetUtcNow = () => today; - var actual = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + var actual = ttlStrategy.GetTtl([with("someOperationKey")], null); actual.Timespan.ShouldBe(TimeSpan.FromDays(1)); actual.SlidingExpiration.ShouldBeFalse(); @@ -60,7 +60,7 @@ public void Should_return_zero_ttl_if_configured_to_expire_now() AbsoluteTtl ttlStrategy = new AbsoluteTtl(SystemClock.DateTimeOffsetUtcNow()); - var actual = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + var actual = ttlStrategy.GetTtl([with("someOperationKey")], null); actual.Timespan.ShouldBe(TimeSpan.Zero); actual.SlidingExpiration.ShouldBeFalse(); diff --git a/test/Polly.Specs/Caching/CacheAsyncSpecs.cs b/test/Polly.Specs/Caching/CacheAsyncSpecs.cs index d1bdbb0e6f2..7f3c5c5bc97 100644 --- a/test/Polly.Specs/Caching/CacheAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/CacheAsyncSpecs.cs @@ -341,7 +341,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -360,7 +360,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, [with(OperationKey)])).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -393,7 +393,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp SystemClock.DateTimeOffsetUtcNow = () => fixedTime; // First execution should execute delegate and put result in the cache. - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -402,14 +402,14 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp // Second execution (before cache expires) should get it from the cache - no further delegate execution. // (Manipulate time so just prior cache expiry). SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(-1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); // Manipulate time to force cache expiry. SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(1); // Third execution (cache expired) should not get it from the cache - should cause further delegate execution. - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(2); } @@ -426,7 +426,7 @@ public async Task Should_execute_delegate_but_not_put_value_in_cache_if_cache_do cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, [with(OperationKey)])).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeFalse(); @@ -449,13 +449,13 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_pri return ValueToReturn; }; - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); } @@ -522,7 +522,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(OperationKey))).ShouldBe(valueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, [with(OperationKey)])).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -547,7 +547,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return valueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -566,7 +566,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(OperationKey))).ShouldBe(valueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, [with(OperationKey)])).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -592,7 +592,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return valueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -623,7 +623,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -650,7 +650,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -677,7 +677,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -719,10 +719,10 @@ public void Should_always_execute_delegate_if_execution_is_void_returning() int delegateInvocations = 0; Func action = async _ => { delegateInvocations++; await TaskHelper.EmptyTask; }; - cache.ExecuteAsync(action, new Context(operationKey)); + cache.ExecuteAsync(action, [with(operationKey)]); delegateInvocations.ShouldBe(1); - cache.ExecuteAsync(action, new Context(operationKey)); + cache.ExecuteAsync(action, [with(operationKey)]); delegateInvocations.ShouldBe(2); } @@ -750,12 +750,12 @@ public async Task Should_honour_cancellation_even_if_prior_execution_has_cached( return ValueToReturn; }; - (await policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)).ShouldBe(ValueToReturn); + (await policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); tokenSource.Cancel(); - await Should.ThrowAsync(() => policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)); + await Should.ThrowAsync(() => policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)); } delegateInvocations.ShouldBe(1); @@ -780,7 +780,7 @@ public async Task Should_honour_cancellation_during_delegate_execution_and_not_p return ValueToReturn; }; - await Should.ThrowAsync(() => policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)); + await Should.ThrowAsync(() => policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)); } (bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); @@ -819,7 +819,7 @@ public async Task Should_call_onError_delegate_if_cache_get_errors() await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromExecution); delegateExecuted.ShouldBeTrue(); @@ -846,7 +846,7 @@ public async Task Should_call_onError_delegate_if_cache_put_errors() cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, [with(OperationKey)])).ShouldBe(ValueToReturn); // error should be captured by onError delegate. exceptionFromCacheProvider.ShouldBe(ex); @@ -866,7 +866,7 @@ public async Task Should_execute_oncacheget_after_got_from_cache() const string OperationKey = "SomeOperationKey"; string? keyPassedToDelegate = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToDelegate = null; Action noErrorHandling = (_, _, _) => { }; @@ -904,7 +904,7 @@ public async Task Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_ho string? keyPassedToOnCacheMiss = null; string? keyPassedToOnCachePut = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToOnCacheMiss = null; Context? contextPassedToOnCachePut = null; @@ -941,7 +941,7 @@ public async Task Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_no string? keyPassedToOnCacheMiss = null; string? keyPassedToOnCachePut = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToOnCacheMiss = null; Context? contextPassedToOnCachePut = null; diff --git a/test/Polly.Specs/Caching/CacheSpecs.cs b/test/Polly.Specs/Caching/CacheSpecs.cs index 0ea58bd9b7e..b89675623de 100644 --- a/test/Polly.Specs/Caching/CacheSpecs.cs +++ b/test/Polly.Specs/Caching/CacheSpecs.cs @@ -385,7 +385,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -404,7 +404,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -436,7 +436,7 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e SystemClock.DateTimeOffsetUtcNow = () => fixedTime; // First execution should execute delegate and put result in the cache. - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); @@ -446,14 +446,14 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e // Second execution (before cache expires) should get it from the cache - no further delegate execution. // (Manipulate time so just prior cache expiry). SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(-1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); // Manipulate time to force cache expiry. SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(1); // Third execution (cache expired) should not get it from the cache - should cause further delegate execution. - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(2); } @@ -470,7 +470,7 @@ public void Should_execute_delegate_but_not_put_value_in_cache_if_cache_does_not cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeFalse(); @@ -492,13 +492,13 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_prior_exe return ValueToReturn; }; - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); } @@ -565,7 +565,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => valueToReturn, new Context(OperationKey)).ShouldBe(valueToReturn); + cache.Execute(_ => valueToReturn, [with(OperationKey)]).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -589,7 +589,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return valueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -608,7 +608,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => valueToReturn, new Context(OperationKey)).ShouldBe(valueToReturn); + cache.Execute(_ => valueToReturn, [with(OperationKey)]).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -633,7 +633,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return valueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -663,7 +663,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -689,7 +689,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -715,7 +715,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -756,10 +756,10 @@ public void Should_always_execute_delegate_if_execution_is_void_returning() int delegateInvocations = 0; Action action = _ => { delegateInvocations++; }; - cache.Execute(action, new Context(operationKey)); + cache.Execute(action, [with(operationKey)]); delegateInvocations.ShouldBe(1); - cache.Execute(action, new Context(operationKey)); + cache.Execute(action, [with(operationKey)]); delegateInvocations.ShouldBe(2); } @@ -786,12 +786,12 @@ public void Should_honour_cancellation_even_if_prior_execution_has_cached() return ValueToReturn; }; - policy.Execute(func, new Context(OperationKey), tokenSource.Token).ShouldBe(ValueToReturn); + policy.Execute(func, [with(OperationKey)], tokenSource.Token).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); tokenSource.Cancel(); - Should.Throw(() => policy.Execute(func, new Context(OperationKey), tokenSource.Token)); + Should.Throw(() => policy.Execute(func, [with(OperationKey)], tokenSource.Token)); } delegateInvocations.ShouldBe(1); @@ -815,7 +815,7 @@ public void Should_honour_cancellation_during_delegate_execution_and_not_put_to_ return ValueToReturn; }; - Should.Throw(() => policy.Execute(func, new Context(OperationKey), tokenSource.Token)); + Should.Throw(() => policy.Execute(func, [with(OperationKey)], tokenSource.Token)); } (bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(OperationKey); @@ -852,7 +852,7 @@ public void Should_call_onError_delegate_if_cache_get_errors() { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromExecution); delegateExecuted.ShouldBeTrue(); @@ -879,7 +879,7 @@ public void Should_call_onError_delegate_if_cache_put_errors() cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); // error should be captured by onError delegate. exceptionFromCacheProvider.ShouldBe(ex); @@ -900,7 +900,7 @@ public void Should_execute_oncacheget_after_got_from_cache() const string OperationKey = "SomeOperationKey"; string? keyPassedToDelegate = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToDelegate = null; Action noErrorHandling = (_, _, _) => { }; @@ -937,7 +937,7 @@ public void Should_execute_oncachemiss_and_oncacheput_if_cache_does_not_hold_val string? keyPassedToOnCacheMiss = null; string? keyPassedToOnCachePut = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToOnCacheMiss = null; Context? contextPassedToOnCachePut = null; @@ -975,7 +975,7 @@ public void Should_execute_oncachemiss_but_not_oncacheput_if_cache_does_not_hold string? keyPassedToOnCacheMiss = null; string? keyPassedToOnCachePut = null; - Context contextToExecute = new Context(OperationKey); + Context contextToExecute = [with(OperationKey)]; Context? contextPassedToOnCacheMiss = null; Context? contextPassedToOnCachePut = null; diff --git a/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs b/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs index 25a8b69062f..c064b12cf98 100644 --- a/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/CacheTResultAsyncSpecs.cs @@ -407,7 +407,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -426,7 +426,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, [with(OperationKey)])).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -459,7 +459,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp SystemClock.DateTimeOffsetUtcNow = () => fixedTime; // First execution should execute delegate and put result in the cache. - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); @@ -469,14 +469,14 @@ public async Task Should_execute_delegate_and_put_value_in_cache_but_when_it_exp // Second execution (before cache expires) should get it from the cache - no further delegate execution. // (Manipulate time so just prior cache expiry). SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(-1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); // Manipulate time to force cache expiry. SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(1); // Third execution (cache expired) should not get it from the cache - should cause further delegate execution. - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(2); } @@ -493,7 +493,7 @@ public async Task Should_execute_delegate_but_not_put_value_in_cache_if_cache_do cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return ValueToReturn; }, [with(OperationKey)])).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeFalse(); @@ -516,13 +516,13 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_pri return ValueToReturn; }; - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - (await cache.ExecuteAsync(func, new Context(OperationKey))).ShouldBe(ValueToReturn); + (await cache.ExecuteAsync(func, [with(OperationKey)])).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); } @@ -590,7 +590,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(OperationKey))).ShouldBe(valueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, [with(OperationKey)])).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -615,7 +615,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return valueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -634,7 +634,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_if_cache_does_n cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, new Context(OperationKey))).ShouldBe(valueToReturn); + (await cache.ExecuteAsync(async _ => { await TaskHelper.EmptyTask; return valueToReturn; }, [with(OperationKey)])).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); cacheHit2.ShouldBeTrue(); @@ -660,7 +660,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return valueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -691,7 +691,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -718,7 +718,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -745,7 +745,7 @@ public async Task Should_return_value_from_cache_and_not_execute_delegate_if_cac delegateExecuted = true; await TaskHelper.EmptyTask; return ValueToReturnFromExecution; - }, new Context(OperationKey))) + }, [with(OperationKey)])) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -801,12 +801,12 @@ public async Task Should_honour_cancellation_even_if_prior_execution_has_cached( return ValueToReturn; }; - (await policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)).ShouldBe(ValueToReturn); + (await policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); tokenSource.Cancel(); - await Should.ThrowAsync(() => policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)); + await Should.ThrowAsync(() => policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)); } delegateInvocations.ShouldBe(1); @@ -831,7 +831,7 @@ public async Task Should_honour_cancellation_during_delegate_execution_and_not_p return ValueToReturn; }; - await Should.ThrowAsync(() => policy.ExecuteAsync(func, new Context(OperationKey), tokenSource.Token)); + await Should.ThrowAsync(() => policy.ExecuteAsync(func, [with(OperationKey)], tokenSource.Token)); } (bool cacheHit, object? fromCache) = await stubCacheProvider.TryGetAsync(OperationKey, CancellationToken, false); diff --git a/test/Polly.Specs/Caching/CacheTResultSpecs.cs b/test/Polly.Specs/Caching/CacheTResultSpecs.cs index 5ef3f19c84e..9a20750960d 100644 --- a/test/Polly.Specs/Caching/CacheTResultSpecs.cs +++ b/test/Polly.Specs/Caching/CacheTResultSpecs.cs @@ -1116,7 +1116,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1141,7 +1141,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1160,7 +1160,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -1192,7 +1192,7 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e SystemClock.DateTimeOffsetUtcNow = () => fixedTime; // First execution should execute delegate and put result in the cache. - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); @@ -1202,14 +1202,14 @@ public void Should_execute_delegate_and_put_value_in_cache_but_when_it_expires_e // Second execution (before cache expires) should get it from the cache - no further delegate execution. // (Manipulate time so just prior cache expiry). SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(-1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); // Manipulate time to force cache expiry. SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(ttl).AddSeconds(1); // Third execution (cache expired) should not get it from the cache - should cause further delegate execution. - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(2); } @@ -1226,7 +1226,7 @@ public void Should_execute_delegate_but_not_put_value_in_cache_if_cache_does_not cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeFalse(); @@ -1248,13 +1248,13 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_prior_exe return ValueToReturn; }; - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); - cache.Execute(func, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(func, [with(OperationKey)]).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); } @@ -1321,7 +1321,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => valueToReturn, new Context(OperationKey)).ShouldBe(valueToReturn); + cache.Execute(_ => valueToReturn, [with(OperationKey)]).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -1345,7 +1345,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return valueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1364,7 +1364,7 @@ public void Should_execute_delegate_and_put_value_in_cache_if_cache_does_not_hol cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => valueToReturn, new Context(OperationKey)).ShouldBe(valueToReturn); + cache.Execute(_ => valueToReturn, [with(OperationKey)]).ShouldBe(valueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); cacheHit2.ShouldBeTrue(); @@ -1389,7 +1389,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return valueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(valueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1419,7 +1419,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1445,7 +1445,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1471,7 +1471,7 @@ public void Should_return_value_from_cache_and_not_execute_delegate_if_cache_hol { delegateExecuted = true; return ValueToReturnFromExecution; - }, new Context(OperationKey)) + }, [with(OperationKey)]) .ShouldBe(ValueToReturnFromCache); delegateExecuted.ShouldBeFalse(); @@ -1525,12 +1525,12 @@ public void Should_honour_cancellation_even_if_prior_execution_has_cached() return ValueToReturn; }; - policy.Execute(func, new Context(OperationKey), tokenSource.Token).ShouldBe(ValueToReturn); + policy.Execute(func, [with(OperationKey)], tokenSource.Token).ShouldBe(ValueToReturn); delegateInvocations.ShouldBe(1); tokenSource.Cancel(); - Should.Throw(() => policy.Execute(func, new Context(OperationKey), tokenSource.Token)); + Should.Throw(() => policy.Execute(func, [with(OperationKey)], tokenSource.Token)); } delegateInvocations.ShouldBe(1); @@ -1554,7 +1554,7 @@ public void Should_honour_cancellation_during_delegate_execution_and_not_put_to_ return ValueToReturn; }; - Should.Throw(() => policy.Execute(func, new Context(OperationKey), tokenSource.Token)); + Should.Throw(() => policy.Execute(func, [with(OperationKey)], tokenSource.Token)); } (bool cacheHit, object? fromCache) = stubCacheProvider.TryGet(OperationKey); diff --git a/test/Polly.Specs/Caching/ContextualTtlSpecs.cs b/test/Polly.Specs/Caching/ContextualTtlSpecs.cs index 838a8459045..7210e6c9a5d 100644 --- a/test/Polly.Specs/Caching/ContextualTtlSpecs.cs +++ b/test/Polly.Specs/Caching/ContextualTtlSpecs.cs @@ -12,7 +12,7 @@ public void Should_throw_when_context_is_null() [Fact] public void Should_return_zero_if_no_value_set_on_context() => - new ContextualTtl().GetTtl(new Context("someOperationKey"), null).Timespan.ShouldBe(TimeSpan.Zero); + new ContextualTtl().GetTtl([with("someOperationKey")], null).Timespan.ShouldBe(TimeSpan.Zero); [Fact] public void Should_return_zero_if_invalid_value_set_on_context() diff --git a/test/Polly.Specs/Caching/DefaultCacheKeyStrategySpecs.cs b/test/Polly.Specs/Caching/DefaultCacheKeyStrategySpecs.cs index f42079cc0df..a44996b34e8 100644 --- a/test/Polly.Specs/Caching/DefaultCacheKeyStrategySpecs.cs +++ b/test/Polly.Specs/Caching/DefaultCacheKeyStrategySpecs.cs @@ -15,7 +15,7 @@ public void Should_return_Context_OperationKey_as_cache_key() { string operationKey = "SomeKey"; - Context context = new Context(operationKey); + Context context = [with(operationKey)]; DefaultCacheKeyStrategy.Instance.GetCacheKey(context) .ShouldBe(operationKey); diff --git a/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs b/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs index cf2586030bd..1358916a1b8 100644 --- a/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs +++ b/test/Polly.Specs/Caching/GenericCacheProviderAsyncSpecs.cs @@ -22,7 +22,7 @@ public async Task Should_not_error_for_executions_on_non_nullable_types_if_cache { await TaskHelper.EmptyTask; return ResultPrimitive.Substitute; - }, new Context(OperationKey)); + }, [with(OperationKey)]); onErrorCalled.ShouldBeFalse(); } @@ -45,7 +45,7 @@ public async Task Should_execute_delegate_and_put_value_in_cache_for_non_nullabl { await TaskHelper.EmptyTask; return ResultPrimitive.Substitute; - }, new Context(OperationKey))).ShouldBe(ValueToReturn); + }, [with(OperationKey)])).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = await stubCacheProvider.TryGetAsync(OperationKey, cancellationToken, false); cacheHit2.ShouldBeTrue(); diff --git a/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs b/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs index 381835a3246..a4acf977fef 100644 --- a/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs +++ b/test/Polly.Specs/Caching/GenericCacheProviderSpecs.cs @@ -18,7 +18,7 @@ public void Should_not_error_for_executions_on_non_nullable_types_if_cache_does_ cacheHit.ShouldBeFalse(); fromCache.ShouldBeNull(); - ResultPrimitive result = cache.Execute(_ => ResultPrimitive.Substitute, new Context(OperationKey)); + ResultPrimitive result = cache.Execute(_ => ResultPrimitive.Substitute, [with(OperationKey)]); onErrorCalled.ShouldBeFalse(); } @@ -37,7 +37,7 @@ public void Should_execute_delegate_and_put_value_in_cache_for_non_nullable_type cacheHit1.ShouldBeFalse(); fromCache1.ShouldBeNull(); - cache.Execute(_ => ValueToReturn, new Context(OperationKey)).ShouldBe(ValueToReturn); + cache.Execute(_ => ValueToReturn, [with(OperationKey)]).ShouldBe(ValueToReturn); (bool cacheHit2, object? fromCache2) = stubCacheProvider.TryGet(OperationKey); diff --git a/test/Polly.Specs/Caching/RelativeTtlSpecs.cs b/test/Polly.Specs/Caching/RelativeTtlSpecs.cs index 7d56e7d7b52..4f7c49feefc 100644 --- a/test/Polly.Specs/Caching/RelativeTtlSpecs.cs +++ b/test/Polly.Specs/Caching/RelativeTtlSpecs.cs @@ -33,7 +33,7 @@ public void Should_return_configured_timespan() RelativeTtl ttlStrategy = new RelativeTtl(ttl); - Ttl retrieved = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + Ttl retrieved = ttlStrategy.GetTtl([with("someOperationKey")], null); retrieved.Timespan.ShouldBe(ttl); retrieved.SlidingExpiration.ShouldBeFalse(); } @@ -49,7 +49,7 @@ public void Should_return_configured_timespan_from_time_requested() SystemClock.DateTimeOffsetUtcNow = () => fixedTime.Add(delay); - Ttl retrieved = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + Ttl retrieved = ttlStrategy.GetTtl([with("someOperationKey")], null); retrieved.Timespan.ShouldBe(ttl); retrieved.SlidingExpiration.ShouldBeFalse(); } diff --git a/test/Polly.Specs/Caching/ResultTtlSpecs.cs b/test/Polly.Specs/Caching/ResultTtlSpecs.cs index bcb763ccc12..c0319243504 100644 --- a/test/Polly.Specs/Caching/ResultTtlSpecs.cs +++ b/test/Polly.Specs/Caching/ResultTtlSpecs.cs @@ -42,7 +42,7 @@ public void Should_return_func_result() ResultTtl ttlStrategy = new ResultTtl(func); - Ttl retrieved = ttlStrategy.GetTtl(new Context("someOperationKey"), new { Ttl = ttl }); + Ttl retrieved = ttlStrategy.GetTtl([with("someOperationKey")], new { Ttl = ttl }); retrieved.Timespan.ShouldBe(ttl); retrieved.SlidingExpiration.ShouldBeFalse(); } @@ -57,7 +57,7 @@ public void Should_return_func_result_using_context() ResultTtl ttlStrategy = new ResultTtl(func); - ttlStrategy.GetTtl(new Context("someOperationKey"), new { Ttl = ttl }).Timespan.ShouldBe(ttl); - ttlStrategy.GetTtl(new Context(SpecialKey), new { Ttl = ttl }).Timespan.ShouldBe(TimeSpan.Zero); + ttlStrategy.GetTtl([with("someOperationKey")], new { Ttl = ttl }).Timespan.ShouldBe(ttl); + ttlStrategy.GetTtl([with(SpecialKey)], new { Ttl = ttl }).Timespan.ShouldBe(TimeSpan.Zero); } } diff --git a/test/Polly.Specs/Caching/SlidingTtlSpecs.cs b/test/Polly.Specs/Caching/SlidingTtlSpecs.cs index 95f3bc7c8ec..0a0e5bc341a 100644 --- a/test/Polly.Specs/Caching/SlidingTtlSpecs.cs +++ b/test/Polly.Specs/Caching/SlidingTtlSpecs.cs @@ -33,7 +33,7 @@ public void Should_return_configured_timespan() SlidingTtl ttlStrategy = new SlidingTtl(ttl); - Ttl retrieved = ttlStrategy.GetTtl(new Context("someOperationKey"), null); + Ttl retrieved = ttlStrategy.GetTtl([with("someOperationKey")], null); retrieved.Timespan.ShouldBe(ttl); retrieved.SlidingExpiration.ShouldBeTrue(); } diff --git a/test/Polly.Specs/ContextSpecs.cs b/test/Polly.Specs/ContextSpecs.cs index f7b8528b018..53d10cb9734 100644 --- a/test/Polly.Specs/ContextSpecs.cs +++ b/test/Polly.Specs/ContextSpecs.cs @@ -5,7 +5,7 @@ public class ContextSpecs [Fact] public void Should_assign_OperationKey_from_constructor() { - Context context = new Context("SomeKey"); + Context context = [with("SomeKey")]; context.OperationKey.ShouldBe("SomeKey"); @@ -33,7 +33,7 @@ public void NoArgsCtor_should_assign_no_OperationKey() [Fact] public void Should_assign_CorrelationId_when_accessed() { - Context context = new Context("SomeKey"); + Context context = [with("SomeKey")]; context.OperationKey.ShouldBe("SomeKey"); } @@ -41,7 +41,7 @@ public void Should_assign_CorrelationId_when_accessed() [Fact] public void Should_return_consistent_CorrelationId() { - Context context = new Context("SomeKey"); + Context context = [with("SomeKey")]; Guid retrieved1 = context.CorrelationId; Guid retrieved2 = context.CorrelationId; diff --git a/test/Polly.Specs/PolicyAsyncSpecs.cs b/test/Polly.Specs/PolicyAsyncSpecs.cs index 29e32f9e1f7..843bbf7c605 100644 --- a/test/Polly.Specs/PolicyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyAsyncSpecs.cs @@ -189,7 +189,7 @@ public async Task Executing_the_policy_function_should_throw_when_context_is_nul public async Task Executing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; var policy = Policy.NoOpAsync(); @@ -245,7 +245,7 @@ public async Task Execute_and_capturing_the_policy_function_should_throw_when_co public async Task Execute_and_capturing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; var policy = Policy.NoOpAsync(); @@ -259,7 +259,7 @@ public async Task Execute_and_capturing_the_policy_function_should_pass_context_ public async Task Execute_and_capturing_the_policy_function_should_pass_context_to_PolicyResult() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; var policy = Policy.NoOpAsync(); diff --git a/test/Polly.Specs/PolicyKeyAsyncSpecs.cs b/test/Polly.Specs/PolicyKeyAsyncSpecs.cs index 5870ac84e8c..14e9aa12c24 100644 --- a/test/Polly.Specs/PolicyKeyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyKeyAsyncSpecs.cs @@ -146,7 +146,7 @@ await retry.ExecuteAsync(async _ => firstExecution = false; throw new Exception(); } - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } @@ -196,7 +196,7 @@ await retry.ExecuteAsync(async _ => } return 0; - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } diff --git a/test/Polly.Specs/PolicyKeySpecs.cs b/test/Polly.Specs/PolicyKeySpecs.cs index b31085eab84..812cb58fa81 100644 --- a/test/Polly.Specs/PolicyKeySpecs.cs +++ b/test/Polly.Specs/PolicyKeySpecs.cs @@ -126,7 +126,7 @@ public void Should_pass_OperationKey_to_execution_context() firstExecution = false; throw new Exception(); } - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } @@ -174,7 +174,7 @@ public void Should_pass_OperationKey_to_execution_context_in_generic_execution_o } return 0; - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } diff --git a/test/Polly.Specs/PolicySpecs.cs b/test/Polly.Specs/PolicySpecs.cs index f8c26d81719..c0649ac19ae 100644 --- a/test/Polly.Specs/PolicySpecs.cs +++ b/test/Polly.Specs/PolicySpecs.cs @@ -185,7 +185,7 @@ public void Executing_the_policy_function_should_throw_when_context_is_null() public void Executing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; Policy policy = Policy.NoOp(); @@ -241,7 +241,7 @@ public void Execute_and_capturing_the_policy_function_should_throw_when_context_ public void Execute_and_capturing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; Policy policy = Policy.NoOp(); @@ -255,7 +255,7 @@ public void Execute_and_capturing_the_policy_function_should_pass_context_to_exe public void Execute_and_capturing_the_policy_function_should_pass_context_to_PolicyResult() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Policy policy = Policy.NoOp(); diff --git a/test/Polly.Specs/PolicyTResultAsyncSpecs.cs b/test/Polly.Specs/PolicyTResultAsyncSpecs.cs index fe947069b3b..22fc1287d94 100644 --- a/test/Polly.Specs/PolicyTResultAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyTResultAsyncSpecs.cs @@ -105,7 +105,7 @@ public async Task Executing_the_policy_function_should_throw_when_context_is_nul public async Task Executing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; var policy = Policy.NoOpAsync(); @@ -130,7 +130,7 @@ public async Task Execute_and_capturing_the_policy_function_should_throw_when_co public async Task Execute_and_capturing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; var policy = Policy.NoOpAsync(); @@ -144,7 +144,7 @@ public async Task Execute_and_capturing_the_policy_function_should_pass_context_ public async Task Execute_and_capturing_the_policy_function_should_pass_context_to_PolicyResult() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; var policy = Policy.NoOpAsync(); diff --git a/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs b/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs index 0dc12e5220e..9a025210f99 100644 --- a/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs +++ b/test/Polly.Specs/PolicyTResultKeyAsyncSpecs.cs @@ -140,7 +140,7 @@ await retry.ExecuteAsync(async _ => } return ResultPrimitive.Good; - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } diff --git a/test/Polly.Specs/PolicyTResultKeySpecs.cs b/test/Polly.Specs/PolicyTResultKeySpecs.cs index 2158d50c184..af779e04a2a 100644 --- a/test/Polly.Specs/PolicyTResultKeySpecs.cs +++ b/test/Polly.Specs/PolicyTResultKeySpecs.cs @@ -128,7 +128,7 @@ public void Should_pass_OperationKey_to_execution_context() } return ResultPrimitive.Good; - }, new Context(operationKey)); + }, [with(operationKey)]); operationKeySetOnContext.ShouldBe(operationKey); } diff --git a/test/Polly.Specs/PolicyTResultSpecs.cs b/test/Polly.Specs/PolicyTResultSpecs.cs index b0812c2bb03..d331db7c5ca 100644 --- a/test/Polly.Specs/PolicyTResultSpecs.cs +++ b/test/Polly.Specs/PolicyTResultSpecs.cs @@ -105,7 +105,7 @@ public void Executing_the_policy_function_should_throw_when_context_is_null() public void Executing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; Policy policy = Policy.NoOp(); @@ -141,7 +141,7 @@ public void Execute_and_capturing_the_policy_function_should_throw_when_context_ public void Execute_and_capturing_the_policy_function_should_pass_context_to_executed_delegate() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Context? capturedContext = null; Policy policy = Policy.NoOp(); @@ -156,7 +156,7 @@ public void Execute_and_capturing_the_policy_function_should_pass_context_to_exe public void Execute_and_capturing_the_policy_function_should_pass_context_to_PolicyResult() { string operationKey = "SomeKey"; - Context executionContext = new Context(operationKey); + Context executionContext = [with(operationKey)]; Policy policy = Policy.NoOp(); diff --git a/test/Polly.Specs/Polly.Specs.csproj b/test/Polly.Specs/Polly.Specs.csproj index a7d836659d8..fea06311e73 100644 --- a/test/Polly.Specs/Polly.Specs.csproj +++ b/test/Polly.Specs/Polly.Specs.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 enable Test diff --git a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs index 1c3ca996005..6f6f051f6cf 100644 --- a/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutAsyncSpecs.cs @@ -680,7 +680,7 @@ await Should.ThrowAsync(() => policy.ExecuteAsync(asyn public async Task Should_call_ontimeout_with_passed_context__pessimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Func onTimeoutAsync = (ctx, _, _) => @@ -921,7 +921,7 @@ await Should.ThrowAsync(() => policy.ExecuteAsync(asyn public async Task Should_call_ontimeout_with_passed_context__optimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Func onTimeoutAsync = (ctx, _, _) => diff --git a/test/Polly.Specs/Timeout/TimeoutSpecs.cs b/test/Polly.Specs/Timeout/TimeoutSpecs.cs index 351435a09e4..6c7ce501125 100644 --- a/test/Polly.Specs/Timeout/TimeoutSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutSpecs.cs @@ -671,7 +671,7 @@ public void Should_call_ontimeout_with_configured_timeout__pessimistic() public void Should_call_ontimeout_with_passed_context__pessimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; @@ -839,7 +839,7 @@ public void Should_call_ontimeout_with_configured_timeout__optimistic() public void Should_call_ontimeout_with_passed_context__optimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; diff --git a/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs b/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs index ae744a14529..3336e21e393 100644 --- a/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutTResultAsyncSpecs.cs @@ -562,7 +562,7 @@ await Should.ThrowAsync(() => policy.ExecuteAsync(asyn public async Task Should_call_ontimeout_with_passed_context__pessimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Func onTimeoutAsync = (ctx, _, _) => @@ -834,7 +834,7 @@ await Should.ThrowAsync(() => policy.ExecuteAsync(asyn public async Task Should_call_ontimeout_with_passed_context__optimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Func onTimeoutAsync = (ctx, _, _) => diff --git a/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs b/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs index 6fde711c9e6..717fdf50c5b 100644 --- a/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs +++ b/test/Polly.Specs/Timeout/TimeoutTResultSpecs.cs @@ -658,7 +658,7 @@ public void Should_call_ontimeout_with_configured_timeout__pessimistic() public void Should_call_ontimeout_with_passed_context__pessimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; @@ -821,7 +821,7 @@ public void Should_call_ontimeout_with_configured_timeout__optimistic() public void Should_call_ontimeout_with_passed_context__optimistic() { string operationKey = "SomeKey"; - Context contextPassedToExecute = new Context(operationKey); + Context contextPassedToExecute = [with(operationKey)]; Context? contextPassedToOnTimeout = null; Action onTimeout = (ctx, _, _) => contextPassedToOnTimeout = ctx; diff --git a/test/Polly.TestUtils/Polly.TestUtils.csproj b/test/Polly.TestUtils/Polly.TestUtils.csproj index f9cb8b05a5b..08f58153f02 100644 --- a/test/Polly.TestUtils/Polly.TestUtils.csproj +++ b/test/Polly.TestUtils/Polly.TestUtils.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 Library enable diff --git a/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj b/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj index 646329abf83..a7e3e3f7666 100644 --- a/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj +++ b/test/Polly.Testing.Tests/Polly.Testing.Tests.csproj @@ -1,6 +1,6 @@  - net10.0;net9.0;net8.0 + net11.0;net10.0 $(TargetFrameworks);net481 Test enable From 274386a6a67163c2abdeec1b5ae2fe3e25f6b397 Mon Sep 17 00:00:00 2001 From: "polly-updater-bot[bot]" <138034000+polly-updater-bot[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2026 18:27:08 +0000 Subject: [PATCH 02/15] Update .NET SDK (#2975) Update .NET SDK to version 11.0.100-preview.2.26159.112. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 11.0.100-preview.2.26159.112 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: polly-updater-bot[bot] <138034000+polly-updater-bot[bot]@users.noreply.github.com> Co-authored-by: polly-updater-bot[bot] <138034000+polly-updater-bot[bot]@users.noreply.github.com> --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index f711fcfb06c..b8b12d9b25f 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "11.0.100-preview.1.26104.118", + "version": "11.0.100-preview.2.26159.112", "allowPrerelease": false, "rollForward": "latestMinor" }, From bb2d99437b9f276dacf95e60ccdf0ad223929d82 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 10 Mar 2026 18:32:07 +0000 Subject: [PATCH 03/15] Update to .NET 11 preview 2 Update NuGet packages for .NET 11 preview 2. --- Directory.Packages.props | 20 +++++++++---------- .../Polly.Benchmarks/Polly.Benchmarks.csproj | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index f3e46470df4..d7013034cb3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,11 +13,11 @@ - - + + - - + + @@ -67,11 +67,11 @@ - - - - - - + + + + + + diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index 14b10c53e41..7b613d21bf2 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -13,7 +13,7 @@ - + From e8bf686fa0d0b2d1a104b5232c189f3897b08881 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Wed, 11 Mar 2026 14:02:45 +0000 Subject: [PATCH 04/15] Fix mutation tests Stryker errors for any unknown properties. --- eng/stryker-config.json | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/stryker-config.json b/eng/stryker-config.json index 37906bb49c2..8113fef7a0f 100644 --- a/eng/stryker-config.json +++ b/eng/stryker-config.json @@ -22,7 +22,6 @@ "concurrency": 4, "configuration": "Debug", "language-version": "Preview", - "_comment": "TODO Update to net11.0 when Stryker supports it", "target-framework": "net10.0", "thresholds": { "high": 100, From e19cda2cb9f73970bc5f3f988294046a37c1887f Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Thu, 12 Mar 2026 14:45:07 +0000 Subject: [PATCH 05/15] Fix native AoT tests on Linux Work around issue with newer versions of Clang. --- test/Polly.AotTest/Polly.AotTest.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Polly.AotTest/Polly.AotTest.csproj b/test/Polly.AotTest/Polly.AotTest.csproj index 462ee1c5286..75a5ce242ba 100644 --- a/test/Polly.AotTest/Polly.AotTest.csproj +++ b/test/Polly.AotTest/Polly.AotTest.csproj @@ -17,4 +17,8 @@ + + + + From 7bcfcb7856a974adfe725910145ff41d6e0e8704 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Thu, 12 Mar 2026 14:53:41 +0000 Subject: [PATCH 06/15] Fix build Only apply native AoT workaround on Linux. --- test/Polly.AotTest/Polly.AotTest.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Polly.AotTest/Polly.AotTest.csproj b/test/Polly.AotTest/Polly.AotTest.csproj index 75a5ce242ba..78ba4b2f1a3 100644 --- a/test/Polly.AotTest/Polly.AotTest.csproj +++ b/test/Polly.AotTest/Polly.AotTest.csproj @@ -18,7 +18,7 @@ - + From 3de65d1ec9ae6c49693494b054cf6790eabf0720 Mon Sep 17 00:00:00 2001 From: "polly-updater-bot[bot]" <138034000+polly-updater-bot[bot]@users.noreply.github.com> Date: Tue, 14 Apr 2026 17:05:21 +0000 Subject: [PATCH 07/15] Update .NET SDK (#3026) Update .NET SDK to version 11.0.100-preview.3.26207.106. --- updated-dependencies: - dependency-name: Microsoft.NET.Sdk dependency-version: 11.0.100-preview.3.26207.106 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: polly-updater-bot[bot] <138034000+polly-updater-bot[bot]@users.noreply.github.com> Co-authored-by: polly-updater-bot[bot] <138034000+polly-updater-bot[bot]@users.noreply.github.com> --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 06be0be7def..96c8c3792ab 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "11.0.100-preview.2.26159.112", + "version": "11.0.100-preview.3.26207.106", "allowPrerelease": false, "rollForward": "latestMinor" }, From c90c19c8705410fac7fac2e4e5216be526c36796 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 14 Apr 2026 18:19:35 +0100 Subject: [PATCH 08/15] Fix CS8629 warnings - Update NuGet packages for preview 3. - Fix CS8629 warnings from `Nullable.Value` usage. --- Directory.Packages.props | 20 +++++++++---------- .../Polly.Benchmarks/Polly.Benchmarks.csproj | 2 +- .../Controller/CircuitStateControllerTests.cs | 14 ++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 9e9f5d5e2e3..453171eb198 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,11 +13,11 @@ - - + + - - + + @@ -67,11 +67,11 @@ - - - - - - + + + + + + diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index 7b613d21bf2..bb2272b6efd 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -13,7 +13,7 @@ - + diff --git a/test/Polly.Core.Tests/CircuitBreaker/Controller/CircuitStateControllerTests.cs b/test/Polly.Core.Tests/CircuitBreaker/Controller/CircuitStateControllerTests.cs index d453f95c4f4..a84bc8344a4 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/Controller/CircuitStateControllerTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/Controller/CircuitStateControllerTests.cs @@ -53,7 +53,7 @@ public async Task IsolateAsync_Ok() called.ShouldBeTrue(); var outcome = await controller.OnActionPreExecuteAsync(context); - var exception = outcome.Value.Exception.ShouldBeOfType(); + var exception = outcome.GetValueOrDefault().Exception.ShouldBeOfType(); exception.RetryAfter.ShouldBeNull(); exception.TelemetrySource.ShouldNotBeNull(); @@ -125,7 +125,7 @@ public async Task OnActionPreExecute_CircuitOpenedByValue() using var controller = CreateController(); await OpenCircuit(controller, Outcome.FromResult(99)); - var exception = (BrokenCircuitException)(await controller.OnActionPreExecuteAsync(context)).Value.Exception!; + var exception = (BrokenCircuitException)(await controller.OnActionPreExecuteAsync(context)).GetValueOrDefault().Exception!; exception.RetryAfter.ShouldNotBeNull(); exception.TelemetrySource.ShouldNotBeNull(); @@ -149,7 +149,7 @@ await OpenCircuit( { try { - (await controller.OnActionPreExecuteAsync(context)).Value.ThrowIfException(); + (await controller.OnActionPreExecuteAsync(context)).GetValueOrDefault().ThrowIfException(); } catch (BrokenCircuitException e) { @@ -217,7 +217,7 @@ public async Task OnActionPreExecute_CircuitOpenedByException() using var controller = CreateController(); await OpenCircuit(controller, Outcome.FromException(new InvalidOperationException())); - var exception = (BrokenCircuitException)(await controller.OnActionPreExecuteAsync(context)).Value.Exception!; + var exception = (BrokenCircuitException)(await controller.OnActionPreExecuteAsync(context)).GetValueOrDefault().Exception!; exception.InnerException.ShouldBeOfType(); exception.RetryAfter.ShouldNotBeNull(); exception.TelemetrySource.ShouldNotBeNull(); @@ -276,7 +276,7 @@ public async Task OnActionPreExecute_HalfOpen() // act await controller.OnActionPreExecuteAsync(context); - var error = (await controller.OnActionPreExecuteAsync(context)).Value.Exception; + var error = (await controller.OnActionPreExecuteAsync(context)).GetValueOrDefault().Exception; // assert var exception = error.ShouldBeOfType(); @@ -489,7 +489,7 @@ public async Task OnActionFailureAsync_VoidResult_EnsureBreakingExceptionNotSet( // assert controller.LastException.ShouldBeNull(); var outcome = await controller.OnActionPreExecuteAsync(context); - var exception = outcome.Value.Exception.ShouldBeOfType(); + var exception = outcome.GetValueOrDefault().Exception.ShouldBeOfType(); exception.RetryAfter.ShouldNotBeNull(); exception.TelemetrySource.ShouldNotBeNull(); } @@ -530,7 +530,7 @@ public async Task Flow_Closed_HalfOpen_Open_HalfOpen_Closed() TimeSpan advanceTimeRejected = TimeSpan.FromMilliseconds(1); AdvanceTime(advanceTimeRejected); var outcome = await controller.OnActionPreExecuteAsync(context); - var exception = outcome.Value.Exception.ShouldBeOfType(); + var exception = outcome.GetValueOrDefault().Exception.ShouldBeOfType(); exception.RetryAfter.ShouldBe(_options.BreakDuration - advanceTimeRejected); exception.TelemetrySource.ShouldNotBeNull(); From 039564b3bae4fb4b1a5e1823702f9f3476f9bea8 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 14 Apr 2026 18:21:14 +0100 Subject: [PATCH 09/15] Remove workaround Remove workaround for Linux issue that should be fixed in .NET 11 preview 3. --- test/Polly.AotTest/Polly.AotTest.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/Polly.AotTest/Polly.AotTest.csproj b/test/Polly.AotTest/Polly.AotTest.csproj index 78ba4b2f1a3..462ee1c5286 100644 --- a/test/Polly.AotTest/Polly.AotTest.csproj +++ b/test/Polly.AotTest/Polly.AotTest.csproj @@ -17,8 +17,4 @@ - - - - From 550d1c1739894b74f16478d3105f616ab03b8c28 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 12 May 2026 20:20:42 +0100 Subject: [PATCH 10/15] Update to .NET 11 preview 4 (#3066) Update to preview 4 of .NET 11. --- Directory.Packages.props | 20 +++++++++---------- .../Polly.Benchmarks/Polly.Benchmarks.csproj | 2 +- global.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 63ba14eaf6d..111b4040c2c 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,11 +13,11 @@ - - + + - - + + @@ -67,11 +67,11 @@ - - - - - - + + + + + + diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index bb2272b6efd..c7656b4c296 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -13,7 +13,7 @@ - + diff --git a/global.json b/global.json index 96c8c3792ab..d17220029f0 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "11.0.100-preview.3.26207.106", + "version": "11.0.100-preview.4.26230.115", "allowPrerelease": false, "rollForward": "latestMinor" }, From 9923b8408e33047ea87581d7d4f6ae08668ec6a3 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 7 Jun 2026 15:13:37 +0100 Subject: [PATCH 11/15] Fix build Remove `rollForward` to workaround actions/setup-dotnet issue. --- global.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/global.json b/global.json index bc36ef0db68..6a87d59e47a 100644 --- a/global.json +++ b/global.json @@ -1,8 +1,7 @@ { "sdk": { "version": "11.0.100-preview.4.26230.115", - "allowPrerelease": false, - "rollForward": "latestMinor" + "allowPrerelease": false }, "msbuild-sdks": { "Cake.Sdk": "6.2.0" From 8b6971c354ee5f15c1d56aa53e3fcbd1f2da664d Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 9 Jun 2026 17:53:45 +0100 Subject: [PATCH 12/15] Update to .NET 11 preview 5 (#3107) Update to preview 5 of .NET 11. --- Directory.Packages.props | 20 +++++++++---------- .../Polly.Benchmarks/Polly.Benchmarks.csproj | 2 +- global.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 6ba3a2b3c74..f4c2f59a1a0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,11 +13,11 @@ - - + + - - + + @@ -67,11 +67,11 @@ - - - - - - + + + + + + diff --git a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj index c7656b4c296..fea722f2f1d 100644 --- a/bench/Polly.Benchmarks/Polly.Benchmarks.csproj +++ b/bench/Polly.Benchmarks/Polly.Benchmarks.csproj @@ -13,7 +13,7 @@ - + diff --git a/global.json b/global.json index 6a87d59e47a..82e846a1ad0 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "11.0.100-preview.4.26230.115", + "version": "11.0.100-preview.5.26302.115", "allowPrerelease": false }, "msbuild-sdks": { From 7786838e6ba97598a5c01d6df47c120a46dc519e Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 14 Jun 2026 15:45:55 +0100 Subject: [PATCH 13/15] Enable runtime async for tests Enable runtime async for test projects targeting .NET 11+. --- eng/Test.targets | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eng/Test.targets b/eng/Test.targets index 4058f40c299..885a31a7c29 100644 --- a/eng/Test.targets +++ b/eng/Test.targets @@ -5,6 +5,11 @@ true + + + runtime-async=on + + From 20c6ef79b6ea5c4643f1afa8a4e0e8d197eda919 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sun, 14 Jun 2026 15:46:10 +0100 Subject: [PATCH 14/15] Enable CheckSdkVulnerabilities Enable the new CheckSdkVulnerabilities property in .NET 11. --- eng/Common.props | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/Common.props b/eng/Common.props index bf4cf8420b8..d8f01c777a8 100644 --- a/eng/Common.props +++ b/eng/Common.props @@ -2,6 +2,7 @@ true $(MSBuildThisFileDirectory)..\Polly.snk + true enable preview direct From 020962f404db2dbf91b10d6cbe71363a8270a91b Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Sun, 14 Jun 2026 16:29:27 +0100 Subject: [PATCH 15/15] Fix build Append to `Features` rather than replacing it. --- eng/Test.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Test.targets b/eng/Test.targets index 885a31a7c29..53a6c1afa17 100644 --- a/eng/Test.targets +++ b/eng/Test.targets @@ -7,7 +7,7 @@ - runtime-async=on + $(Features);runtime-async=on