https://github.com/mazharenko/fluentassertions.eventual
The extension allows to wait for an assertion to pass
https://github.com/mazharenko/fluentassertions.eventual
csharp-sourcegenerator extensions fluentassertions
Last synced: 29 days ago
JSON representation
The extension allows to wait for an assertion to pass
- Host: GitHub
- URL: https://github.com/mazharenko/fluentassertions.eventual
- Owner: mazharenko
- License: cc0-1.0
- Archived: true
- Created: 2022-07-02T09:09:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-05-05T06:52:47.000Z (9 months ago)
- Last Synced: 2025-05-05T07:41:20.126Z (9 months ago)
- Topics: csharp-sourcegenerator, extensions, fluentassertions
- Language: C#
- Homepage:
- Size: 89.8 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The project is archived due to the recent FluentAssertions licence [update](https://github.com/fluentassertions/fluentassertions/pull/2943).
[](https://www.nuget.org/packages/mazharenko.FluentAssertions.Eventual/)
[](https://www.nuget.org/packages/mazharenko.FluentAssertions.Eventual.FSharp/)
[](https://www.nuget.org/packages/mazharenko.FluentAssertions.Eventual.Generator/)
[](LICENSE)
# Eventual assertions for FluentAssertions
`FluentAssertions.Eventual` is an extension that allows to wait for `FluentAssertions` checks to pass which can be useful when writing end-to-end tests.
## Basic usage
Any `FluentAssertions` checks can be placed under a special `foreach` loop, which will implement the waiting and retry logic.
```csharp
foreach (var _ in EventualAssertions.Attempts(4.Seconds(), 400.Milliseconds()))
{
button.Should().BeVisible();
}
```
## Source generator usage
When having a custom assertion class for a dynamic by nature subject the class can be decorated by the `[GenerateEventual]` attribute to get a special waiting wrapper generated.
Your code (simplified):
```csharp
[GenerateEventual]
public class ButtonAssertions
{
[CustomAssertion]
public AndConstraint BeVisible(string? because = null, params object[] becauseArgs)
{
// implementation
}
}
```
What gets generated (simplified):
```csharp
public static class ButtonAssertions_Eventual_Extensions
{
public static ButtonAssertions_Eventual Eventually(this ButtonAssertions underlying) { /* ... */ }
// more generated extensions
}
public class ButtonAssertions_Eventual
{
// constructor, fields
[CustomAssertion]
public AndConstraint BeVisible(string? because = null, params object[] becauseArgs)
{
AndConstraint result = default !;
foreach (var _ in EventualAssertions.Attempts(timeout, delay))
result = underlying.BeVisible(because, becauseArgs);
return result;
}
}
```
Which allows for the following syntax:
```csharp
button.Should().Eventually().BeVisible();
button.Should().Eventually(4.Seconds(), 400.Milliseconds()).BeVisible();
button.Should().EventuallyLong().BeVisible();
```
## More info
Complete interactive README in mybinder:\
[](https://mybinder.org/v2/gh/mazharenko/FluentAssertions.Eventual/HEAD?urlpath=lab/tree/README.ipynb)
Also in nbviewer:\
[](https://nbviewer.org/github/mazharenko/FluentAssertions.Eventual/tree/HEAD/docs/README.ipynb)