-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
989c399
commit 9de173b
Showing
122 changed files
with
4,384 additions
and
2,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Polly.Specs.Executables | ||
{ | ||
public class ExecutablesAsyncSpecs | ||
{ | ||
[Fact] | ||
public async Task Should_execute_user_delegate_with_input_parameter() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int64 captured = 0; | ||
|
||
await policy.ExecuteAsync<Int16>((context, token, captureContext, input) => | ||
{ | ||
captured = input; | ||
return Task.CompletedTask; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1); | ||
|
||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_execute_user_delegate_with_two_input_parameters() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
Int64 captured = 0; | ||
|
||
await policy.ExecuteAsync<Int16, Int32>((context, token, captureContext, t1, t2) => | ||
{ | ||
captured = t1 + t2; | ||
return Task.CompletedTask; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1, | ||
input2); | ||
|
||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_execute_user_delegate_with_input_parameter_and_return_type() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int64 captured = await policy.ExecuteAsync<Int16, Int64>(async (context, token, captureContext, input) => | ||
{ | ||
await Task.CompletedTask; | ||
return input; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1); | ||
|
||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_execute_user_delegate_with_two_input_parameters_and_return_type() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
Int64 captured = await policy.ExecuteAsync<Int16, Int32, Int64>(async (context, token, captureContext, t1, t2) => | ||
{ | ||
await Task.CompletedTask; | ||
return t1 + t2; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1, | ||
input2); | ||
|
||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_executeandcapture_user_delegate_with_input_parameter() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int64 captured = 0; | ||
|
||
var policyResult = await policy.ExecuteAndCaptureAsync<Int16>((context, token, captureContext, input) => | ||
{ | ||
captured = input; | ||
return Task.CompletedTask; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_executeandcapture_user_delegate_with_two_input_parameters() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
Int64 captured = 0; | ||
|
||
var policyResult = await policy.ExecuteAndCaptureAsync<Int16, Int32>((context, token, captureContext, t1, t2) => | ||
{ | ||
captured = t1 + t2; | ||
return Task.CompletedTask; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1, | ||
input2); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_executeandcapture_user_delegate_with_input_parameter_and_return_type() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
var policyResult = await policy.ExecuteAndCaptureAsync<Int16, Int64>(async (context, token, captureContext, input) => | ||
{ | ||
await Task.CompletedTask; | ||
return input; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
policyResult.Result.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_executeandcapture_user_delegate_with_two_input_parameters_and_return_type() | ||
{ | ||
var policy = Policy.NoOpAsync(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
var policyResult = await policy.ExecuteAndCaptureAsync<Int16, Int32, Int64>(async (context, token, captureContext, t1, t2) => | ||
{ | ||
await Task.CompletedTask; | ||
return t1 + t2; | ||
}, new Context(), | ||
CancellationToken.None, | ||
continueOnCapturedContext: false, | ||
input1, | ||
input2); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
policyResult.Result.Should().Be(input1 + input2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using System.Threading; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Polly.Specs.Executables | ||
{ | ||
public class ExecutablesSyncSpecs | ||
{ | ||
[Fact] | ||
public void Should_execute_user_delegate_with_input_parameter() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
Int64 captured = 0; | ||
|
||
policy.Execute<Int16>((context, token, input) => | ||
{ | ||
captured = input; | ||
}, new Context(), | ||
CancellationToken.None, | ||
input1); | ||
|
||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public void Should_execute_user_delegate_with_two_input_parameters() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
Int64 captured = 0; | ||
|
||
policy.Execute<Int16, Int32>((context, token, t1, t2) => | ||
{ | ||
captured = t1 + t2; | ||
}, new Context(), | ||
CancellationToken.None, | ||
input1, | ||
input2); | ||
|
||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public void Should_execute_user_delegate_with_input_parameter_and_return_type() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
double captured = policy.Execute<Int16, Int64>((context, token, input) => input, new Context(), | ||
CancellationToken.None, | ||
input1); | ||
|
||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public void Should_execute_user_delegate_with_two_input_parameters_and_return_type() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
double captured = policy.Execute<Int16, Int32, Int64>((context, token, t1, t2) => t1 + t2, new Context(), | ||
CancellationToken.None, | ||
input1, | ||
input2); | ||
|
||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public void Should_executeandcapture_user_delegate_with_input_parameter() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
double captured = 0; | ||
|
||
var policyResult = policy.ExecuteAndCapture<Int16>((context, token, input) => | ||
{ | ||
captured = input; | ||
}, new Context(), | ||
CancellationToken.None, | ||
input1); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
captured.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public void Should_executeandcapture_user_delegate_with_two_input_parameters() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
double captured = 0; | ||
|
||
var policyResult = policy.ExecuteAndCapture<Int16, Int32>((context, token, t1, t2) => | ||
{ | ||
captured = t1 + t2; | ||
}, new Context(), | ||
CancellationToken.None, | ||
input1, | ||
input2); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
captured.Should().Be(input1 + input2); | ||
} | ||
|
||
[Fact] | ||
public void Should_executeandcapture_user_delegate_with_input_parameter_and_return_type() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
var policyResult = policy.ExecuteAndCapture<Int16, Int64>((context, token, input) => input, new Context(), | ||
CancellationToken.None, | ||
input1); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
policyResult.Result.Should().Be(input1); | ||
} | ||
|
||
[Fact] | ||
public void Should_executeandcapture_user_delegate_with_two_input_parameters_and_return_type() | ||
{ | ||
var policy = Policy.NoOp(); | ||
|
||
Int16 input1 = 1; | ||
Int32 input2 = 2; | ||
var policyResult = policy.ExecuteAndCapture<Int16, Int32, Int64>((context, token, t1, t2) => t1 + t2, new Context(), | ||
CancellationToken.None, | ||
input1, | ||
input2); | ||
|
||
policyResult.Outcome.Should().Be(OutcomeType.Successful); | ||
policyResult.Result.Should().Be(input1 + input2); | ||
} | ||
} | ||
} |
Oops, something went wrong.