Skip to content

Commit 87cf9c0

Browse files
committed
use var
1 parent addc946 commit 87cf9c0

File tree

133 files changed

+2731
-2731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2731
-2731
lines changed

src/Polly.Benchmarks/Cache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public MemoryCacheProvider(IMemoryCache memoryCache)
6868

6969
public (bool, object) TryGet(string key)
7070
{
71-
bool cacheHit = _cache.TryGetValue(key, out var value);
71+
var cacheHit = _cache.TryGetValue(key, out var value);
7272
return (cacheHit, value);
7373
}
7474

7575
public void Put(string key, object value, Ttl ttl)
7676
{
77-
TimeSpan remaining = DateTimeOffset.MaxValue - DateTimeOffset.UtcNow;
77+
var remaining = DateTimeOffset.MaxValue - DateTimeOffset.UtcNow;
7878
var options = new MemoryCacheEntryOptions();
7979

8080
if (ttl.SlidingExpiration)

src/Polly.Benchmarks/Retry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<int> Retry_Asynchronous_With_Result_Succeeds_With_Cancellation
5050
[Benchmark]
5151
public void Retry_Synchronous_Throws_Then_Succeeds()
5252
{
53-
int count = 0;
53+
var count = 0;
5454

5555
SyncPolicy.Execute(() =>
5656
{
@@ -64,7 +64,7 @@ public void Retry_Synchronous_Throws_Then_Succeeds()
6464
[Benchmark]
6565
public async Task Retry_Asynchronous_Throws_Then_Succeeds()
6666
{
67-
int count = 0;
67+
var count = 0;
6868

6969
await AsyncPolicy.ExecuteAsync(() =>
7070
{

src/Polly.Specs/Bulkhead/BulkheadAsyncSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ public void Should_throw_when_onBulkheadRejected_is_null()
5454
[Fact]
5555
public void Should_call_onBulkheadRejected_with_passed_context()
5656
{
57-
string operationKey = "SomeKey";
58-
Context contextPassedToExecute = new Context(operationKey);
57+
var operationKey = "SomeKey";
58+
var contextPassedToExecute = new Context(operationKey);
5959

6060
Context contextPassedToOnRejected = null;
6161
Func<Context, Task> onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; };
6262

6363
using (var bulkhead = Policy.BulkheadAsync(1, onRejectedAsync))
6464
{
65-
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
66-
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
65+
var tcs = new TaskCompletionSource<object>();
66+
using (var cancellationSource = new CancellationTokenSource())
6767
{
6868
Task.Run(() => { bulkhead.ExecuteAsync(async () => { await tcs.Task; }); });
6969

src/Polly.Specs/Bulkhead/BulkheadSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public void Should_throw_when_onBulkheadRejected_is_null()
5252
[Fact]
5353
public void Should_call_onBulkheadRejected_with_passed_context()
5454
{
55-
string operationKey = "SomeKey";
56-
Context contextPassedToExecute = new Context(operationKey);
55+
var operationKey = "SomeKey";
56+
var contextPassedToExecute = new Context(operationKey);
5757

5858
Context contextPassedToOnRejected = null;
5959
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };
6060

61-
using (BulkheadPolicy bulkhead = Policy.Bulkhead(1, onRejected))
61+
using (var bulkhead = Policy.Bulkhead(1, onRejected))
6262
{
63-
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
63+
var tcs = new TaskCompletionSource<object>();
6464

6565
Task.Run(() => { bulkhead.Execute(() => { tcs.Task.Wait(); }); });
6666

src/Polly.Specs/Bulkhead/BulkheadSpecsBase.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ public void Should_control_executions_per_specification(int maxParallelization,
9393
TotalActions = totalActions;
9494
Scenario = $"MaxParallelization {maxParallelization}; MaxQueuing {maxQueuingActions}; TotalActions {totalActions}; CancelQueuing {cancelQueuing}; CancelExecuting {cancelExecuting}: {scenario}";
9595

96-
IBulkheadPolicy bulkhead = GetBulkhead(maxParallelization, maxQueuingActions);
96+
var bulkhead = GetBulkhead(maxParallelization, maxQueuingActions);
9797
using (bulkhead)
9898
{
9999
BulkheadForStats = bulkhead;
100100

101101
// Set up delegates which we can track whether they've started; and control when we allow them to complete (to release their semaphore slot).
102102
Actions = new TraceableAction[totalActions];
103-
for (int i = 0; i < totalActions; i++) { Actions[i] = new TraceableAction(i, StatusChangedEvent, TestOutputHelper); }
103+
for (var i = 0; i < totalActions; i++) { Actions[i] = new TraceableAction(i, StatusChangedEvent, TestOutputHelper); }
104104

105105
// Throw all the delegates at the bulkhead simultaneously.
106106
Tasks = new Task[totalActions];
107-
for (int i = 0; i < totalActions; i++) { Tasks[i] = ExecuteOnBulkhead(bulkhead, Actions[i]); }
107+
for (var i = 0; i < totalActions; i++) { Tasks[i] = ExecuteOnBulkhead(bulkhead, Actions[i]); }
108108

109109
OutputStatus("Immediately after queueing...");
110110

@@ -204,7 +204,7 @@ protected void UpdateActuals()
204204
{
205205
ActualCompleted = ActualCancelled = ActualExecuting = ActualRejects = ActualQueuing = ActualFaulted = 0;
206206

207-
foreach (TraceableAction action in Actions)
207+
foreach (var action in Actions)
208208
{
209209
switch (action.Status)
210210
{
@@ -285,7 +285,7 @@ protected AssertionFailure ActualsMatchExpecteds()
285285

286286
protected AssertionFailure AllTasksCompleted()
287287
{
288-
int countTasksCompleted = Tasks.Count(t => t.IsCompleted);
288+
var countTasksCompleted = Tasks.Count(t => t.IsCompleted);
289289
if (countTasksCompleted < TotalActions)
290290
{
291291
return new AssertionFailure(TotalActions, countTasksCompleted, nameof(countTasksCompleted));
@@ -296,7 +296,7 @@ protected AssertionFailure AllTasksCompleted()
296296

297297
protected void EnsureNoUnbservedTaskExceptions()
298298
{
299-
for (int i = 0; i < Tasks.Length; i++)
299+
for (var i = 0; i < Tasks.Length; i++)
300300
{
301301
try
302302
{
@@ -313,14 +313,14 @@ protected void EnsureNoUnbservedTaskExceptions()
313313

314314
protected AssertionFailure Expect(int expected, Func<int> actualFunc, string measure)
315315
{
316-
int actual = actualFunc();
316+
var actual = actualFunc();
317317
return actual != expected ? new AssertionFailure(expected, actual, measure) : null;
318318
}
319319

320320
protected void Within(TimeSpan timeSpan, Func<AssertionFailure> actionContainingAssertions)
321321
{
322-
TimeSpan permitted = timeSpan;
323-
Stopwatch watch = Stopwatch.StartNew();
322+
var permitted = timeSpan;
323+
var watch = Stopwatch.StartNew();
324324
while (true)
325325
{
326326
var potentialFailure = actionContainingAssertions();
@@ -336,7 +336,7 @@ protected void Within(TimeSpan timeSpan, Func<AssertionFailure> actionContaining
336336
throw new InvalidOperationException("Code should never reach here. Preceding assertion should fail.");
337337
}
338338

339-
bool signaled = StatusChangedEvent.WaitOne(ShimTimeSpan);
339+
var signaled = StatusChangedEvent.WaitOne(ShimTimeSpan);
340340
if (signaled)
341341
{
342342
// Following TraceableAction.CaptureCompletion() signalling the AutoResetEvent,
@@ -360,7 +360,7 @@ protected void OutputStatus(string statusHeading)
360360
TestOutputHelper.WriteLine("Bulkhead: {0} slots out of {1} available.", ActualBulkheadFree, MaxParallelization);
361361
TestOutputHelper.WriteLine("Bulkhead queue: {0} slots out of {1} available.", ActualQueueFree, MaxQueuingActions);
362362

363-
for (int i = 0; i < Actions.Length; i++)
363+
for (var i = 0; i < Actions.Length; i++)
364364
{
365365
TestOutputHelper.WriteLine("Action {0}: {1}", i, Actions[i].Status);
366366
}
@@ -382,7 +382,7 @@ public void Dispose()
382382

383383
if (Actions != null)
384384
{
385-
foreach (TraceableAction action in Actions)
385+
foreach (var action in Actions)
386386
{
387387
action.Dispose();
388388
}

src/Polly.Specs/Bulkhead/BulkheadTResultAsyncSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public void Should_throw_when_onBulkheadRejected_is_null()
5555
[Fact]
5656
public void Should_call_onBulkheadRejected_with_passed_context()
5757
{
58-
string operationKey = "SomeKey";
59-
Context contextPassedToExecute = new Context(operationKey);
58+
var operationKey = "SomeKey";
59+
var contextPassedToExecute = new Context(operationKey);
6060

6161
Context contextPassedToOnRejected = null;
6262
Func<Context, Task> onRejectedAsync = async ctx => { contextPassedToOnRejected = ctx; await TaskHelper.EmptyTask; };
6363

6464
using (var bulkhead = Policy.BulkheadAsync<int>(1, onRejectedAsync))
6565
{
66-
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
67-
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
66+
var tcs = new TaskCompletionSource<object>();
67+
using (var cancellationSource = new CancellationTokenSource())
6868
{
6969
Task.Run(() => {
7070
bulkhead.ExecuteAsync(async () =>

src/Polly.Specs/Bulkhead/BulkheadTResultSpecs.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public void Should_throw_when_onBulkheadRejected_is_null()
5555
[Fact]
5656
public void Should_call_onBulkheadRejected_with_passed_context()
5757
{
58-
string operationKey = "SomeKey";
59-
Context contextPassedToExecute = new Context(operationKey);
58+
var operationKey = "SomeKey";
59+
var contextPassedToExecute = new Context(operationKey);
6060

6161
Context contextPassedToOnRejected = null;
6262
Action<Context> onRejected = ctx => { contextPassedToOnRejected = ctx; };
6363

64-
using (BulkheadPolicy<int> bulkhead = Policy.Bulkhead<int>(1, onRejected))
64+
using (var bulkhead = Policy.Bulkhead<int>(1, onRejected))
6565
{
66-
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
67-
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
66+
var tcs = new TaskCompletionSource<object>();
67+
using (var cancellationSource = new CancellationTokenSource())
6868
{
6969
Task.Run(() => {
7070
bulkhead.Execute(() =>

src/Polly.Specs/Caching/AbsoluteTtlSpecs.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ public void Should_be_able_to_configure_for_past()
3737
[Fact]
3838
public void Should_return_zero_ttl_if_configured_to_expire_in_past()
3939
{
40-
AbsoluteTtl ttlStrategy = new AbsoluteTtl(SystemClock.DateTimeOffsetUtcNow().Subtract(TimeSpan.FromTicks(1)));
40+
var ttlStrategy = new AbsoluteTtl(SystemClock.DateTimeOffsetUtcNow().Subtract(TimeSpan.FromTicks(1)));
4141

4242
ttlStrategy.GetTtl(new Context("someOperationKey"), null).Timespan.Should().Be(TimeSpan.Zero);
4343
}
4444

4545
[Fact]
4646
public void Should_return_timespan_reflecting_time_until_expiry()
4747
{
48-
DateTime today = DateTime.Today;
49-
DateTime tomorrow = today.AddDays(1);
48+
var today = DateTime.Today;
49+
var tomorrow = today.AddDays(1);
5050

51-
AbsoluteTtl ttlStrategy = new AbsoluteTtl(tomorrow);
51+
var ttlStrategy = new AbsoluteTtl(tomorrow);
5252

5353
SystemClock.DateTimeOffsetUtcNow = () => today;
5454
ttlStrategy.GetTtl(new Context("someOperationKey"), null).Timespan.Should().Be(TimeSpan.FromDays(1));

0 commit comments

Comments
 (0)