Releases
8.1.0
- Provide a toggle to suppress the soft warning that commercial use requires a paid license - #2984
8.0.0
License Change
Versions 8 and beyond are/will be free for open-source projects and non-commercial use, but commercial use requires a paid license. Check out the license page for more information.
Version 7 will remain fully open-source indefinitely and receive bugfixes and other important corrections.
What’s new
- Introduced a new assembly-level attribute that you can use to initialize Fluent Assertions before the first assertion - #2292
- Ensure compatibility with .NET 8 - #2466
- Add support for NUnit 4 - #2483
- Added
NotBeIn
to check if aDateTime
is not in a givenDateTimeKind
- #2536 - Introduced a new
Satisfy
method available to all reference types to allow for nested assertions - #2597 - Added
BeNaN
andNotBeNaN
for assertions onfloat
anddouble
- #2606 - Added option for event monitoring to ignore failing event accessors - #2629
- Added the capability of associating
IValueFormatter
s to a (nested)AssertionScope
- #2676 - Added support for throwing TUnit exceptions when using TUnit as your testing framework - #2758
- Added a few more assertions on
XElement
- #2690[Not]HaveElementWithValue
NotHaveElement
[Not]HaveAttribute
NotHaveAttributeWithValue
- Added a few more assertions on
XDocument
- #2690[Not]HaveElementWithValue
NotHaveElement
- Added support for xUnit.net v3 - #2718
Improvements
- Improve failure message for string assertions when checking for equality - #2307
- Allow specifying
EquivalencyOptions
in string assertions - #2413- This also adds the capability to ignore casing, leading or trailing whitespace on strings when using
BeEquivalentTo
on object graphs or collections. - Also adds the capability to ignore the newline style on strings - #2565
- This also adds the capability to ignore casing, leading or trailing whitespace on strings when using
- You can mark all assertions in an assembly as custom assertions using the
[CustomAssertionsAssembly]
attribute - #2389 - All
Should()
methods on reference types are now annotated with the[NotNull]
attribute for a better Fluent Assertions experience when nullable reference types are enabled - #2380 - All assertions that support chaining using the
.Which
construct will now amend the caller identifier - #2539 - Introduced a
MethodInfoFormatter
and improved thePropertyInfoFormatter
- #2539 Excluding()
/For().Exclude()
andIncluding()
onBeEquivalentTo()
now also accepts an anonymous object to include/exclude multiple members at once - #2488- You can exclude explicitly implemented properties from
BeEquivalentTo
viaExcludingExplicitlyImplementedProperties
- #2851
Fixes
- Fixed incorrect treatment of “\r\n” as new line - #2569
- Fixed
RaisePropertyChangeFor
to return a filtered list of events - #2677 - Including or excluding members did not work when
WithMapping
was used inBeEquivalentTo
- #2860 - Fix a crash when using
WithStrictOrderingFor(x => x)
withBeEquivalentTo
- #2932
Breaking Changes (for users)
- Moved support for
DataSet
,DataTable
,DataRow
andDataColumn
into a new packageFluentAssertions.DataSet
- #2267 - Removed obsolete
...OrEqualTo
methods - #2269GenericCollectionAssertions
HaveCountGreaterOrEqualTo
: UseHaveCountGreaterThanOrEqualTo
HaveCountLessOrEqualTo
: UseHaveCountLessThanOrEqualTo
ComparableTypeAssertions
BeGreaterOrEqualTo
: UseBeGreaterThanOrEqualTo
BeLessOrEqualTo
: UseBeLessThanOrEqualTo
SimpleTimeSpanAssertions
BeGreaterOrEqualTo
: UseBeGreaterThanOrEqualTo
BeLessOrEqualTo
: UseBeLessThanOrEqualTo
ExecutionTimeAssertions
BeGreaterOrEqualTo
: UseBeGreaterThanOrEqualTo
BeLessOrEqualTo
: UseBeLessThanOrEqualTo
- Removed the
DefaultValueFormatter.SpacesPerIndentionLevel
property which was added during the development of v6, but wasn’t removed before the release of v6 - #2281 - Dropped direct support for .NET Core 2.x and .NET Core 3.x - #2302
AllSatisfy
now succeeds when asserting that an empty collection satisfies some predicates - #2321OnlyContain
now succeeds when asserting that an empty collection matches some predicates - #2350- Dropped support for
BinaryFormatter
- #2278 - Renamed “…AssertionOptions” to “…Options” - #2414
EquivalencyAssertionOptions
toEquivalencyOptions
EquivalencyAssertionOptions<TExpectation>
toEquivalencyOptions<TExpectation>
IEquivalencyAssertionOptions
toIEquivalencyOptions
SelfReferenceEquivalencyAssertionOptions<TSelf>
toSelfReferenceEquivalencyOptions<TSelf>
- Allow fluently calling
WithoutMatchingRules
andWithoutSelectionRules
while usingBeEquivalentTo
- #2457 - Removed
utcNow
overload for.Monitor<T>()
- #2629 - The semantics of
BeLowerCased
/BeUpperCased
have been changed to align with the behavior ofToLower
/ToUpper
- #2660 - Renamed
HaveAttribute
toHaveAttributeWithValue
onXElement
- #2690 - Renamed
RespectingRuntimeTypes
toPreferringRuntimeMemberTypes
andRespectingDeclaredTypes
toPreferringDeclaredMemberTypes
- #2866 - Renamed
ExcludingNestedObjects
toWithoutRecursing
to better describe its purpose - #2876 - Removed direct support for assertions on
HttpResponseMessage
. Use FluentAssertions.Web instead. - #2909 - Consolidated the configuration options under
Configuration
andServices
intoGlobalConfiguration
accessible throughAssertionEngine.Configuration
andAssertionConfiguration.Current.Configuration
- #2901 - Removed support for setting configuration settings through an
app.config
file - #2901
Breaking Changes (for extensions)
- Add
ForConstraint
toIAssertionsScope
to support chaining.ForConstraint()
after.Then
- #2324 - Refactored
AsyncFunctionAssertions
into real base class - #2359- Its constructor has been made
protected
. - Unused constructors have been removed.
- Methods overwritten in
GenericAsyncFunctionAssertions
has been moved toNonGenericAsyncFunctionAssertions
.
- Its constructor has been made
- Moved the non-generic
NotThrow
andNotThrowAfter
fromDelegateAssertions<TDelegate, TAssertions>
toActionAssertions
- #2371 - Made
EquivalencyValidator
internal
- #2854
7.1.0
Improvements
- Added compatibility with xUnit.net v3 - #2970
- Added support for throwing TUnit exceptions when using TUnit as your testing framework - #2971
7.0.0
Fixes
- The expectation node identified as a cyclic reference is still compared to the subject node using simple equality - #2819
- Fixed a problem in
BeEquivalentTo
where write-only properties would cause aNullReferenceException
- #2836
Breaking Changes
- Dropped direct support for .NET Core 2.x and .NET Core 3.x - #2302
- Dropped support for
NSpec3
test framework - #2356 - Raised dependencies on
System.Configuration.ConfigurationManager
to 6.0.0 andSystem.Threading.Tasks.Extensions
to 4.5.4 - #2673 and #2855
6.12.2
Fixes
- Better handling of normal vs explicitly implemented vs default interface properties - #2794
6.12.1
Improvements
- Improve
BeEmpty()
andBeNullOrEmpty()
performance forIEnumerable<T>
, by materializing only the first item - #2530
Fixes
- Fixed formatting error when checking nullable
DateTimeOffset
withBeWithin(...).Before(...)
- #2312 BeEquivalentTo
will now find and can map subject properties that are implemented through an explicitly-implemented interface - #2152- Fixed that the
because
andbecauseArgs
were not passed down the equivalency tree - #2318 BeEquivalentTo
can again compare a non-genericIDictionary
with a generic one - #2358- Fixed that the
FormattingOptions
were not respected in innerAssertionScope
- #2329 - Capitalize
true
andfalse
in failure messages and make them formattable to a customBooleanFormatter
- #2390, #2393 - Improved the failure message for
NotBeOfType
when wrapped in anAssertionScope
and the subject is null - #2399 - Improved the failure message for
BeWritable
/BeReadable
when wrapped in anAssertionScope
and the subject is read-only/write-only - #2399 - Improved the failure message for
ThrowExactly[Async]
when wrapped in anAssertionScope
and no exception is thrown - #2398 - Improved the failure message for
[Not]HaveExplicitProperty
when wrapped in anAssertionScope
and not implementing the interface - #2403 - Improved the failure message for
[Not]HaveExplicitMethod
when wrapped in anAssertionScope
and not implementing the interface - #2403 - Changed
BeEquivalentTo
to excludeprivate protected
members from the comparison - #2417 - Fixed using
BeEquivalentTo
on an emptyArraySegment
- #2445, #2511 BeEquivalentTo
with a custom comparer can now handle null values - #2489- Ensured that nested calls to
AssertionScope(context)
create a chained context - #2607 - One overload of the
AssertionScope
constructor would not create an actual scope associated with the thread - #2607 - Fixed
ThrowWithinAsync
not respectingOperationCanceledException
- #2614 - Fixed using
BeEquivalentTo
with anIEqualityComparer
targeting nullable types - #2648
6.12.0
What’s new
- Added
Be
,NotBe
andBeOneOf
for object comparisons with custom comparer - #2111 - Added
BeSignedWithPublicKey()
andBeUnsigned()
for assertions onAssembly
- #2207 - Added
NotContainItemsAssignableTo
for asserting that a collection does not contain any items assignable to a specific type - #2266
Fixes
because
andbecauseArgs
were not included in the error message when collections of enums were not equivalent - #2214- Improve caller identification for tests written in Visual Basic - #2254
- Improved auto conversion to enums for objects of different integral type - #2261
- Fixed exceptions when trying to auto convert strings or enums of different type to enums- #2261
- Format records and anonymous objects with their member values instead of the generated
ToString
- #2144
6.11.0
What’s new
- Added
ThrowWithinAsync
for assertions onTask
- #1974 - Added support for converting integers to enums using
AutoConversion
- #2147 - Changed exception formatting to include any inner exception - #2150
- Added an expression overload for
WithoutStrictOrderingFor
- #2151
Fixes
- Improved robustness of several assertions when they’re wrapped in an
AssertionScope
- #2133 - The maximum depth
BeEquivalentTo
uses for recursive comparisons was 9 instead of the expected 10 - #2145 - Fixed
.Excluding()
and.For().Exclude()
not working if root is a collection - #2135 - Prevent
InvalidOperationException
when formatting a lambda expression calling a constructor - #2176
6.10.0
Fixes
- Fixed hanging of
CompleteWithinAsync
when used withWithResult
andAssertionScope
- #2101 BeEquivalentTo
no longer crashes on fields hiding base-class fields - #1990- Fixed System.Net.Http dependency declaration for net47 target framework to be a framework dependency instead of a nuget dependency - #2122
6.9.0
What’s new
- Added
ThatAre[Not]ValueTypes
method for filtering the types - #2083 - Added
Imply
method toBooleanAssertions
- #2074 - Added
ThatAre[Not]Interfaces
method for filtering the types - #2057 - Added
ThatAre[Not]Abstract
method for filtering the types - #2058 - Added
ThatAre[Not]Sealed
method for filtering the types - #2059 - Added
ThatAre[Not]Abstract
methods toMethodInfoSelector.cs
for filtering the methods - #2060 - Added
ThatAre[Not]Abstract
,ThatAre[Not]Static
andThatAre[Not]Virtual
properties for filtering inPropertyInfoSelector.cs
- #2054 - Added
BeOneOf
methods for object comparisons andIComparable
s - #2028 - Added
BeCloseTo
andNotBeCloseTo
toTimeOnly
- #2030 - Added new extension methods to be able to write
Exactly.Times(n)
,AtLeast.Times(n)
andAtMost.Times(n)
in a more fluent way - #2047 - Changed
BeEquivalentTo
to treat record structs like records, thus comparing them by member by default - #2009
Fixes
PropertyInfoSelector.ThatArePublicOrInternal
now takes the setter into account when determining if a property ispublic
orinternal
- #2082- Querying properties on classes, e.g.
typeof(MyClass).Properties()
, now also includes static properties - #2054 - Nested AssertionScopes now print the inner scope reportables - #2044
- Throw
ArgumentException
instead ofArgumentNullException
when a requiredstring
argument is empty - #2023 - Assertions on the ordering of a collection of
string
s now uses ordinal comparison when anIComparer<T>
is not provided - #2075
6.8.0
What’s new
- Added
ContainInConsecutiveOrder
andNotContainInConsecutiveOrder
assertions to check if a collection contains items in a specific order and to be consecutive - #1963 - Added
NotCompleteWithinAsync
for assertions onTask
- #1967 - Added
CompleteWithinAsync
andNotCompleteWithinAsync
for non-genericTaskCompletionSource
(.NET 6 and above) - #1961 - Added a
ParentType
toIObjectInfo
to help determining the parent in a call toUsing
/When
constructs - #1950 - Added a
Monitor
toEventAssertions
to enable writing extension methods for event assertions. - #2008
Improvements
- Updated exception messages to provide suggestions when incorrectly using
Equals()
- #2006 - Included the time difference in the error message of
BeCloseTo
- #2013
Fixes
- Fixed
For
/Exclude
not excluding properties in objects in a collection - #1953 - Changed
MatchEquivalentOf
to useCultureInfo.InvariantCulture
instead ofCultureInfo.CurrentCulture
- #1985. - Fixed
BeEquivalentTo
not taking into account anyrecord
equivalency settings coming from theAssertionOptions
- #1984 - Fixed
ExecutionTimeOf
formatting failing when the expression includes {} - #1994
6.7.0
What’s new
- Added
BeDefined
andNotBeDefined
to assert on existence of an enum value - #1888 - Added the ability to exclude fields & properties marked as non-browsable in the code editor from structural equality comparisons - #1807 & #1812
- Assertions on the collection types in System.Data (
DataSet.Tables
,DataTable.Columns
,DataTable.Rows
) have been restored - #1812 - Added
For
/Exclude
to allow exclusion of members inside a collection - #1782 - Added overload for
HaveElement
forXDocument
andXElement
to assert on number of XML nodes - #1880
Fixes
- Fixed the failure message for regex matches (occurrence overload) to include the missing subject - #1913
- Fixed
WithArgs
matching too many events when at least one argument matched the expected type - #1920
6.6.0
What’s New
- Annotated
[Not]MatchRegex(string)
with[StringSyntax("Regex")]
which IDEs can use to colorize the regular expression argument - #1816 - Added support for .NET6
DateOnly
struct - #1844 - Added support for .NET6
TimeOnly
struct - #1848 - Added
NotBe
for nullable boolean values - #1865 - Added a new overload to
MatchRegex()
to assert on the number of regex matches - #1869 - Added difference to numeric assertion failure messages - #1859
Fixes
EnumAssertions.Be
did not determine the caller name - #1835- Ensure
ExcludingMissingMembers
doesn’t undo usage ofWithMapping
inBeEquivalentTo
- #1838 - Better handling of NaN in various numeric assertions - #1822 & #1867
WithMapping
inBeEquivalentTo
now also works when the root is a collection - #1858
6.5.1
Fixes
- Fixed regression introduced in 6.5.0 where
collection.Should().BeInAscendingOrder(x => x)
would fail - #1802
6.5.0
What’s New
- Added
AllSatisfy
for asserting all items in a collection satisfy an inspector - #1790 - Added
WithMapping
option toBeEquivalentTo
to map members with different names between the subject and expectation - #1742
Fixes
- Improved the documentation on
BeLowerCased
andBeUpperCased
for strings with non-alphabetic characters - #1792 - Caller identification does not handle all arguments using
new
- #1794 - Resolved an issue preventing
HaveAccessModifier
from correctly recognizing internal interfaces and enums - #1793 - Improved tracing for nested
AssertionScope
s - #1797
Fixes (Extensibility)
- Fixed a continuation issue when using
ClearExpectation
- #1791
6.4.0
What’s New
- Added
ThatAreStatic()
andThatAreNotStatic()
for filtering in method assertions - #1740 - Added new assertions for the
HttpStatusCode
of anHttpResponseMessage
- #1737 - Added non-generic overloads for
WithInnerExceptionExactly
andWithInnerException
- #1769
Fixes
ContainItemsAssignableTo
now expects at least one item assignable toT
- #1765- Querying methods on classes, e.g.
typeof(MyController).Methods()
, now also includes static methods - #1740 - Variable name is not captured after await assertion - #1770
OccurredEvent
ordering on monitored object is now done via thread-safe counter - #1773- Avoid a
NullReferenceException
when testing an application compiled with .NET Native - #1776 [Not]Contain(key, value)
for dictionary-like enumerables incorrectly checked if the key was present - #1786- Avoid throwing a
FormatException
when caller name determination returns an unformattable string - #1788
6.3.0
What’s New
- Added
ThatAreAsync()
andThatAreNotAsync()
for filtering in method assertions - #1725 - Added
ThatAreVirtual()
andThatAreNotVirtual()
for filtering in method assertions - #1744 - Added collection content to assertion messages for
HaveCountGreaterThan()
,HaveCountGreaterThanOrEqualTo()
,HaveCountLessThan()
andHaveCountLessThanOrEqualTo()
- #1760
Fixes
- Prevent multiple enumeration of
IEnumerable
s in parameter-lessContainSingle()
- #1753 - Changed
HaveCount()
assertion message order to state expected and actual collection count before dumping its content` - #1760 CompleteWithinAsync
did not take initial sync computation into account when measuring execution time - 1762.
6.2.0
What’s New
- Added new overloads to all
GreaterOrEqualTo
andLessOrEqualTo
assertions, adding the wordThan
- #1673 BeAsync()
andNotBeAsync()
are now also available onMethodInfoSelectorAssertions
- #1700
Fixes
- Prevent exceptions when asserting on
ImmutableArray<T>
- #1668 At
now retains theDateTimeKind
and keeps sub-second precision when using aTimeSpan
- #1687.- Removed iteration over enumerable when generating the
BeEmpty
assertion failure message - #1692. - Prevent
ArgumentNullException
when formatting a lambda expression containing an extension method - #1696 IgnoringCyclicReferences
inBeEquivalentTo
now works while comparing value types usingComparingByMembers
- #1708- Using
BeEquivalentTo
on a collection with nested collections would complain about missing members - #1713 - Formatting a lambda expression containing lifted operators - #1714.
- Performance improvements in
BeEquivalentTo
by caching expensive Reflection operations - #1719
6.1.0
What’s New
- Prevent asserting directly on
AndConstraint
- #1649 - Added
WithInnerExceptionExactly
extension method onTask<ExceptionAssertions<T>>
for easier use withThrowAsync
- #1658
Fixes
- Resolved a significant performance degradation in
BeEquivalentTo
- #1660
6.0.0
What’s New
- Added official support for .NET Core 3.0 - #1227.
- Added
WithOffset
extension method onDateTime
for easier creation ofDateTimeOffset
objects - #1235. - Added
collectionOfStrings.Should().NotContainMatch()
to assert that the collection does not contain a string that matches a wildcard pattern - #1246. - The
Using
/When
option onBeEquivalentTo
will now use the conversion rules when trying to match the predicate - #1257. - Added
NotBeWritable
toPropertyInfoSelectorAssertions
to be able to assert that properties are not writable - #1269. - Added extension to assert
TaskCompletionSource<T>
- #1267. - Added the ability to pass an
IEqualityComparer<T>
throughBeEquivalentTo(x => x.Using<MyComparer>())
- #1284. - Added
NotBe
toBooleanAssertions
to be able to assert that a boolean is not the expected value - #1290. - Make
DefaultValueFormatter
andEnumerableValueFormatter
suitable for inheritance - #1295. - Added support for dictionary assertions on
IReadOnlyDictionary<TKey, TValue>
- #1298. GenericAsyncFunctionAssertions
now hasAndWhichConstraint
overloads forNotThrow[Async]
andNotThrowAfter[Async]
- #1289.- Added
ReturnTypes
toMethodInfoSelector
to get all return types from all the methods selected - Added
[Not]Be
toMethodInfoSelector
to check that methods [don’t] have specified access modifier - Added
ThatAre[Not]Classes
,ThatAre[Not]Static
selectors toTypeSelector
- Added
ThatSatisfy
toTypeSelector
to filter types with specified predicate - Added
UnwrapEnumerableTypes
toTypeSelector
to get theT
type from types implementingIEnumerable<T>
- Added
UnwrapTaskTypes
toTypeSelector
to get theT
type for any type that areTask<T>
orValueTask<T>
- Added
[Not]BeSealed
toTypeSelectorAssertions
- Added
collection.Should().NotContainEquivalentOf
to use object graph comparison rules to assert absence of an element in the collection - #1318. - Added
[Not]BeInNamespace
and[NotBeUnderNamespace]
toTypeSelectorAssertions
- #1329. - The
Using
option onBeEquivalentTo
and onAssertionOptions.AssertEquivalencyUsing
now supports customIOrderingRule
implementations #1337. - Added
AllBe
toStringCollectionAssertions
to be able to assert that all strings in collection are equal to the specified string - #1332. - Added
ForConstraint
method toAssertionScope
to open upOccurenceConstraint
for usage in custom assertion extensions - #1341. - Added
NotContainInOrder
toCollectionAssertions
andStringCollectionAssertions
to be able to assert that the collection does not contain the specified elements in the exact same order, not necessarily consecutive - #1339. - Added async version of
Where
extension method toExceptionAssertions
to be able to check asynchronously thrown exception - #1352. - Added
[Not]BeUpperCased
and[Not]BeLowerCased
toStringAssertions
to be able to assert that a string is in upper or lower casing or not - #1357. - Added
ObjectAssertions<TSubject, TAssertions>
to ease creation of custom assertion classes - #1371. - Added
ComparingBy{Members,Value}(Type)
to allow specifying open generic types - #1389. - Added overload of
CollectionAssertions.NotBeEquivalentTo
that takes aconfig
parameter` - #1408. - Changed
StringAssertions.StartWith
,StringAssertions.EndWith
and theirEquivalentOf
versions to allow empty strings - #1413. - The equivalency assertions will now include the type of the member and whether it involves a field or property - #1379
- Changed AttributeBasedFormatter to allow custom formatter selection based on the parent type - #1418.
- Added nullable overload for
Be
andNotBe
methods ofDateTimeAssertions
andDateTimeOffsetAssertions
- #1427. - Added overload of
Enumerating
extension method to be able to force the enumeration of an object member -#1433 - Add overloads of
MatchRegex
andNotMatchRegex
that takeSystem.Text.RegularExpressions.Regex
-#1436 - Added support for equivalency tests on System.Data types (
DataSet
,DataTable
,DataColumn
,DataRow
,DataRelation
,Constraint
) - #1419. - Added
WithParameterName
extension to ease asserting on the parameter name for a thrownArgumentException
- #1466. - Added
BeExactly
assertions to verify aDateTimeOffset
exactly, i.e both its date/time and its offset - #1609. - Added
NotCompleteWithinAsync
toTaskCompletionSourceAssertions
- #1474. - Added
HaveValue(decimal)
,HaveSameValueAs
andHaveSameNameAs
toEnumAssertions
- #1479. - Added
WithResult
extension method toCompleteWithinAsync
assertions forTask<T>
andTaskCompletionSource<T>
- #1478. - Added
Satisfy
to be able to compare a collection with a set of predicates in any order - #1500. - Added milliseconds formatting for error messages including
TimeSpan
- #1504. - Added
AddReportable
overload toAssertionScope
for deferring reportable value calculation only on a test failure - #1515. - Added the possibility to set the maximum depth and other formatting settings either globally or per
AssertionScope
- #1469. - Added
BeInAscendingOrder
andBeInDescendingOrder
for collections taking a lambda expression - #1526 - Added
[Not]BeWritable
,[Not]BeSeekable
,[Not]BeReadable
,[Not]BeReadOnly
,[Not]BeWriteOnly
,[Not]HaveLength
,[Not]HavePosition
for Stream and[Not]HaveBufferSize
for BufferedStream - #1543 - Added native support for
XDocument
,XElement
andXAttribute
properties and fields toBeEquivalentTo
- #1572 - The equivalency failure message will include information on how tuples, anonymous types, records and other types are compared - #1571
- Improved formatting a dictionary when key or value is a complex type - #1577.
- Added
NotBe(string)
for symmetry withBe(string)
for GuidAssertions - #1597. - Added
BeOneOf
for enum assertions - #1637 - Homogenized assertion message formatting of predicate expressions - #1619.
Fixes
- Reported actual value when it contained
{{{{
or}}}}
- #1234. - Changed dictionary assertion
NotContainKeys
to honour the key comparer if applicable - #1233. - Ensures that date time assertions like “a is less than an hour after b” don’t succeed when
a - b == -30.Minutes()
#1313. - Event raising assertions like
WithSender
andWithArgs
will only return the events that match the constraints - #1321 - Fixed an
InvalidCastException
thatBeEquivalentTo
could throw while debugging - #1325 - Ensured that
Given
will no longer evaluate its predicate if the precedingFailWith
raised an assertion failure - #1325 - Improved the message that
RaisePropertyChangeFor
throws when the wrong property was detected - #1333 - Guard against negative precision arguments for
BeCloseTo
andBeApproximately
- #1386 - Guard against implicitly or explicitly trying to compare primitive types by members - #1394.
- Fixed formatting of brackets in expressions passed to ContainSingle(…) - #1406.
- Fixed
Contain
,NotContain
andOnlyContain
to avoid multiple enumerations when the condition is false - #1421. - Added variable name and other useful and consistent information to XML assertions - #1440.
- Sometimes
BeEquivalentTo
reported an incorrect message when a dictionary was missing a key - #1454 - Some dictionary failures did not honor the user-provided reason - #1456
- Restrict what types
WhenTypeIs<T>
can use and howUsing<T>
handles non-nullable types, see the Migration Guide for more details - #1494. HaveElement
did not ignore the xml namespace - #1541- Better parameter checking of
TypeAssertions
- #1550 [Not]HaveExplicitMethod
did not mention the parameters in the failure message - #1550- Better parameter checking of
PropertyInfoAssertions
- #1558 - Better parameter checking of
MethodBaseAssertions
andMethodInfoAssertions
- #1559 - Better parameter checking of
AssemblyAssertions
- #1561 - Better parameter checking of
PropertyInfoSelectorAssertions
- #1565 - Better parameter checking of
MethodInfoSelectorAssertions
- #1569 - Better parameter checking of
XDocumentAssertions
,XElementAssertions
andXAttributeAssertions
- #1564 - In a chained assertion API call, a second call to
ForCondition
should not even evaluate its lambda when the previous assertion failed - #1587 - Added parameter checking for
Be(string)
for GuidAssertions - #1597. - Improved consistency of XML documentation on
AssertionScope
,ContinuedAssertionScope
, andGivenSelector<T>
methods. - #1606. - Handle
WithDefaultIdentifier
andWithExpectation
correctly when anAssertionScope
continues - #1610. - Improved stack trace when a property of an element of a generic collection throws an exception during
GenericEnumerableEquivalencyStep
inGenericCollectionAssertions
- #1615. - Removed the type info from the failure message in equivalency checks - #1621.
- Fixed a regression so that collections of similarly typed key-value pairs should be equivalent to a dictionary - #1603.
- Fixed a regression where a nested class without suitable members inside a collection raised an exception - #1627.
- Fixed support for covariant and inherited property exclusion and inclusion in
BeEquivalentTo
- #1631. - Reintroduced
Match
for enum assertions - #1637 - Improved caller name determination by supporting multiple lines, comments and semicolons - #1435.
Breaking Changes
- Dropped support for .NET Framework 4.5, .NET Standard 1.3 and 1.6 - #1227.
- Dropped support for older test frameworks such as MSTest v1, NSpec v1 and v2, XUnit v1, Gallio and MBUnit - #1227.
- Removed
[Not]Have{Im,Ex}plictConversionOperator
(they had typos) - #1221.- Use the equivalent assertions without the typo “plict” instead.
- Removed
NotBeAscendingInOrder
/NotBeDescendingInOrder
- #1221.- Use
NotBeInAscendingOrder
/NotBeInDescendingOrder
instead.
- Use
- Removed
HasAttribute
,HasMatchingAttribute
andIsDecoratedWith(Type, bool)
Type
extensions - #1221.- Use
IsDecoratedWith
/IsDecoratedWithOrInherits
instead.
- Use
- Made
EquivalencyAssertionOptionsExtentions
internal
(and fixed a typo in the type name) - #1221. - Changed
ReferenceTypeAssertions.Subject
to bereadonly
- #1229.- Set the
Subject
through the constructor instead.
- Set the
- Changed
TypeAssertions.HaveAccessModifier
return type fromAndConstraint<Type>
toAndConstraint<TypeAssertions>
- #1159. - Changed
TypeAssertions.NotHaveAccessModifier
return type fromAndConstraint<Type>
toAndConstraint<TypeAssertions>
- #1159. - Changed
AllBeAssignableTo<T>
andAllBeOfType<T>
return type fromAndConstraint<TAssertions>
toAndWhichConstraint<TAssertions, IEnumerable<T>>
- #1265. - The new extension on
TaskCompletionSource<T>
overlays the previously used assertions based onObjectAssertions
. - Removed
[Not]BeCloseTo
forDateTime[Offset]
andTimeSpan
that took anint precision
- #1278.- Use the overloads that take a
TimeSpan precision
instead.
- Use the overloads that take a
- Aligned strings to be compared using
Ordinal[Ignorecase]
- #1283. - Changed
AutoConversion
to convert usingCultureInfo.InvariantCulture
instead ofCultureInfo.CurrentCulture
- #1283. - Renamed
StartWithEquivalent
andEndWithEquivalent
toStartWithEquivalentOf
andEndWithEquivalentOf
to make the API for Equivalent methods consistent - #1292. - Several event raising assertion APIs will return an
IEventRecording
instead ofIEventRecorder
- #1321 - The classes
EventMonitor
andRecordedEvent
are now treated asinternal
code - #1321 - Renamed method
GetEventRecorder
of interfaceIMonitor
toGetRecordingFor
and will returnIEventRecording
- #1321 - Removed synchronous assertions on asynchronous operations (
Throw
,NotThrow
,CompleteWithin
, …) #1324 - Do not modify
SynchronizationContext.Current
while asserting asynchronous operations. In case hitting deadlocks in your tests please check whether you mix synchronous and asynchronous operations. #1324 - Moved
[Not]HaveFlag
fromObjectAssertions
toEnumAssertions
- #1375. - Requesting an unsupported test framework via
Services.Configuration.TestFrameworkName
or"FluentAssertions.TestFramework"
now throws an exception instead of using the fallback - #1366. - Guard
[Not]Match
,[Not]MatchEquivalentOf
,[Not]MatchRegex
and[Not]ContainMatch
againstnull
or empty patterns - #1401. - Renamed
WhichValue
toWhoseValue
- #1581 - By default, records are now compared by their members. Can be overridden using
ComparingRecordsByValue
- #1571 - Changed
becauseArgs
of[Not]Reference(Assembly)
fromstring[]
toobject[]
- #1459 - Major overhaul on how enums are handled, see the Migration Guide for more details - #1479.
- Removed support for non-generic collections, see the Migration Guide for more details - #1529.
- Removed
[Not]Contain(IEnumerable<T>, params T[])
- #1529. - Removed
BeEquivalentTo(params object[])
- #1529. - Renamed
EquivalencyStepCollection
toEquivalencyPlan
andAssertionOptions.EquivalencyCollection
toEquivalencyPlan
- #1539. BeEquivalentTo
will no longer includeinternal
properties and fields, unlessIncludingInternalProperties
orIncludingInternalFields
is used - #1575.- Renamed
protected
methods onDelegateAssertionsBase
such asThrow
andNotThrow
to avoid confusion - #1642 - Moved the properties of
IMemberInfo.SelectedMemberInfo
toIMemberInfo
. RenamedIMemberInfo.SelectedMemberPath
toPath
and replacedSelectedMemberDescription
by a combination ofPath
andName
- #1379 - Changed
[Not]Be
on anIComparable<T>
to useEquals(object)
instead ofCompareTo(T)
and added[Not]BeRankedEquallyTo
to useCompareTo(T)
- #1177.
Breaking Changes (Extensibility)
- Removed parameterless constructors from:
CollectionAssertions
,ReferenceTypeAssertions
,MemberInfoAssertions
,MethodBaseAssertions
andMethodInfoAssertions
- #1229.- Use the constructors taking a
subject
instead.
- Use the constructors taking a
- Restrict generic constraints on
[Nullable]NumericAssertions<T>
toIComparable<T>
- #1266. - Changed return type of
[Nullable]NumericAssertions.Subject
fromIComparable
toT?
andT
, respectively - #1266. - Removed
Succeeded
andSourceSucceeded
fromContinuation
andIAssertionScope
- #1325 - Made the extension methods under the
FluentAssertions.Common
namespaceinternal
- #1376 - The
IEquivalencyValidationContext
has undergone significant refactorings where its properties have been moved into theINode
hierarchy and the twoReason
andTracer
classes - #1379 - The
IMemberMatchingRule
,IMemberSelectionRule
andIOrderingRule
have been changed to replace their dependency onSelectedMemberInfo
toINode
and its derivativesIMember
- #1379 - The
SelectedMemberInfo
class has been removed, since it main user,IMemberInfo
has been flattened - #1379 - Several methods that took an
IMemberInfo
, but could also act on other objects than a property or field now take anIObjectInfo
- #1379 - Pascal cased
CallerIdentifier.logger
- #1458. - Pascal cased
SelfReferenceEquivalencyAssertionOptions.orderingRules
- #1458. - Moved extension methods on
ExceptionAssertions
fromAssertionExtensions
toExceptionAssertionsExtensions
- #1471. - Moved
Including(Expression<Func<IMemberInfo, bool>> predicate)
fromEquivalencyAssertionOptions<T>
toSelfReferenceEquivalencyAssertionOptions<T>
- #1495. Formatter.ToString()
andIValueFormatter
now work with aFormattingOptions
object that wraps theUseLineBreaks
option - #1469.- Split-up the subject and expectation from
IEquivalencyValidationContext
into a new typeComparands
. This affectedIEquivalencyStep
- #1539. - Moved the responsibility of
IEquivalencyStep.CanHandle
intoHandle
and replacedHandle
’s return value with a more clearerEquivalencyResult
- #1539 - Simplified
MemberSelectionContext
which is used byIMemberSelectionRule
to remove the need for extensions to understand the difference between run-time and compile-time types - #1539. - The implementations of
IEquivalencyStep
have moved to theFluentAssertions.Equivalency.Steps
namespace - #1588.
5.10.3
Fixes
- Fixed XPath index calculation in XML comparison when child node names are repeated in repeated parent nodes - #1273
5.10.2
Fixes
- Added missing dependency on System.Xml - #79
5.10.1
This version was skipped.
5.10.0
What’s New
- Added
string.Should().NotBeEquivalentTo
- #1134 - Added
collectionOfStrings.Should().ContainMatch()
to assert that the collection contains at least one string that matches a wildcard pattern - #1138 - Added overloads of
NotBeInAscendingOrder
andNotBeInDescendingOrder
that take a property expression - #1140 - Include the index in the XPath information reported while comparing
XDocument
s for equivalence - #1181 - Added
NotHaveSameCount
andHaveSameCount
for dictionary assertions - #1178 - Extended
string.Should().Contain()
andstring.Should().ContainEquivalentOf()
to test the number of times a phrase exists in a string usingtheString.Should().Contain("is a", MoreThan.Thrice())
- #1145 - Added support for methods returning
ValueTask
andValueTask<T>
- #1158 - Added support for using
SatisfyRespectively
on all collections, including collections ofstring
- #1201
Fixes
- Updated the docs to clarify that
CompleteWithin
works onFunc<Task>
and not onTask
directly - #1127. - Renamed collection assertion
NotBeAscendingInOrder
andNotBeDescendingInOrder
toNotBeInAscendingOrder
andNotBeInDescendingOrder
(in a non-breaking way) - #1140 - Collections containing
null
s where not properly treated as equivalent byBeEquivalentTo
- #1143 BeEquivalentTo
now allows selecting an explicit interface member over a regular instance member when usingRespectingDeclaredTypes
and the expectation type is an interface - #1144- Fixed a crash that can occur when trying to determine the caller identity under .NET Native - #1149
- Ensured that determining the caller identity works for namespaces that contain the phrase
System
and don’t match on partial namespace segments - #1193 BeEquivalentTo
on anXDocument
could report the incorrect path to a self-closing XML tag - #1170BeEquivalentTo
on multi-dimensional arrays with empty elements could cause an internal error - #1167- Several assertion APIs did not include the reason in the failure messages - #1172
- A self-closing XML element was not treated as equivalent to an empty element with the same name - #1174
- Ensure that type assertion
ThatAreUnderNamespace
handles types in the global namespaces correctly - #1197 - When comparing whether two objects are equal, a conversion should be precision preserving - #1202
BeEquivalentTo
on normalTuple
s should use structural equivalency instead of treating them as value types - #1206- Some platforms throw reflection exceptions when trying to use
ConfigurationManager
. This is now handled more gracefully - #1210 - Reintroduced the package dependency on
System.Xml.Linq
for .NET 4.5/4.7 - #79 - Treat enums and their numeric representations in structural object graph comparisons the same - #1208
Thanks to contributors Ronald Kroon, Daniel Petrov, @david-a-jetter, Lukas Grützmacher and Ben Randall.
And special thanks to Matthias Koch to switch us over to the awesome Nuke build system.
5.9.0
What’s New
- Added
Match
method to (nullable) numeric assertions - #1112
Fixes
- Using a custom
IAssertionStrategy
with anAssertionScope
did not always capture all assertion failures - #1118 - Ensured
null
arguments are handled with clearer exception messages - #1117
Special thanks to contributors @liklainy and Amaury Levé.
5.8.0
What’s New
- Added thread-safety to tests using
AssertionScope
while running manyasync
tests concurrently - #1091 - Allow users to specify a custom
IAssertionStrategy
for the assertion scope, for instance, to create screenshots when a test fails - #1094 & #906. - Supports .NET Core 3.0 Preview 7 - #1107
Fixes
Excluding
withBeEquivalentTo
did not always work well with overridden properties - #1087 & #1077- Failure message formatting threw a
FormatException
when a nested message contains braces - #1092 - Fixed confusing
(Not)BeAssignableTo
failure messages - #1104 & #1103 - Fixed a potential leakage of failure messages between multiple assertions - #1105
Kudos to conklinb and Amaury Levé for notable contributions and my partner-in-crime Jonas Nyrup for some of the fixes, a lot of (internal) quality improvements and his critical eye.
5.7.0
What’s New
- Added official support for .NET Core 3 (Preview 5 or later) - #1057
- Introduced
SatisfyRespectively
on collections - #1043 - Added an alternative fluent syntax for evaluating/invoking actions - #1017
- Added overloads of
Invoking
andAwaiting
for different sets of generic parameters - #1051 NotThrowAfter
is now also available for .NET Standard 1.3 and 1.6 - #1050- Added
CompleteWithin
to assert asynchronous operations complete within a time span - #1013/#1048 - Added
NotBeEquivalent
for objects - #1071 - Added
WithMessage()
forasync
exception assertions - #1052 - Added extension methods like
100.Nanosecond()
and20.Microsecond()
to represent time spans - #1069
Fixes
AllBeAssignableTo
andAllBeOfType
did not work for list of types - #1007- Backslashes in subject or expected result were not correctly shown in the message - #986
BeOfType
does not attach to theAssertionScope
correctly - #1002- Event monitoring did not detect events on interfaces - #821
- Fix continuation on
NotThrow(After)
in chainedAssertionScope
invocations - #1031 - Allow nesting equivalency checks in custom assertion rules when using
BeEquivalentTo
- #1033 - Removed redundant use of the thread pool in async assertions - #1020
- Improved formatting of multidimensional arrays - #1044
- Better handling of exceptions wrapped in
AggregateException
s - #1041 - Fix
BadImageFormatException
under the .NET Core 3.0 Preview - #1057 ThrowExactly
andThrowExactlyAsync
now support expecting anAggregateException
- #1046
Kudos to Lukas Grützmacher, Matthias Lischka, Christoffer Lette, Ed Ball, David Omid, mu88, Dmitriy Maksimov and Ivan Shimko for the contributions and Jonas Nyrup to make this release possible again.
5.6.0
Fixes
- Provide opt-out to
AssertionOptions(o => o.WithStrictOrdering())
-#974 - Add collection assertion
ContainEquivalentOf
- #950 - Add
Should().NotThrowAfter
assertion for actions - #942
Kudos to @BrunoJuchli, @matthiaslischka and @frederik-h for these amazing additions.
5.5.3
Fixes
- Performance fixes in
BeEquivalenTo
- #935 - Reverted 5.5.0 changes to
AssertionScope
to ensure binary compatibility - #977
5.5.2
Fixes
- Allows
BeEquivalentTo
to handle a non-generic collection as the SUT - #975, #973 - Optimized performance of
IncludeMemberByPathSelectionRule
- #969
5.5.1
What’s New
- Now provides a hint when strings differ in length and contain differences - #915, #907
- Added
ThrowAsync
,ThrowExactlyAsync
andNotThrowAsync
- #931 - Added support for
Should().Throw
andShould().NotThrow
forFunc<T>
- #951 - Added support for
private protected
access modifier - #932 - Updated
BeApproximately
to support nullable types for both the subject and the expectation nullable - #934 - Added
async
version ofExecutionTime
to - #938 - Updated
NotBeApproximately
to accepting nullable subject and expectation - #939 type.Should().Be(type)
now support open generics - #954, #955
Fixes
- Minor performance improvements to prevent rendering messages if a test did not fail - #921, #915
- Improve performance of
Should().AllBeEquivalentTo()
- #920, #914 - Improve the presentation of enums to include the value and the number - #923, #897
BeEquivalentTo
withWithStrictOrdering
produced messy failure message - #918- Fixes detecting checking equivalency of a
null
subject to a dictionary - #933 - Fixes duplicate conversions being mentioned in the output of the equivalency API - #941
- Comparing an object graph against
IEnumerable
now works now as expected - #911 - Selecting members during object graph assertions now better handles
new
overrides - #960, #956
Note In versions prior to 5.5, FA may have skipped certain properties in the equivalency comparison. #960 fixes this, so this may cause some breaking changes.
Lots of kudos @jnyrup and @krajek for a majority for the work in this release.