-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1289 from jnyrup/FuncTaskT
Support chaining `NotThrowAfter` and `NotThrowAsync`
- Loading branch information
Showing
18 changed files
with
890 additions
and
307 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
64 changes: 64 additions & 0 deletions
64
Src/FluentAssertions/Specialized/FunctionAssertionHelpers.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,64 @@ | ||
using System; | ||
using FluentAssertions.Common; | ||
using FluentAssertions.Execution; | ||
|
||
namespace FluentAssertions.Specialized | ||
{ | ||
internal class FunctionAssertionHelpers | ||
{ | ||
internal static T NotThrow<T>(Func<T> subject, string because, object[] becauseArgs) | ||
{ | ||
try | ||
{ | ||
return subject(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Execute.Assertion | ||
.ForCondition(exception is null) | ||
.BecauseOf(because, becauseArgs) | ||
.FailWith("Did not expect any exception{reason}, but found {0}.", exception); | ||
|
||
return default; | ||
} | ||
} | ||
|
||
internal static TResult NotThrowAfter<TResult>(Func<TResult> subject, IClock clock, TimeSpan waitTime, TimeSpan pollInterval, string because, object[] becauseArgs) | ||
{ | ||
if (waitTime < TimeSpan.Zero) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(waitTime), $"The value of {nameof(waitTime)} must be non-negative."); | ||
} | ||
|
||
if (pollInterval < TimeSpan.Zero) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(pollInterval), $"The value of {nameof(pollInterval)} must be non-negative."); | ||
} | ||
|
||
TimeSpan? invocationEndTime = null; | ||
Exception exception = null; | ||
ITimer timer = clock.StartTimer(); | ||
|
||
while (invocationEndTime is null || invocationEndTime < waitTime) | ||
{ | ||
try | ||
{ | ||
return subject(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
exception = ex; | ||
} | ||
|
||
clock.Delay(pollInterval); | ||
invocationEndTime = timer.Elapsed; | ||
} | ||
|
||
Execute.Assertion | ||
.BecauseOf(because, becauseArgs) | ||
.FailWith("Did not expect any exceptions after {0}{reason}, but found {1}.", waitTime, exception); | ||
|
||
return default; | ||
} | ||
} | ||
} |
Oops, something went wrong.