A new year with a new release of Fluent Assertions

Edit this page | 2 minute read

Christmas usually means a week off and a whole lot of free time between the social obligations and spending some quality time with my wife and daughter. That’s why I decided to get rid of some of the backlog items for the next version of Fluent Assertions. And I’m done, version 1.3.0 is a fact.

New Features
  • Introduced a new set of extension methods for asserting that events were raised with the appropriate data. With his permission, I borrowed, adapted and integrated the code from Mendelt Siebenga’s original EMo project. I’ll write up a separate post on how to use this in Silverlight testing.
  • BeOfType<T>() and BeAssignableTo<T>() are available for all reference types. Before this, they were only available on the ObjectAssertions class.
  • Added an OnlyContain() method to the collection assertions that takes a lambda expression and ensures that the collection only contains items matching the predicate.
  • Added an overload of Contain() to the collection assertions that takes both an IEnumerable<T> and a params array. I regularly ran into the situation that I wanted to check if a particular new item was added to a collection. With this overload, you no longer need to create a temporary list that contains both the original collection and the newly added items.
  • Added support for ShouldHave().SharedProperties().EqualTo(otherObject). This saved me a lot of work when asserting that some DTO-entity conversion was implemented correctly. Before I had to exclude all the properties that I didn’t want to include in the DTO, or swap the calling order, neither improving the readability. But since you still may end up wanting to exclude a particular property, I also added an additional But(x => x.Property) method that can be combined with AllProperties() and SharedProperties().

Breaking Changes
  • Changed the way test framework assemblies are found so that they are not relying on specific versions anymore. In fact, I introduced separate versions for .NET 3.5 and .NET 4.0 that both support all test frameworks. They will automatically find the test framework assembly, but you can force it using an <appSetting>.
  • Switched to Silverlight 4 for the Silverlight version of Fluent Assertions.
  • Renamed the Assertions base-class to ReferenceTypeAssertions because it better explains its purpose.
  • BeOfType<T>() was not properly checking that the subject was of the exact same type rather than a subclass. I fixed this, but it may break existing unit tests.

  • Signed all assemblies with a strong name.
  • Added some missing XML comments.
  • Improved the extensibility by exposing the subject-under-test via a public Subject property and making all contructors protected.
  • If the exception message is shorter than the expected one specified using WithMessage(), but starts with the same text, it was not detected as a difference.
  • Fixed a NullReferenceException when calling ObjectAssertions().Be() on a null object.
  • As<T>() uses a type safe-cast now so that you can do stuff like someObject.As<SomeType>().ShouldNotBeNull();
  • Fixed a bug that caused the property comparison assertions to ignore internal or base-class properties.
I’ve also updated the documentation to include these changes and completed it with some missing information on the property comparison features that I introduced in version 1.2.0.

Leave a Comment