-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for
ConfigureAwaitOptions
in .NET 8 (#189)
* Add `ConfigureAwaitOptions` * Update README.md * Update README.md * Fix File Naming * Update to v7.0.0 * `dotnet format`
- Loading branch information
1 parent
0be41b3
commit 6ef4fe6
Showing
13 changed files
with
449 additions
and
26 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
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
2 changes: 1 addition & 1 deletion
2
src/AsyncAwaitBestPractices.UnitTests/AsyncAwaitBestPractices.UnitTests.csproj
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
File renamed without changes.
122 changes: 122 additions & 0 deletions
122
...s.UnitTests/SafeFireAndForgetTests/Tests_Task_SafeFireAndForgetT_ConfigureAwaitOptions.cs
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,122 @@ | ||
#if NET8_0_OR_GREATER | ||
using System; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace AsyncAwaitBestPractices.UnitTests; | ||
|
||
class Tests_Task_SafeFIreAndForgetT_ConfigureAwaitOptions : BaseTest | ||
{ | ||
[SetUp] | ||
public void BeforeEachTest() | ||
{ | ||
SafeFireAndForgetExtensions.Initialize(false); | ||
SafeFireAndForgetExtensions.RemoveDefaultExceptionHandling(); | ||
} | ||
|
||
[TearDown] | ||
public void AfterEachTest() | ||
{ | ||
SafeFireAndForgetExtensions.Initialize(false); | ||
SafeFireAndForgetExtensions.RemoveDefaultExceptionHandling(); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForget_HandledException() | ||
{ | ||
//Arrange | ||
NullReferenceException? exception = null; | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget<NullReferenceException>(ConfigureAwaitOptions.None, ex => exception = ex); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNotNull(exception); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForget_HandledException_ConfigureAwaitOptionsSuppressThrowing() | ||
{ | ||
//Arrange | ||
NullReferenceException? exception = null; | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget<NullReferenceException>(ConfigureAwaitOptions.SuppressThrowing, ex => exception = ex); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNull(exception); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForgetT_SetDefaultExceptionHandling_NoParams() | ||
{ | ||
//Arrange | ||
Exception? exception = null; | ||
SafeFireAndForgetExtensions.SetDefaultExceptionHandling(ex => exception = ex); | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget(ConfigureAwaitOptions.None); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNotNull(exception); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForgetT_SetDefaultExceptionHandling_ConfigureAwaitOptionsSuppressThrowing() | ||
{ | ||
//Arrange | ||
Exception? exception = null; | ||
SafeFireAndForgetExtensions.SetDefaultExceptionHandling(ex => exception = ex); | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget(ConfigureAwaitOptions.SuppressThrowing); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNull(exception); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForgetT_SetDefaultExceptionHandling_WithParams() | ||
{ | ||
//Arrange | ||
Exception? exception1 = null; | ||
NullReferenceException? exception2 = null; | ||
SafeFireAndForgetExtensions.SetDefaultExceptionHandling(ex => exception1 = ex); | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget<NullReferenceException>(ConfigureAwaitOptions.None, ex => exception2 = ex); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNotNull(exception1); | ||
Assert.IsNotNull(exception2); | ||
} | ||
|
||
[Test] | ||
public async Task SafeFireAndForgetT_SetDefaultExceptionHandling_WithParams_ConfigureAwaitOptionsSuppressThrowing() | ||
{ | ||
//Arrange | ||
Exception? exception1 = null; | ||
NullReferenceException? exception2 = null; | ||
SafeFireAndForgetExtensions.SetDefaultExceptionHandling(ex => exception1 = ex); | ||
|
||
//Act | ||
NoParameterDelayedNullReferenceExceptionTask().SafeFireAndForget<NullReferenceException>(ConfigureAwaitOptions.SuppressThrowing, ex => exception2 = ex); | ||
await NoParameterTask(); | ||
await NoParameterTask(); | ||
|
||
//Assert | ||
Assert.IsNull(exception1); | ||
Assert.IsNull(exception2); | ||
} | ||
} | ||
#endif |
Oops, something went wrong.