-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed some catch() extensions, and added tests
- Loading branch information
1 parent
5af7a49
commit e0ffd22
Showing
5 changed files
with
170 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Then.Tests { | ||
public class CatchTests { | ||
public class CustomException : Exception { | ||
public CustomException() : this( "Hello World" ) { } | ||
public CustomException( string message ) : base( message ) { } | ||
} | ||
|
||
public class OtherException : Exception { | ||
public OtherException() : this( "Hello World" ) { } | ||
public OtherException( string message ) : base( message ) { } | ||
} | ||
|
||
[Fact] | ||
public async Task CatchTestSimple() | ||
{ | ||
await Task | ||
.FromException( new CustomException() ) | ||
.Catch(); | ||
} | ||
|
||
[Fact] | ||
public async Task CatchTestSimple2() | ||
{ | ||
var result = await Task | ||
.FromException<string>( new CustomException() ) | ||
.Catch(); | ||
|
||
Assert.Null( result ); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task SimpleUntypedExceptionHandler() | ||
{ | ||
var result = await Task | ||
.FromException<string>( new CustomException() ) | ||
.Catch( e => "hello" ); | ||
|
||
Assert.Equal( "hello", result ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleTypedExceptionHandler() | ||
{ | ||
var result = await Task | ||
.FromException<string>( new CustomException() ) | ||
.Catch<string, CustomException>( e => "hello" ); | ||
|
||
Assert.Equal( "hello", result ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleUntypedAsyncExceptionHandler() | ||
{ | ||
var result = await Task | ||
.FromException<string>( new CustomException() ) | ||
.Catch( async e => "hello" ); | ||
|
||
Assert.Equal( "hello", result ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleTypedAsyncExceptionHandler() | ||
{ | ||
var result = await Task | ||
.FromException<string>( new CustomException() ) | ||
.Catch<string, CustomException>( async e => "hello" ); | ||
|
||
Assert.Equal( "hello", result ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleTypedExceptionHandlerWithNoResult() | ||
{ | ||
await Task | ||
.FromException( new CustomException() ) | ||
.Catch<CustomException>( e => { } ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleUntypedExceptionHandlerWithNoResult() | ||
{ | ||
await Task | ||
.FromException( new CustomException() ) | ||
.Catch( e => { } ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleTypedAsyncExceptionHandlerWithNoResult() | ||
{ | ||
await Task | ||
.FromException( new CustomException() ) | ||
.Catch<CustomException>( async e => { } ); | ||
} | ||
|
||
[Fact] | ||
public async Task SimpleUntypedAsyncExceptionHandlerWithNoResult() | ||
{ | ||
await Task | ||
.FromException( new CustomException() ) | ||
.Catch( async e => { } ); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task FilteredExceptionHandlerShouldNotCatchOtherExceptions() | ||
{ | ||
await Assert.ThrowsAsync<OtherException>( async () => { | ||
await Task | ||
.FromException<string>( new OtherException() ) | ||
.Catch<string, CustomException>( e => "hello" ); | ||
} ); | ||
} | ||
} | ||
} |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> | ||
<PackageReference Include="xunit" Version="2.2.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Then\Then.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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