You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_pages/upgradingtov7.md
+2-137Lines changed: 2 additions & 137 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,141 +11,6 @@ sidebar:
11
11
12
12
As of v7, we've decided to no longer directly target .NET Core. All versions of .NET Core, including .NET 5 are [already out of support by Microsoft](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core). But we still support .NET Standard 2.0 and 2.1, so Fluent Assertions will still work with those deprecated frameworks.
13
13
14
-
## From `Execute.Assertion` to `AssertionChain`
14
+
## Dropping support for `NSpec3` test framework
15
15
16
-
We've made quite some changes to the API that you use to build your own assertions. For example, the `BooleanAssertions` class was instantiated in `AssertionExtensions` like this:
To be able to support chaining multiple assertions where the chained assertion can extend the caller identification, we introduced an `AssertionChain` class which instance can flow from one assertion to another. Because of that, the above code changed to:
Notice how we pass the call to `AssertionChain.GetOrCreate` to the assertions class? By default `GetOrCreate` will create a new instance of `AssertionChain`. But if the previous assertion method uses `AssertionChain.ReuseOnce`, `GetOrCreate` will return that reused instance only once.
So all of the methods to build an assertion that used to live on the `AssertionScope` (which is what `Execute.Assertion` returned), have now moved to `AssertionChain`. This is great because it allows the second assertion to get access to the state of the first assertion. For instance, if the first assertion failed, any successive attempts to call `FailWith` will not do anything.
65
-
66
-
## No more `ClearExpectation`
67
-
68
-
If you wanted to reuse the first part of the failure message across multiple failures, you could use the following construct (example taken from `TimeOnlyAssertions.BeCloseTo`):
69
-
70
-
```csharp
71
-
Execute.Assertion
72
-
.BecauseOf(because, becauseArgs)
73
-
.WithExpectation("Expected {context:the time} to be within {0} from {1}{reason}, ", precision, nearbyTime)
.FailWith("but {0} was off by {1}.", Subject, difference)
79
-
.Then
80
-
.ClearExpectation();
81
-
```
82
-
83
-
When using an `using new AssertionScope()` construct to wrap multiple assertions, all assertions executed within that scope will reuse the same instance of `AssertionScope` (which is what `Execute.Assertion` returned). The problem was that you had to explicitly call `ClearExpectation` to prevent the failure message passed to `WithExpectation` to leak into the next assertion within that scope. People often forgot that.
84
-
85
-
We solved this in v7, by making `WithExpectation` use a nested construct. This is what it now looks like:
86
-
87
-
```csharp
88
-
assertionChain
89
-
.BecauseOf(because, becauseArgs)
90
-
.WithExpectation("Expected {context:the time} to be within {0} from {1}{reason}, ", precision, nearbyTime, chain=>chain
Prior to version 7, if the `HaveElement` assertion succeeded, but the `NotBeNull` failed, you would get the following exception:
119
-
120
-
Expected element to contain 1 item(s), but found 3: {<child />, <child />, <child />}.
121
-
122
-
Now, in v7, it'll will return the following:
123
-
124
-
Expected element/child to contain 1 item(s), but found 3: {<child />, <child />, <child />}.
125
-
126
-
This is possible because `HaveElement` will pass the `AssertionChain` through `ReuseOnce` to the succeeding `HaveCount()`_and_ amend the automatically detected caller identifier `element` (the part on which the first `Should` is invoked) with `"/child"` using `WithCallerPostfix`. Since this is a common thing in v7, the `AndWhichConstraint` has a constructor that does most of that automatically.
127
-
128
-
This is what `HaveElement` looks like (with some details left out):
0 commit comments