-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support async & task as first-class testables
- Loading branch information
1 parent
dcc9ec2
commit b88b0b9
Showing
9 changed files
with
370 additions
and
48 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
56 changes: 56 additions & 0 deletions
56
examples/FsCheck.NUnit.CSharpExamples/SyncVersusAsyncExamples.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,56 @@ | ||
using System.Threading.Tasks; | ||
using FsCheck.Fluent; | ||
using NUnit.Framework; | ||
|
||
namespace FsCheck.NUnit.CSharpExamples; | ||
|
||
public class SyncVersusAsyncExamples | ||
{ | ||
[Property] | ||
public Property Property_ShouldPass(bool b) | ||
{ | ||
return (b ^ !b).Label("b ^ !b"); | ||
} | ||
|
||
[Property] | ||
public Property Property_ShouldFail(bool b) | ||
{ | ||
return (b && !b).Label("b && !b"); | ||
} | ||
|
||
[Property] | ||
public async Task Task_ShouldPass(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
Assert.That(b ^ !b); | ||
} | ||
|
||
[Property] | ||
public async Task Task_Exception_ShouldFail(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
Assert.That(b && !b); | ||
} | ||
|
||
[Property] | ||
public async Task Task_Cancelled_ShouldFail(bool b) | ||
{ | ||
await Task.Run(() => Assert.That(b ^ !b), new System.Threading.CancellationToken(canceled: true)); | ||
} | ||
|
||
[Property] | ||
public async Task<Property> TaskProperty_ShouldPass(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
return (b ^ !b).Label("b ^ !b"); | ||
} | ||
|
||
[Property] | ||
public async Task<Property> TaskProperty_ShouldFail(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
return (b && !b).Label("b && !b"); | ||
} | ||
|
||
private static async Task DoSomethingAsync() => await Task.Yield(); | ||
} |
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
29 changes: 29 additions & 0 deletions
29
examples/FsCheck.NUnit.Examples/SyncVersusAsyncExamples.fs
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,29 @@ | ||
namespace FsCheck.NUnit.Examples | ||
|
||
open FsCheck.FSharp | ||
open FsCheck.NUnit | ||
|
||
module SyncVersusAsyncExamples = | ||
let private doSomethingAsync () = async { return () } | ||
|
||
[<Property>] | ||
let ``Sync - should pass`` b = | ||
b = b |> Prop.label "b = b" | ||
|
||
[<Property>] | ||
let ``Sync - should fail`` b = | ||
b = not b |> Prop.label "b = not b" | ||
|
||
[<Property>] | ||
let ``Async - should pass`` b = | ||
async { | ||
do! doSomethingAsync () | ||
return b = b |> Prop.label "b = b" | ||
} | ||
|
||
[<Property>] | ||
let ``Async - should fail`` b = | ||
async { | ||
do! doSomethingAsync () | ||
return b = not b |> Prop.label "b = not b" | ||
} |
57 changes: 57 additions & 0 deletions
57
examples/FsCheck.XUnit.CSharpExamples/SyncVersusAsyncExamples.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,57 @@ | ||
using System.Threading.Tasks; | ||
using FsCheck.Fluent; | ||
using FsCheck.Xunit; | ||
using Xunit; | ||
|
||
namespace FsCheck.XUnit.CSharpExamples; | ||
|
||
public class SyncVersusAsyncExamples | ||
{ | ||
[Property] | ||
public Property Property_ShouldPass(bool b) | ||
{ | ||
return (b ^ !b).Label("b ^ !b"); | ||
} | ||
|
||
[Property] | ||
public Property Property_ShouldFail(bool b) | ||
{ | ||
return (b && !b).Label("b && !b"); | ||
} | ||
|
||
[Property] | ||
public async Task Task_ShouldPass(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
Assert.True(b ^ !b); | ||
} | ||
|
||
[Property] | ||
public async Task Task_Exception_ShouldFail(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
Assert.True(b && !b); | ||
} | ||
|
||
[Property] | ||
public async Task Task_Cancelled_ShouldFail(bool b) | ||
{ | ||
await Task.Run(() => Assert.True(b ^ !b), new System.Threading.CancellationToken(canceled: true)); | ||
} | ||
|
||
[Property] | ||
public async Task<Property> TaskProperty_ShouldPass(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
return (b ^ !b).Label("b ^ !b"); | ||
} | ||
|
||
[Property] | ||
public async Task<Property> TaskProperty_ShouldFail(bool b) | ||
{ | ||
await DoSomethingAsync(); | ||
return (b && !b).Label("b && !b"); | ||
} | ||
|
||
private static async Task DoSomethingAsync() => await Task.Yield(); | ||
} |
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
Oops, something went wrong.