1
#if NET_3_5 || NET_4_0 || NET_4_5
3
using System.Threading.Tasks;
5
using NUnit.Framework.Constraints;
7
namespace nunit.framework.tests.net45
10
public class AfterDelayedTests
13
public void ConstraintSuccess()
15
Assert.IsTrue(new DelayedConstraint(new EqualConstraint(1), 100)
16
.Matches(async () => await One()));
20
public void ConstraintFailure()
22
Assert.IsFalse(new DelayedConstraint(new EqualConstraint(2), 100)
23
.Matches(async () => await One()));
27
public void ConstraintError()
29
Assert.Throws<InvalidOperationException>(() =>
30
new DelayedConstraint(new EqualConstraint(1), 100).Matches(async () => await Throw()));
34
public void ConstraintVoidDelegateFailureAsDelegateIsNotCalled()
36
Assert.IsFalse(new DelayedConstraint(new EqualConstraint(1), 100)
37
.Matches(new TestDelegate(async () => { await One(); })));
41
public void ConstraintVoidDelegateExceptionIsFailureAsDelegateIsNotCalled()
43
Assert.IsFalse(new DelayedConstraint(new EqualConstraint(1), 100)
44
.Matches(new TestDelegate(async () => { await Throw(); })));
48
public void SyntaxSuccess()
50
Assert.That(async () => await One(), Is.EqualTo(1).After(100));
55
public void SyntaxFailure()
57
Assert.Throws<AssertionException>(() =>
58
Assert.That(async () => await One(), Is.EqualTo(2).After(100)));
62
public void SyntaxError()
64
Assert.Throws<InvalidOperationException>(() =>
65
Assert.That(async () => await Throw(), Is.EqualTo(1).After(100)));
69
public void SyntaxVoidDelegateExceptionIsFailureAsCodeIsNotCalled()
71
Assert.Throws<AssertionException>(() =>
72
Assert.That(new TestDelegate(async () => await Throw()), Is.EqualTo(1).After(100)));
75
private static async Task<int> One()
77
return await Task.Run(() => 1);
80
private static async Task Throw()
83
throw new InvalidOperationException();
b'\\ No newline at end of file'