Fluent Assertions just a got a little bit better
Just a quick post to let you all know that I’ve just published a new version of Fluent Assertions with a load of little improvements that will improve your life as a unit test developer a little bit.
New features
- Added
CompareEnumsAsStringandCompareEnumsAsValueto the options taken byShouldBeEquivalentToso specify how enumerations are compared. - Added
ShouldThrowExactlyandWithInnerExceptionExactlyto assert a specific exception was thrown rather than the default of allowing sub-classes of those exceptions. #176 - Introduced a new static
AssertionOptionsclass that can be used to change the defaults used byShouldBeEquivalentTo, alter the global collection ofIEquivalencySteps that are used internally, and change the rules that are used to identify value types. #134 ShouldBeEquivalentTowill now also include public fields. Obviously, this can be changed using a set of new members on theEquivalencyAssertionOptions<T>class that the equivalency API takes.- Extended the collection assertions with
StartWith,EndWith,HaveElementPrecedingandHaveElementSucceeding. - Added methods
ThatAreDecoratedWith,ThatAreInNamespace,ThatAreUnderNamespace,ThatDeriveFromandThatImplementto filter types from assemblies that need to comply to certain prerequisites. - Added
BeAssignableTothat directly apply toTypeobjects.
Minor improvements and fixes
- Extended the time-conversion convenience methods with
4.Ticks() - When an object implements
IDictionary<T,K>more than once,ShouldBeEquivalentTowill fail rather than pick a random implementation. Likewise, if a dictionary only implementsIDictionary<,>explicitly, it will still be treated as a dictionary. Finally,ShouldBeEquivalentTowill now respect the declared type of a generic dictionary. - A null reference in a nested collection wasn't properly detected by
ShouldBeEquivalentTo. - Corrected the remaining cases where
ShouldBeEquivalentTodid not respect the declared type. #161 - Adding an overload to
collection.ContainSingle()having no arguments. - Included the time zone offset when displaying a
DateTimeOffset. #160 collection.Should().BeEmpty()now properly reports the collection items it found unexpectedly. #224- Made the fallback
AssertFailedExceptionserializable to help in certain cross-AppDomainunit tests. #214 - Better support for rendering the
TimeSpan'sMinValueandMaxValuewithout causign stack overflow exceptions. #212 - Fixed an issue where the Windows 8.1 test framework detection code would ran into a deadlock when using a
[UITestMethod]. #223 - Fixed an issue where
ShouldBeEquivalentTowould throw an internal exception on a unsetbyte[]property. #165
Internal changes
- We now use StyleCop to improve the quality level of the code.
- The first steps have been taken to deprecate
IAssertionRule. - The internal assertion API has been changed to allow chaining complex assertions using a fluent API. This should make it a lot easier to extend Fluent Assertions. You can read more about that in this blog post
- We've started to use Chill to improve the readability of the more behavioral unit tests.
As usual, you can get the bits from NuGet or through the main landing page. Tweet me at @ddoomen for questions or post them on StackOverflow. If you find any issues, post them to the GitHub repository.
Fluent Assertions
Leave a Comment