<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>fluentassertions Wiki Rss Feed</title><link>http://fluentassertions.codeplex.com/wikipage</link><description>fluentassertions Wiki Rss Description</description><item><title>New Comment on "Documentation"</title><link>https://fluentassertions.codeplex.com/documentation?&amp;ANCHOR#C27482</link><description>I have a couple of questions on the section &amp;#34;Object Graph Comparison --&amp;#62; Overriding and collections&amp;#34;&amp;#10;&amp;#10;orderDto.ShouldBeEquivalentTo&amp;#40;order, options &amp;#61;&amp;#62; options &amp;#10;    .Using&amp;#60;DateTime&amp;#62;&amp;#40;ctx &amp;#61;&amp;#62; ctx.Date.Should&amp;#40;&amp;#41;.BeCloseTo&amp;#40;ctx.Date, 1000&amp;#41;&amp;#41; &amp;#10;    .WhenTypeIs&amp;#60;DateTime&amp;#62;&amp;#40;&amp;#41;&amp;#59;&amp;#10;&amp;#10;1&amp;#41; ctx.Date should actually read ctx.Subject, right&amp;#63;&amp;#10;&amp;#10;2&amp;#41; If yes, this is not working for me. The validation seems to always succeed even though the corresponding DateTime properties differ greatly. I can provide a sample code if you let me know where. Or if I&amp;#39;m using the feature wrong, I&amp;#39;d appreciate any guidance. I&amp;#39;m using the line above just as it is on this page, except that I&amp;#39;m using my own variable names of course, and that I&amp;#39;m using ctx.Subject instead of ctx.Date</description><author>laulowen</author><pubDate>Tue, 14 May 2013 15:28:50 GMT</pubDate><guid isPermaLink="false">New Comment on "Documentation" 20130514032850P</guid></item><item><title>New Comment on "Documentation"</title><link>https://fluentassertions.codeplex.com/documentation?&amp;ANCHOR#C27294</link><description>I love this to be on a single page. I hate that MS&amp;#39;s .Net documentation is too normalized &amp;#40;you have to click on each method just to discover the return type&amp;#41;&amp;#59; this one presents all you need to get hands on&amp;#33;</description><author>DannieJuge</author><pubDate>Wed, 24 Apr 2013 17:12:47 GMT</pubDate><guid isPermaLink="false">New Comment on "Documentation" 20130424051247P</guid></item><item><title>New Comment on "Documentation"</title><link>https://fluentassertions.codeplex.com/documentation?&amp;ANCHOR#C27140</link><description>Could you break down the wiki so that there is a page for each section&amp;#63;</description><author>bronumski</author><pubDate>Tue, 09 Apr 2013 14:53:17 GMT</pubDate><guid isPermaLink="false">New Comment on "Documentation" 20130409025317P</guid></item><item><title>New Comment on "Documentation"</title><link>http://fluentassertions.codeplex.com/documentation?&amp;ANCHOR#C26142</link><description>Typo&amp;#58; &amp;#10;&amp;#34;Action act &amp;#61; &amp;#40;&amp;#41; &amp;#61;&amp;#62; subject.Foo2&amp;#40;&amp;#34;Hello&amp;#34;&amp;#41;&amp;#59;&amp;#10;&amp;#10;Act.ShouldThrow&amp;#60;InvalidOperationException&amp;#62;&amp;#40;&amp;#41;&amp;#10;     .WithInnerException&amp;#60;ArgumentException&amp;#62;&amp;#40;&amp;#41;&amp;#10;     .WithInnerMessage&amp;#40;&amp;#34;whatever&amp;#34;&amp;#41;&amp;#59;&amp;#34;&amp;#10;&amp;#10;The variable is called &amp;#34;act&amp;#34;, not &amp;#34;Act&amp;#34;. Cheers&amp;#33; &amp;#58;&amp;#41;</description><author>christianfredh</author><pubDate>Thu, 10 Jan 2013 11:15:32 GMT</pubDate><guid isPermaLink="false">New Comment on "Documentation" 20130110111532A</guid></item><item><title>Updated Wiki: Temporary Post Used For Theme Detection (2ca91bfc-29a6-40c3-b1b6-b106ff551f3c - 3bfe001a-32de-4114-a6b4-4005b770f6d7)</title><link>https://fluentassertions.codeplex.com/wikipage?title=Temporary Post Used For Theme Detection (2ca91bfc-29a6-40c3-b1b6-b106ff551f3c - 3bfe001a-32de-4114-a6b4-4005b770f6d7)&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;This is a temporary post that was not deleted. Please delete this manually. (13389238-c4d2-466f-a886-d0c3655d1a79 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)&lt;/p&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Sun, 07 Oct 2012 18:21:35 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Temporary Post Used For Theme Detection (2ca91bfc-29a6-40c3-b1b6-b106ff551f3c - 3bfe001a-32de-4114-a6b4-4005b770f6d7) 20121007062135P</guid></item><item><title>Updated Wiki: Home</title><link>http://fluentassertions.codeplex.com/wikipage?version=90</link><description>
&lt;h2&gt;Project Description&lt;/h2&gt;
&lt;p&gt;Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs
 on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.&lt;/p&gt;
&lt;h2&gt;Why?&lt;/h2&gt;
&lt;p&gt;Nothing is more annoying then a unit test that fails without clearly explaining why. More than often, you need to set a breakpoint and start up the debugger to be able to figure out what went wrong. Jeremy D. Miller
&lt;a href="http://codebetter.com/jeremymiller/2005/08/18/testing-granularity-feedback-cycles-and-holistic-development/"&gt;
once&lt;/a&gt; gave the advice to &amp;quot;keep out of the debugger hell&amp;quot; and I can only agree with that.&lt;/p&gt;
&lt;p&gt;For instance, only test a single condition per test case. If you don't, and the first condition fails, the test engine will not even try to test the other conditions. But if any of the others fail, you'll be on your own to figure out which one. I often run
 into this problem when developers try to combine multiple related tests that test a member using different parameters into one test case. If you really need to do that, consider using a
&lt;a href="http://xunitpatterns.com/Parameterized%20Test.html"&gt;parameterized&lt;/a&gt; test that is being called by several clearly named test cases.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why we designed Fluent Assertions to help you in this area. Not only by using clearly named assertion methods, but also by making sure the failure message provides as much information as possible. Consider this example:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;&amp;quot;1234567890&amp;quot;&lt;/span&gt;.Should().Be(&lt;span class="str"&gt;&amp;quot;0987654321&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;This will be reported as: &lt;br&gt;
&lt;br&gt;
&lt;a href="http://lh3.ggpht.com/-CRwTIbsz8bA/TjK_fSZHjjI/AAAAAAAAIhw/3g-ohBmem8I/s1600-h/clip_image001%25255B6%25255D%25255B4%25255D.png"&gt;&lt;img title="clip_image001[6]" src="http://lh4.ggpht.com/-TuAorOjJXQ4/TjK_fza6W8I/AAAAAAAAIh0/HytVNTA2g_c/clip_image001%25255B6%25255D_thumb%25255B2%25255D.png?imgmax=800" border="0" alt="clip_image001[6]" width="231" height="51" style="padding-top:0px; padding-left:0px; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
The fact that both strings are displayed on a separate line is on purpose and happens if any of them is longer than 8 characters. However, if that's not enough, all assertion methods take an optional formatted reason with placeholders, similarly to String.Format,
 that you can use to enrich the failure message. For instance, the assertion&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3 }.Should().Contain(item =&amp;gt; item &amp;gt; 3, &lt;span class="str"&gt;&amp;quot;at least {0} item should be larger than 3&amp;quot;&lt;/span&gt;, 1);&lt;/pre&gt;
&lt;p&gt;will fail with: &lt;br&gt;
&lt;br&gt;
&lt;a href="http://lh4.ggpht.com/-820NKb40J34/TjK_gTqYSPI/AAAAAAAAIh4/XTPJWfDCP7g/s1600-h/clip_image002%25255B6%25255D%25255B4%25255D.png"&gt;&lt;img title="clip_image002[6]" src="http://lh4.ggpht.com/-bPifQdmVWH4/TjK_gztuiBI/AAAAAAAAIh8/_fuhX5zmh2U/clip_image002%25255B6%25255D_thumb%25255B2%25255D.png?imgmax=800" border="0" alt="clip_image002[6]" width="589" height="21" style="padding-top:0px; padding-left:0px; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;div class="wikidoc"&gt;
&lt;p&gt;To verify that a string begins, ends and contains a particular phrase.&lt;/p&gt;
&lt;pre&gt;string actual = &amp;quot;ABCDEFGHI&amp;quot;;
actual.Should().StartWith(&amp;quot;AB&amp;quot;).And.EndWith(&amp;quot;HI&amp;quot;).And.Contain(&amp;quot;EF&amp;quot;).And.HaveLength(9);&lt;/pre&gt;
&lt;p&gt;To verify that a collection contains a specified number of elements and that all elements match a predicate.&lt;/p&gt;
&lt;pre&gt;&lt;br&gt;IEnumerable collection = new[] { 1, 2, 3 };
collection.Should().HaveCount(4, &amp;quot;because we thought we put three items in the collection&amp;quot;))&lt;br&gt;collection.Should().Contain(i =&amp;gt; i &amp;gt; 0);&lt;/pre&gt;
The nice thing about the second failing example is that it will throw an exception with the message
&lt;br&gt;
&lt;br&gt;
&lt;em&gt;&amp;quot;Expected &amp;lt;4&amp;gt; items because we thought we put three items in the collection, but found &amp;lt;3&amp;gt;.&amp;quot;&lt;/em&gt;
&lt;p&gt;To verify that a particular business rule is enforced using exceptions.&lt;/p&gt;
&lt;pre&gt;var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For(&amp;quot;Milk&amp;quot;).WithQuantity(200, Unit.Milliliters))
   .Build();

Action action = () =&amp;gt; recipe.AddIngredient(&amp;quot;Milk&amp;quot;, 100, Unit.Spoon);

action
   .ShouldThrow&amp;lt;RuleViolationException&amp;gt;()
   .WithMessage(&amp;quot;change the unit of an existing ingredient&amp;quot;, ComparisonMode.Substring)
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;What&amp;rsquo;s new?&lt;/h2&gt;
&lt;div class="wikidoc"&gt;
&lt;div&gt;&lt;strong&gt;
&lt;div&gt;&lt;strong&gt;October&amp;nbsp;7th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;/strong&gt;Version 2.0 is now out of beta.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;August 25th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;Fluent Assertions 2.0, a major new version with support for .NET 4.5, Windows Phone and Windows Store Apps is in
&lt;a href="http://fluentassertions.codeplex.com/releases/view/82423"&gt;beta&lt;/a&gt;. Read all the details in
&lt;a href="http://www.dennisdoomen.net/2012/08/breaking-with-past-orfluent-assertions.html"&gt;
this&lt;/a&gt; blog post.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;January 13th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;div class="wikidoc"&gt;A relatively small release. Read all about it in &lt;a href="http://www.dennisdoomen.net/2012/01/fluent-assertions-170-has-been-released.html"&gt;
this blog post&lt;/a&gt;.&lt;/div&gt;
&lt;div class="wikidoc"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;October 31st, 2011 &lt;br&gt;
&lt;/strong&gt;Another release with lots of bug fixes and small improvements and with great contributions by Martin Opdam and Urs Enzler. Download it
&lt;a href="http://fluentassertions.codeplex.com/releases/view/75904"&gt;here&lt;/a&gt; or get it through
&lt;a href="http://nuget.org/List/Packages/FluentAssertions"&gt;NuGet&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;About versioning&lt;/h2&gt;
&lt;p&gt;The version numbers of Fluent Assertions releases comply to the &lt;a href="http://semver.org/"&gt;
Semantic Versioning&lt;/a&gt; scheme. In other words, release 1.4.0 only adds backwards-compatible functionality and bug fixes compared to 1.3.0. Release 1.4.1 should only include bug fixes. And if we ever introduce breaking changes, the number increased to 2.0.0.&lt;/p&gt;
&lt;h2&gt;Who are we?&lt;/h2&gt;
&lt;div class="wikidoc"&gt;We are a bunch of developers working for &lt;a href="http://www.avivasolutions.nl"&gt;
Aviva Solutions&lt;/a&gt; who highly value software quality, in particular&lt;/div&gt;
&lt;div class="wikidoc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dennisdoomen.net"&gt;Dennis Doomen&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://twitter.com/#!/mpopdam" target="_blank"&gt;Martin Opdam&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;If you have any comments or suggestions, please let us know via twitter, through the
&lt;a href="http://fluentassertions.codeplex.com/discussions"&gt;discussions&lt;/a&gt; page, or through
&lt;a href="http://stackoverflow.com/questions/tagged/fluent-assertions"&gt;StackOverflow&lt;/a&gt;.&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpadding="2" width="150"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="40" valign="top"&gt;&lt;a href="http://www.twitter.com/hterwal"&gt;&lt;img title="clip_image002" src="http://download.codeplex.com/Download?ProjectName=fluentassertions&amp;DownloadId=314062" border="0" alt="clip_image002" width="21" height="21" style="padding-top:0px; padding-left:0px; display:inline; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td width="110" valign="top"&gt;&lt;a href="http://twitter.com/#!/search/%23fluentassertions" target="_blank"&gt;#fluentassertions&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description><author>dennisdoomen</author><pubDate>Sun, 07 Oct 2012 15:37:16 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121007033716P</guid></item><item><title>Updated Wiki: Home</title><link>http://fluentassertions.codeplex.com/wikipage?version=89</link><description>
&lt;h2&gt;Project Description&lt;/h2&gt;
&lt;p&gt;Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test. We currently use it in all our internal and client projects, and it is used in many open-source projects. It runs
 on .NET 3.5, 4.0 and 4.5 (Desktop and Windows Store), Silverlight 4 and 5 and Windows Phone 7.5. And it supports the unit test frameworks NUnit, XUnit, MBUnit, Gallio and MSpec.&lt;/p&gt;
&lt;h2&gt;Why?&lt;/h2&gt;
&lt;p&gt;Nothing is more annoying then a unit test that fails without clearly explaining why. More than often, you need to set a breakpoint and start up the debugger to be able to figure out what went wrong. Jeremy D. Miller
&lt;a href="http://codebetter.com/jeremymiller/2005/08/18/testing-granularity-feedback-cycles-and-holistic-development/"&gt;
once&lt;/a&gt; gave the advice to &amp;quot;keep out of the debugger hell&amp;quot; and I can only agree with that.&lt;/p&gt;
&lt;p&gt;For instance, only test a single condition per test case. If you don't, and the first condition fails, the test engine will not even try to test the other conditions. But if any of the others fail, you'll be on your own to figure out which one. I often run
 into this problem when developers try to combine multiple related tests that test a member using different parameters into one test case. If you really need to do that, consider using a
&lt;a href="http://xunitpatterns.com/Parameterized%20Test.html"&gt;parameterized&lt;/a&gt; test that is being called by several clearly named test cases.&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s why we designed Fluent Assertions to help you in this area. Not only by using clearly named assertion methods, but also by making sure the failure message provides as much information as possible. Consider this example:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;&amp;quot;1234567890&amp;quot;&lt;/span&gt;.Should().Be(&lt;span class="str"&gt;&amp;quot;0987654321&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;This will be reported as: &lt;br&gt;
&lt;br&gt;
&lt;a href="http://lh3.ggpht.com/-CRwTIbsz8bA/TjK_fSZHjjI/AAAAAAAAIhw/3g-ohBmem8I/s1600-h/clip_image001%25255B6%25255D%25255B4%25255D.png"&gt;&lt;img title="clip_image001[6]" src="http://lh4.ggpht.com/-TuAorOjJXQ4/TjK_fza6W8I/AAAAAAAAIh0/HytVNTA2g_c/clip_image001%25255B6%25255D_thumb%25255B2%25255D.png?imgmax=800" border="0" alt="clip_image001[6]" width="231" height="51" style="padding-top:0px; padding-left:0px; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
The fact that both strings are displayed on a separate line is on purpose and happens if any of them is longer than 8 characters. However, if that's not enough, all assertion methods take an optional formatted reason with placeholders, similarly to String.Format,
 that you can use to enrich the failure message. For instance, the assertion&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3 }.Should().Contain(item =&amp;gt; item &amp;gt; 3, &lt;span class="str"&gt;&amp;quot;at least {0} item should be larger than 3&amp;quot;&lt;/span&gt;, 1);&lt;/pre&gt;
&lt;p&gt;will fail with: &lt;br&gt;
&lt;br&gt;
&lt;a href="http://lh4.ggpht.com/-820NKb40J34/TjK_gTqYSPI/AAAAAAAAIh4/XTPJWfDCP7g/s1600-h/clip_image002%25255B6%25255D%25255B4%25255D.png"&gt;&lt;img title="clip_image002[6]" src="http://lh4.ggpht.com/-bPifQdmVWH4/TjK_gztuiBI/AAAAAAAAIh8/_fuhX5zmh2U/clip_image002%25255B6%25255D_thumb%25255B2%25255D.png?imgmax=800" border="0" alt="clip_image002[6]" width="589" height="21" style="padding-top:0px; padding-left:0px; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Examples&lt;/h2&gt;
&lt;div class="wikidoc"&gt;
&lt;p&gt;To verify that a string begins, ends and contains a particular phrase.&lt;/p&gt;
&lt;pre&gt;string actual = &amp;quot;ABCDEFGHI&amp;quot;;
actual.Should().StartWith(&amp;quot;AB&amp;quot;).And.EndWith(&amp;quot;HI&amp;quot;).And.Contain(&amp;quot;EF&amp;quot;).And.HaveLength(9);&lt;/pre&gt;
&lt;p&gt;To verify that a collection contains a specified number of elements and that all elements match a predicate.&lt;/p&gt;
&lt;pre&gt;&lt;br&gt;IEnumerable collection = new[] { 1, 2, 3 };
collection.Should().HaveCount(4, &amp;quot;because we thought we put three items in the collection&amp;quot;))&lt;br&gt;collection.Should().Contain(i =&amp;gt; i &amp;gt; 0);&lt;/pre&gt;
The nice thing about the second failing example is that it will throw an exception with the message
&lt;br&gt;
&lt;br&gt;
&lt;em&gt;&amp;quot;Expected &amp;lt;4&amp;gt; items because we thought we put three items in the collection, but found &amp;lt;3&amp;gt;.&amp;quot;&lt;/em&gt;
&lt;p&gt;To verify that a particular business rule is enforced using exceptions.&lt;/p&gt;
&lt;pre&gt;var recipe = new RecipeBuilder()
   .With(new IngredientBuilder().For(&amp;quot;Milk&amp;quot;).WithQuantity(200, Unit.Milliliters))
   .Build();

Action action = () =&amp;gt; recipe.AddIngredient(&amp;quot;Milk&amp;quot;, 100, Unit.Spoon);

action
   .ShouldThrow&amp;lt;RuleViolationException&amp;gt;()
   .WithMessage(&amp;quot;change the unit of an existing ingredient&amp;quot;, ComparisonMode.Substring)
   .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity);&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;What&amp;rsquo;s new?&lt;/h2&gt;
&lt;div class="wikidoc"&gt;
&lt;div&gt;&lt;strong&gt;
&lt;div&gt;&lt;strong&gt;October&amp;nbsp;7th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/strong&gt;Version 2.0 is now out of beta.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;August 25th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;Fluent Assertions 2.0, a major new version with support for .NET 4.5, Windows Phone and Windows Store Apps is in
&lt;a href="http://fluentassertions.codeplex.com/releases/view/82423"&gt;beta&lt;/a&gt;. Read all the details in
&lt;a href="http://www.dennisdoomen.net/2012/08/breaking-with-past-orfluent-assertions.html"&gt;
this&lt;/a&gt; blog post.&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;January 13th, 2012&lt;/strong&gt;&lt;/div&gt;
&lt;div class="wikidoc"&gt;A relatively small release. Read all about it in &lt;a href="http://www.dennisdoomen.net/2012/01/fluent-assertions-170-has-been-released.html"&gt;
this blog post&lt;/a&gt;.&lt;/div&gt;
&lt;div class="wikidoc"&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;October 31st, 2011 &lt;br&gt;
&lt;/strong&gt;Another release with lots of bug fixes and small improvements and with great contributions by Martin Opdam and Urs Enzler. Download it
&lt;a href="http://fluentassertions.codeplex.com/releases/view/75904"&gt;here&lt;/a&gt; or get it through
&lt;a href="http://nuget.org/List/Packages/FluentAssertions"&gt;NuGet&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;h2&gt;About versioning&lt;/h2&gt;
&lt;p&gt;The version numbers of Fluent Assertions releases comply to the &lt;a href="http://semver.org/"&gt;
Semantic Versioning&lt;/a&gt; scheme. In other words, release 1.4.0 only adds backwards-compatible functionality and bug fixes compared to 1.3.0. Release 1.4.1 should only include bug fixes. And if we ever introduce breaking changes, the number increased to 2.0.0.&lt;/p&gt;
&lt;h2&gt;Who are we?&lt;/h2&gt;
&lt;div class="wikidoc"&gt;We are a bunch of developers working for &lt;a href="http://www.avivasolutions.nl"&gt;
Aviva Solutions&lt;/a&gt; who highly value software quality, in particular&lt;/div&gt;
&lt;div class="wikidoc"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dennisdoomen.net"&gt;Dennis Doomen&lt;/a&gt; &lt;/li&gt;&lt;li&gt;&lt;a href="http://twitter.com/#!/mpopdam" target="_blank"&gt;Martin Opdam&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;If you have any comments or suggestions, please let us know via twitter, through the
&lt;a href="http://fluentassertions.codeplex.com/discussions"&gt;discussions&lt;/a&gt; page, or through
&lt;a href="http://stackoverflow.com/questions/tagged/fluent-assertions"&gt;StackOverflow&lt;/a&gt;.&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpadding="2" width="150"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td width="40" valign="top"&gt;&lt;a href="http://www.twitter.com/hterwal"&gt;&lt;img title="clip_image002" src="http://download.codeplex.com/Download?ProjectName=fluentassertions&amp;DownloadId=314062" border="0" alt="clip_image002" width="21" height="21" style="padding-top:0px; padding-left:0px; display:inline; padding-right:0px; border-width:0px"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td width="110" valign="top"&gt;&lt;a href="http://twitter.com/#!/search/%23fluentassertions" target="_blank"&gt;#fluentassertions&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</description><author>dennisdoomen</author><pubDate>Sun, 07 Oct 2012 15:37:04 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20121007033704P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=195</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of &lt;font face="Courier New"&gt;Equal()&lt;/font&gt; takes a lambda that is used for checking the equality of two collections without relying on the type’s
&lt;font face="Courier New"&gt;Equals()&lt;/font&gt; method. Consider for instance two collections that contain some kind of domain entity persisted to a database and then reloaded. Since the actual object instance is different, if you want to make sure a particular property
 was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as &lt;font face="Courier New"&gt;CollectionAssertions&amp;lt;T&amp;gt;&lt;/font&gt; or
&lt;font face="Courier New"&gt;ReferenceTypeAssertions&amp;lt;T&amp;gt;&lt;/font&gt; and expose them through a custom static class with extension methods named
&lt;font face="Courier New"&gt;Should()&lt;/font&gt;. &lt;br&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the &lt;font face="Courier New"&gt;Verification&lt;/font&gt; class to verify conditions and create comprehensive failure messages using the built-in formatters. Notice that error messages of custom assertion extensions can specify
 the &lt;em&gt;{context}&lt;/em&gt; tag that is used to inject the property path in object graph comparisons. For instance, in the date/time assertions, this is used to display
&lt;em&gt;date and time. &lt;/em&gt;But when this assertion is used as part of a recursive object graph comparison, it will display the property path instead. You can use this special tag in your own extensions like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;Execute.Verification
    .ForCondition(Subject.Value == expected)
    .BecauseOf(reason, reasonArgs)
    .FailWith(&lt;span class="str"&gt;&amp;quot;Expected {context:date and time} to be {0}{reason}, but found {1}.&amp;quot;&lt;/span&gt;, expected, subject.Value);&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Formatters&lt;/h2&gt;
&lt;p&gt;In addition to writing your own extensions, you can influence the way data is formatted with these two techniques.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can alter the list of &lt;font face="Courier New"&gt;IValueFormatter&lt;/font&gt; objects on the
&lt;font face="Courier New"&gt;Formatter&lt;/font&gt; class with your own implementation of that interface. Just make sure your own formatter precedes any of the built-in ones.&lt;/p&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;You can override the way Fluent Assertions formats objects in an error message by annotating a static method with the
&lt;font face="Courier New"&gt;[ValueFormatter]&lt;/font&gt; attribute. If a class doesn’t override
&lt;font face="Courier New"&gt;ToString()&lt;/font&gt;, the built-in &lt;font face="Courier New"&gt;
DefaultValueFormatter&lt;/font&gt; will render an object graph of that object. But you can now override that using a construct like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomFormatter
{    
    [ValueFormatter]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Foo(SomeClassvalue)    
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Property = &amp;quot;&lt;/span&gt; &amp;#43; &lt;span class="kwrd"&gt;value&lt;/span&gt;.Property;   
    }
}&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:56:23 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903065623P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=194</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of &lt;font face="Courier New"&gt;Equal()&lt;/font&gt; takes a lambda that is used for checking the equality of two collections without relying on the type’s
&lt;font face="Courier New"&gt;Equals()&lt;/font&gt; method. Consider for instance two collections that contain some kind of domain entity persisted to a database and then reloaded. Since the actual object instance is different, if you want to make sure a particular property
 was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as &lt;font face="Courier New"&gt;CollectionAssertions&amp;lt;T&amp;gt;&lt;/font&gt; or
&lt;font face="Courier New"&gt;ReferenceTypeAssertions&amp;lt;T&amp;gt;&lt;/font&gt; and expose them through a custom static class with extension methods named
&lt;font face="Courier New"&gt;Should()&lt;/font&gt;. &lt;br&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the &lt;font face="Courier New"&gt;Verification&lt;/font&gt; class to verify conditions and create comprehensive failure messages using the built-in formatters. Notice that error messages of custom assertion extensions can specify
 the &lt;em&gt;{context}&lt;/em&gt; tag that is used to inject the property path in object graph comparisons. For instance, in the date/time assertions, this is used to display
&lt;em&gt;date and time. &lt;/em&gt;But when this assertion is used as part of a recursive object graph comparison, it will display the property path instead. You can use this special tag in your own extensions like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;Execute.Verification
    .ForCondition(Subject.Value == expected)
    .BecauseOf(reason, reasonArgs)
    .FailWith(&lt;span class="str"&gt;&amp;quot;Expected {context:date and time} to be {0}{reason}, but found {1}.&amp;quot;&lt;/span&gt;, expected, subject.Value);&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Formatters&lt;/h2&gt;
&lt;p&gt;In addition to writing your own extensions, you can influence the way data is formatted with these two techniques.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can alter the list of &lt;font face="Courier New"&gt;IValueFormatter&lt;/font&gt; objects on the
&lt;font face="Courier New"&gt;Formatter&lt;/font&gt; class with your own implementation of that interface. Just make sure your own formatter precedes any of the built-in ones.&lt;/p&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;You can override the way Fluent Assertions formats objects in an error message by annotating a static method with the
&lt;font face="Courier New"&gt;[ValueFormatter]&lt;/font&gt; attribute. If a class doesn’t override
&lt;font face="Courier New"&gt;ToString()&lt;/font&gt;, the built-in &lt;font face="Courier New"&gt;
DefaultValueFormatter&lt;/font&gt; will render an object graph of that object. But you can now override that using a construct like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomFormatter
{    
    [ValueFormatter]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Foo(SomeClassvalue)    
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Property = &amp;quot;&lt;/span&gt; &amp;#43; &lt;span class="kwrd"&gt;value&lt;/span&gt;.Property;   
    }
}&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:55:27 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903065527P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=193</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of &lt;font face="Courier New"&gt;Equal()&lt;/font&gt; takes a lambda that is used for checking the equality of two collections without relying on the type’s
&lt;font face="Courier New"&gt;Equals()&lt;/font&gt; method. Consider for instance two collections that contain some kind of domain entity persisted to a database and then reloaded. Since the actual object instance is different, if you want to make sure a particular property
 was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as &lt;font face="Courier New"&gt;CollectionAssertions&amp;lt;T&amp;gt;&lt;/font&gt; or
&lt;font face="Courier New"&gt;ReferenceTypeAssertions&amp;lt;T&amp;gt;&lt;/font&gt; and expose them through a custom static class with extension methods named
&lt;font face="Courier New"&gt;Should()&lt;/font&gt;. &lt;br&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the &lt;font face="Courier New"&gt;Verification&lt;/font&gt; class to verify conditions and create comprehensive failure messages using the built-in formatters. Notice that error messages of custom assertion extensions can specify
 the &lt;em&gt;{context}&lt;/em&gt; tag that is used to inject the property path in object graph comparisons. For instance, in the date/time assertions, this is used to display
&lt;em&gt;date and time. &lt;/em&gt;But when this assertion is used as part of a recursive object graph comparison, it will display the property path instead. You can use this special tag in your own extensions like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;Execute.Verification
    .ForCondition(Subject.Value == expected)
    .BecauseOf(reason, reasonArgs)
    .FailWith(&lt;span class="str"&gt;&amp;quot;Expected {context:date and time} to be {0}{reason}, but found {1}.&amp;quot;&lt;/span&gt;, expected, subject.Value);&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Formatters&lt;/h2&gt;
&lt;p&gt;In addition to writing your own extensions, you can influence the way data is formatted with these two techniques.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can alter the list of &lt;font face="Courier New"&gt;IValueFormatter&lt;/font&gt; objects on the
&lt;font face="Courier New"&gt;Formatter&lt;/font&gt; class with your own implementation of that interface. Just make sure your own formatter precedes any of the built-in ones.&lt;/p&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;You can override the way Fluent Assertions formats objects in an error message by annotating a static method with the
&lt;font face="Courier New"&gt;[ValueFormatter]&lt;/font&gt; attribute. If a class doesn’t override
&lt;font face="Courier New"&gt;ToString()&lt;/font&gt;, the built-in &lt;font face="Courier New"&gt;
DefaultValueFormatter&lt;/font&gt; will render an object graph of that object. But you can now override that using a construct like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CustomFormatter
{    
    [ValueFormatter]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Foo(SomeClassvalue)    
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Property = &amp;quot;&lt;/span&gt; &amp;#43; &lt;span class="kwrd"&gt;value&lt;/span&gt;.Property;   
    }
}&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;/li&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:54:07 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903065407P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=192</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of &lt;font face="Courier New"&gt;Equal()&lt;/font&gt; takes a lambda that is used for checking the equality of two collections without relying on the type’s
&lt;font face="Courier New"&gt;Equals()&lt;/font&gt; method. Consider for instance two collections that contain some kind of domain entity persisted to a database and then reloaded. Since the actual object instance is different, if you want to make sure a particular property
 was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;Extend one of the built-in classes such as &lt;font face="Courier New"&gt;CollectionAssertions&amp;lt;T&amp;gt;&lt;/font&gt; or
&lt;font face="Courier New"&gt;ReferenceTypeAssertions&amp;lt;T&amp;gt;&lt;/font&gt; and expose them through a custom static class with extension methods named
&lt;font face="Courier New"&gt;Should()&lt;/font&gt;. &lt;br&gt;
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class:
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/li&gt;&lt;li&gt;Create a custom assertions class and use the &lt;font face="Courier New"&gt;Verification&lt;/font&gt; class to verify conditions and create comprehensive failure messages using the built-in formatters. Notice that error messages of custom assertion extensions can specify
 the &lt;em&gt;{context}&lt;/em&gt; tag that is used to inject the property path in object graph comparisons. For instance, in the date/time assertions, this is used to display
&lt;em&gt;date and time. &lt;/em&gt;But when this assertion is used as part of a recursive object graph comparison, it will display the property path instead. You can use this special tag in your own extensions like this:&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;Execute.Verification
    .ForCondition(Subject.Value == expected)
    .BecauseOf(reason, reasonArgs)
    .FailWith(&lt;span class="str"&gt;&amp;quot;Expected {context:date and time} to be {0}{reason}, but found {1}.&amp;quot;&lt;/span&gt;, expected, subject.Value);&lt;/pre&gt;
&lt;h2&gt;Formatters&lt;/h2&gt;
&lt;p&gt;In addition to writing your own extensions, you can influence the way data is formatted with these two techniques.&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;
&lt;p&gt;You can alter the list of &lt;font face="Courier New"&gt;IValueFormatter&lt;/font&gt; objects on the
&lt;font face="Courier New"&gt;Formatter&lt;/font&gt; class with your own implementation of that interface. Just make sure your own formatter precedes any of the built-in ones.&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;
&lt;p&gt;You can override the way Fluent Assertions formats objects in an error message by annotating a static method with the
&lt;font face="Courier New"&gt;[ValueFormatter]&lt;/font&gt; attribute. If a class doesn’t override
&lt;font face="Courier New"&gt;ToString()&lt;/font&gt;, the built-in &lt;font face="Courier New"&gt;
DefaultValueFormatter&lt;/font&gt; will render an object graph of that object. But you can now override that using a construct like this:&lt;/p&gt;
&lt;pre&gt;public static class CustomFormatter
{
    [ValueFormatter]
    public static string Foo(SomeClassvalue)
    {
        return &amp;quot;Property = &amp;quot; &amp;#43; value.Property;
    }
}&lt;/pre&gt;
&lt;/li&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:50:09 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903065009P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=191</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of Equal() takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database and
 then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;@&lt;/p&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as &lt;font face="Courier New"&gt;CollectionAssertions&amp;lt;T&amp;gt;&lt;/font&gt; or
&lt;font face="Courier New"&gt;ReferenceTypeAssertions&amp;lt;T&amp;gt;&lt;/font&gt; and expose them through a custom static class with extension methods named
&lt;font face="Courier New"&gt;Should()&lt;/font&gt;. &lt;br&gt;
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the &lt;font face="Courier New"&gt;Verification&lt;/font&gt; class to verify conditions and create comprehensive failure messages using the built-in formatters. Notice that error messages of custom assertion extensions can specify
 the &lt;em&gt;{context}&lt;/em&gt; tag that is used to inject the property path in object graph comparisons. For instance, in the date/time assertions, this is used to display
&lt;em&gt;date and time. &lt;/em&gt;But when this assertion is used as part of a recursive object graph comparison, it will display the property path instead. You can use this special tag in your own extensions like this:&lt;br&gt;
&lt;pre class="csharpcode"&gt;Execute.Verification
    .ForCondition(Subject.Value == expected)
    .BecauseOf(reason, reasonArgs)
    .FailWith(&lt;span class="str"&gt;&amp;quot;Expected {context:date and time} to be {0}{reason}, but found {1}.&amp;quot;&lt;/span&gt;, expected, subject.Value);&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Formatters&lt;/h2&gt;
&lt;p&gt;In addition to writing your own extensions, you can influence the way data is formatted using two techniques.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can alter the list of &lt;font face="Courier New"&gt;IValueFormatter&lt;/font&gt; objects on the
&lt;font face="Courier New"&gt;Formatter&lt;/font&gt; class with your own implementation of that interface.&lt;/p&gt;
&lt;/li&gt;&lt;li&gt;
&lt;p&gt;You can override the way Fluent Assertions formats objects in an error message by annotating a static method with the
&lt;font face="Courier New"&gt;[ValueFormatter]&lt;/font&gt; attribute. If a class doesn’t override
&lt;font face="Courier New"&gt;ToString()&lt;/font&gt;, the built-in &lt;font face="Courier New"&gt;
DefaultValueFormatter&lt;/font&gt; will render an object graph of that object. But you can now override that using a construct like this:&lt;/p&gt;
&lt;pre&gt;public static class CustomFormatter
{
    [ValueFormatter]
    public static string Foo(SomeClassvalue)
    {
        return &amp;quot;Property = &amp;quot; &amp;#43; value.Property;
    }
}&lt;/pre&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:44:48 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903064448P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=190</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of Equal() takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database and
 then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, Windows Phone and .NET for Windows Store APps, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in those versions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If you also want to assert that an attribute has a specific property value, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;typeWithAttribute.Should()
  .BeDecoratedWith&amp;lt;DummyClassAttribute&amp;gt;(a =&amp;gt; ((a.Name == &lt;span class="str"&gt;&amp;quot;Unexpected&amp;quot;&lt;/span&gt;) &amp;amp;&amp;amp; a.IsEnabled));&lt;/pre&gt;
&lt;p&gt;You can assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;p&gt;Alternatively you can use this more fluent syntax instead.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;AllTypes.From(assembly)
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;@&lt;/p&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:32:36 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903063236P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=189</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value you can use this method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of Equal() takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database and
 then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Important Note: The new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:28:19 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903062819P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=188</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;h2&gt;Timespans&lt;/h2&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of Equal() takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database and
 then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;For the record, the new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:26:19 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903062619P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=187</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;int? nullableInt = 3;&lt;br&gt;nullableInt.Should().Be(3);

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;p&gt;To assert that a value matches one of the provided values, you can do this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeOneOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 3, 6});&lt;/pre&gt;
&lt;h2&gt;Dates and times&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));&lt;br&gt;theDatetime.Should().NotBe(1.March(2010).At(22, 15)); 

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;To assert that a date/time is within a specified number of milliseconds from another date/time value.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeCloseTo(March(2010).At(22,15), 2000); // 2000 milliseconds
theDatetime.Should().BeCloseTo(March(2010).At(22,15));       // &lt;span class="kwrd"&gt;default&lt;/span&gt; &lt;span class="kwrd"&gt;is&lt;/span&gt; 20 milliseconds&lt;/pre&gt;
&lt;p&gt;This can be particularly useful if your database truncates date/time values. &lt;/p&gt;
&lt;p&gt;&lt;font size="5"&gt;&lt;strong&gt;Timespans&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="rem"&gt;FA also support a few dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;A special overload of Equal() takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database and
 then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;For the record, the new extension methods discussed in the previous section are going to supersede the old ShouldHave() method somewhere in a next major version. Internally the old methods are already using the new comparison engine, but new functionality
 will only be available through the new methods.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). This works for entire collections of objects as well, even if you use an interface or an anonymous type. It doesn't matter what kind of collection type you use, as long as it contains the same number
 of objects, and the object’s properties match.&lt;/p&gt;
&lt;p&gt;As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; method. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the nested
 properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;When comparing the properties of an object and one of them causes a cyclic reference, then an exception is thrown. You can now alter that behavior by passing in a value from the
&lt;font face="Courier New"&gt;CyclicReferenceHandling&lt;/font&gt; enum into the &lt;font face="Courier New"&gt;
IncludingNestedObjects()&lt;/font&gt; method.&lt;/p&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:25:48 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903062548P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=186</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;h2&gt;Dates, times and time spans&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="rem"&gt;Some dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().BeInAscendingOrder();&lt;br&gt;collection.Should().NotBeInAscendingOrder();&lt;br&gt;collection.Should().IntersectWith(otherCollection);&lt;br&gt;collection.Should().NotIntersectWith(otherCollection);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;collection.Should().ContainInOrder(new[] { 1, 5, 8 });&lt;/pre&gt;
&lt;p&gt;Added an overload to Equal() that takes a lambda that is used for checking the equality of two collections without relying on the type’s Equals() method. Consider for instance two collections that contain some kind of domain entity persisted to a database
 and then reloaded. Since the actual object instance is different, if you want to make sure a particular property was properly persisted, you usually do something like this:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Select(c =&amp;gt; c.Name).Should().Equal(customers.Select(c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;p&gt;With this new overload, you can rewrite it into:&lt;/p&gt;
&lt;pre&gt;persistedCustomers.Should().Equal(customers, c =&amp;gt; c.Name);&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the
 nested properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 18:02:21 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903060221P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=185</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;h2&gt;Dates, times and time spans&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="rem"&gt;Some dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the
 nested properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects().EqualTo(customer);&lt;/pre&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 17:52:23 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903055223P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=184</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;h2&gt;Dates, times and time spans&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="rem"&gt;Some dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; (a so-called &lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;
DTO&lt;/a&gt;). Suppose also that an order has one or more &lt;font face="Courier New"&gt;Product&lt;/font&gt;s and an associated
&lt;font face="Courier New"&gt;Customer&lt;/font&gt;. Coincidentally, the &lt;font face="Courier New"&gt;
OrderDto&lt;/font&gt; will have one or more &lt;font face="Courier New"&gt;ProductDto&lt;/font&gt;s and a corresponding
&lt;font face="Courier New"&gt;CustomerDto&lt;/font&gt;. Now if you want to make sure that all the properties of all the objects in the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method, the comparison is recursive by default and all properties of the
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt; must be available on the &lt;font face="Courier New"&gt;
Order&lt;/font&gt;. If not, an exception is thrown. You can override this behavior in different ways. For instance, you may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the &lt;font face="Courier New"&gt;
Excluding()&lt;/font&gt; method. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; and &lt;font face="Courier New"&gt;
ExcludingMissingProperties()&lt;/font&gt; can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The &lt;font face="Courier New"&gt;Excluding()&lt;/font&gt; method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original &lt;font face="Courier New"&gt;ShouldHave()&lt;/font&gt; extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method
&lt;font face="Courier New"&gt;ShouldAllBeEquivalentTo()&lt;/font&gt; does support that so you can now take the 2nd example from the post and apply it on a collection of
&lt;font face="Courier New"&gt;OrderDto&lt;/font&gt;s. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt; options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of &lt;font face="Courier New"&gt;
ISelectionRule&lt;/font&gt;, &lt;font face="Courier New"&gt;IMatchingRule&lt;/font&gt; and &lt;font face="Courier New"&gt;
IAssertionRule&lt;/font&gt; that are maintained by the &lt;font face="Courier New"&gt;EquivalencyAssertionOptions&lt;/font&gt;. The
&lt;font face="Courier New"&gt;ExcludePropertyByPredicateSelectionRule&lt;/font&gt; for example, is added to the collection of selection rules when you use the
&lt;font face="Courier New"&gt;Excluding(property expression)&lt;/font&gt; method on the options parameter of
&lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt;. Even the &lt;font face="Courier New"&gt;
Using().When()&lt;/font&gt; construct in the previous section is doing nothing more than inserting an
&lt;font face="Courier New"&gt;AssertionRule&amp;lt;TSubject&amp;gt;&lt;/font&gt; in to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the &lt;font face="Courier New"&gt;ShouldBeEquivalentTo()&lt;/font&gt; call using the
&lt;font face="Courier New"&gt;Using()&lt;/font&gt; method on the options parameters. &lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the
 nested properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects.EqualTo(customer);&lt;/pre&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 17:51:30 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903055130P</guid></item><item><title>Updated Wiki: Documentation</title><link>https://fluentassertions.codeplex.com/documentation?version=183</link><description>&lt;div class="wikidoc"&gt;
&lt;p&gt;&lt;font color="#666666"&gt;For the 1.7.1 release, click &lt;/font&gt;&lt;a href="http://fluentassertions.codeplex.com/wikipage?title=API%20Reference%20Release%201.7.1"&gt;&lt;font color="#666666"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font color="#666666"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;h2&gt;Supported Test Frameworks&lt;/h2&gt;
&lt;p&gt;Fluent Assertions supports MSTest, NUnit, XUnit, MSpec, MBUnit and the Gallio Framework. You can simply add a reference to the corresponding test framework assembly to the unit test project. Fluent Assertions will automatically find the corresponding assembly
 and use it for throwing the framework-specific exceptions. If, for some unknown reason, Fluent Assertions fails to find the assembly, try specifying the framework explicitly using a configuration setting in the project’s
&lt;span style="font-family:consolas"&gt;app.config&lt;/span&gt;. If it cannot find any of the supported frameworks, it will fall back to using a custom
&lt;span style="font-family:courier new"&gt;AssertFailedException&lt;/span&gt; exception class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    
    &lt;span class="rem"&gt;&amp;lt;!-- Supported values: nunit, xunit, mstest, mspec, mbunit and gallio --&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;key&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;FluentAssertions.TestFramework&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;nunit&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;appSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Reference Types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;object&lt;/span&gt; theObject = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theObject.Should().BeNull(&lt;span class="str"&gt;&amp;quot;because the value is null&amp;quot;&lt;/span&gt;);
     
theObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().BeOfType&amp;lt;String&amp;gt;(&lt;span class="str"&gt;&amp;quot;because a {0} is set&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(String));
theObject.Should().NotBeNull();

&lt;span class="kwrd"&gt;string&lt;/span&gt; otherObject = &lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;;
theObject.Should().Be(otherObject, &lt;span class="str"&gt;&amp;quot;because they have the same values&amp;quot;&lt;/span&gt;);
     
theObject = otherObject;     
theObject.Should().BeSameAs(otherObject);
theObject.Should().NotBeSameAs(otherObject);

var ex = &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException();
ex.Should().BeAssignableTo&amp;lt;Exception&amp;gt;(&lt;span class="str"&gt;&amp;quot;because it is an exception&amp;quot;&lt;/span&gt;);

var dummy = &lt;span class="kwrd"&gt;new&lt;/span&gt; Object();
dummy.Should().Match(d =&amp;gt; (d.ToString() == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(d =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));
dummy.Should().Match((&lt;span class="kwrd"&gt;string&lt;/span&gt; d) =&amp;gt; (d == &lt;span class="str"&gt;&amp;quot;System.Object&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Some users requested the ability to easily downcast an object to one of its derived classes in a fluent way.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;customer.Animals.First().As&amp;lt;Human&amp;gt;().Height.Should().Be(178);&lt;/pre&gt;
&lt;p&gt;We’ve also added the possibility to assert that an object can be serialized and deserialized using the XML or binary formatters.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theObject.Should().BeXmlSerializable();
theObject.Should().BeBinarySerializable();&lt;/pre&gt;
&lt;h2&gt;Nullable types&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;short&lt;/span&gt;? theShort = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theShort.Should().NotHaveValue();

&lt;span class="kwrd"&gt;int&lt;/span&gt;? theInt = 3;
theInt.Should().HaveValue();

&lt;span class="kwrd"&gt;DateTime&lt;/span&gt;? theDate = &lt;span class="kwrd"&gt;null&lt;/span&gt;;
theDate.Should().NotHaveValue();&lt;/pre&gt;
&lt;h2&gt;Booleans&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; theBoolean = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
theBoolean.Should().BeFalse(&lt;span class="str"&gt;&amp;quot;it's set to false&amp;quot;&lt;/span&gt;);

theBoolean = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
theBoolean.Should().BeTrue();
theBoolean.Should().Be(otherBoolean);&lt;/pre&gt;
&lt;h2&gt;Strings&lt;/h2&gt;
&lt;p&gt;For asserting whether a string is &lt;em&gt;null&lt;/em&gt;, empty or contains whitespace only, you have a wide range of methods to your disposal.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; theString = &lt;span class="str"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;
theString.Should().NotBeNull();&lt;br&gt;theString.Should().BeNull();&lt;br&gt;theString.Should().BeEmpty();
theString.Should().NotBeEmpty(&lt;span class="str"&gt;&amp;quot;because the string is not empty&amp;quot;&lt;/span&gt;); 
theString.Should().HaveLength(0);&lt;br&gt;theString.Should().BeBlank(); // either null, empty or whitespace only&lt;br&gt;theString.Should().NotBeBlank();&lt;/pre&gt;
&lt;p&gt;Obviously you’ll find all the methods you would expect for string assertions.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theString = &lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;;
theString.Should().Be(&lt;span class="str"&gt;&amp;quot;This is a String&amp;quot;&lt;/span&gt;);
theString.Should().NotBe(&lt;span class="str"&gt;&amp;quot;This is another String&amp;quot;&lt;/span&gt;);
theString.Should().BeEquivalentTo(&lt;span class="str"&gt;&amp;quot;THIS IS A STRING&amp;quot;&lt;/span&gt;);
theString.Should().EndWith(&lt;span class="str"&gt;&amp;quot;a String&amp;quot;&lt;/span&gt;);
theString.Should().EndWithEquivalent(&lt;span class="str"&gt;&amp;quot;a string&amp;quot;&lt;/span&gt;);
theString.Should().Contain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContain(&lt;span class="str"&gt;&amp;quot;is a&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().ContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;WE DONT CARE ABOUT THE CASING&amp;quot;&lt;/span&gt;);&lt;br&gt;theString.Should().NotContainEquivalentOf(&lt;span class="str"&gt;&amp;quot;HeRe ThE CaSiNg Is IgNoReD As WeLl&amp;quot;&lt;/span&gt;);
theString.Should().StartWith(&lt;span class="str"&gt;&amp;quot;This&amp;quot;&lt;/span&gt;);
theString.Should().StartWithEquivalent(&lt;span class="str"&gt;&amp;quot;this&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;We even support wildcars. For instance, if you would like to assert that some email address is correct, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().Match(&lt;span class="str"&gt;&amp;quot;*@*.com&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;If the casing of the input string is irrelevant, use this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;emailAddress.Should().MatchEquivalentOf(&lt;span class="str"&gt;&lt;a href="mailto:*@*.COM"&gt;*@*.COM&lt;/a&gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Numeric types and everything else that implements IComparable&amp;lt;T&amp;gt;&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt = 5;
theInt.Should().BeGreaterOrEqualTo(5);
theInt.Should().BeGreaterOrEqualTo(3);
theInt.Should().BeGreaterThan(4);     
theInt.Should().BeLessOrEqualTo(5);
theInt.Should().BeLessThan(6);
theInt.Should().BePositive();
theInt.Should().Be(5);
theInt.Should().NotBe(10);&lt;br&gt;theInt.Should().BeInRange(1,10);

theInt = -8;
theInt.Should().BeNegative();

&lt;span class="kwrd"&gt;double&lt;/span&gt; theDouble = 5.1;     
theDouble.Should().BeGreaterThan(5);&lt;/pre&gt;
&lt;pre class="csharpcode"&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;byte&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt; = 2;
&lt;span class="kwrd"&gt;&lt;span style="color:#000000"&gt;theByte&lt;/span&gt;&lt;/span&gt;.Should().Be(2);&lt;/pre&gt;
&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-size:x-small; font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().Be()&lt;/span&gt;&lt;/span&gt; and
&lt;span style="font-family:consolas"&gt;&lt;span style="font-size:x-small"&gt;Should().NotBe()&lt;/span&gt;&lt;/span&gt; are not available for
&lt;span style="font-family:consolas"&gt;float&lt;/span&gt;s and &lt;span style="font-family:consolas"&gt;
double&lt;/span&gt;s. As explained in &lt;a href="http://csharpindepth.com/Articles/General/FloatingPoint.aspx"&gt;
this article&lt;/a&gt;, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the
&lt;span style="font-family:consolas"&gt;Should().BeInRange()&lt;/span&gt; method or the following method specifically designed for floating point variables.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;float&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = 3.1415927F;
&lt;span class="kwrd"&gt;value&lt;/span&gt;.Should().BeApproximately(3.14F, 0.001F);&lt;/pre&gt;
&lt;p&gt;This will verify that the value of the &lt;span style="font-family:consolas"&gt;float&lt;/span&gt; is between 3.139 and 3.141.&lt;/p&gt;
&lt;h2&gt;Dates, times and time spans&lt;/h2&gt;
&lt;p&gt;For asserting a date and time against various constraints, FA offers a bunch of methods that, provided that you use the extension methods for representinging dates and times, really help to keep your assertions readable.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var theDatetime = 1.March(2010).At(22,15);&lt;br&gt;
theDatetime.Should().BeAfter(1.February(2010));
theDatetime.Should().BeBefore(2.March(2010));     
theDatetime.Should().BeOnOrAfter(1.March(2010));

theDatetime.Should().Be(1.March(2010).At(22, 15));

theDatetime.Should().HaveDay(1);
theDatetime.Should().HaveMonth(3);
theDatetime.Should().HaveYear(2010);
theDatetime.Should().HaveHour(22);
theDatetime.Should().HaveMinute(15);
theDatetime.Should().HaveSecond(0);&lt;/pre&gt;
&lt;p&gt;We've added a whole set of methods for asserting that the difference between two
&lt;span style="font-family:consolas"&gt;DateTime&lt;/span&gt; objects match a certain time frame. All five methods support a
&lt;span style="font-family:consolas"&gt;Before&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
After&lt;/span&gt; extension method.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;theDatetime.Should().BeLessThan(10.Minutes()).Before(otherDatetime); &lt;span class="rem"&gt;// Equivalent to &amp;lt;&lt;/span&gt;
theDatetime.Should().BeWithin(2.Hours()).After(otherDatetime);       &lt;span class="rem"&gt;// Equivalent to &amp;lt;=&lt;/span&gt;
theDatetime.Should().BeMoreThan(1.Days()).Before(deadline);          &lt;span class="rem"&gt;// Equivalent to &amp;gt;&lt;/span&gt;
theDatetime.Should().BeAtLeast(2.Days()).Before(deliveryDate);       &lt;span class="rem"&gt;// Equivalent to &amp;gt;=&lt;/span&gt;
theDatetime.Should().BeExactly(24.Hours()).Before(appointement);     &lt;span class="rem"&gt;// Equivalent to ==&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span class="rem"&gt;Some dedicated methods that apply to &lt;span style="font-family:consolas"&gt;
TimeSpans&lt;/span&gt; directly:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var timespan = &lt;span class="kwrd"&gt;new&lt;/span&gt; Timespan(12, 59, 59); 
timespan.Should().BePositive(); 
timespan.Should().BeNegative(); 
timespan.Should().Be(12.Hours()); 
timespan.Should().NotBe(1.Days()); 
timespan.Should().BeLessThan(someOtherTimespan); 
timespan.Should().BeLessOrEqual(someOtherTimespan); 
timespan.Should().BeGreaterThan(someOtherTimespan); 
timespan.Should().BeGreaterOrEqual(someOtherTimespan);&lt;/pre&gt;
&lt;h2&gt;Collections&lt;/h2&gt;
&lt;pre class="csharpcode"&gt;IEnumerable collection = &lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 5, 8 };

collection.Should().NotBeEmpty()
     .And.HaveCount(4)
     .And.ContainInOrder(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 2, 5 })
     .And.ContainItemsAssignableTo&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();

collection.Should().Equal(&lt;span class="kwrd"&gt;new&lt;/span&gt; list&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; { 1, 2, 5, 8 });
collection.Should().Equal(1, 2, 5, 8);
collection.Should().BeEquivalent(8, 2, 1, 5);
collection.Should().NotBeEquivalent(8, 2, 3, 5);

collection.Should().HaveCount(c =&amp;gt; c &amp;gt; 3).And.OnlyHaveUniqueItems();
collection.Should().HaveSameCount(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {6, 2, 0, 5});

collection.Should().BeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, });&lt;br&gt;collection.Should().Contain(8).And.HaveElementAt(2, 5).And.NotBeSubsetOf(&lt;span class="kwrd"&gt;new&lt;/span&gt;[] {11, 56});&lt;br&gt;collection.Should().Contain(x =&amp;gt; x &amp;gt; 3); &lt;br&gt;collection.Should().Contain(collection, 5, 6); &lt;span class="rem"&gt;// It should contain the original items, plus 5 and 6.&lt;/span&gt;
collection.Should().OnlyContain(x =&amp;gt; x &amp;lt; 10);
collection.Should().OnlyContainItemsOfType&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
collection.Should().NotContain(82);
collection.Should().NotContainNulls();&lt;br&gt;collection.Should().NotContain(x =&amp;gt; x &amp;gt; 10);

collection = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[0];
collection.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Dictionaries&lt;/h2&gt;
&lt;p&gt;You can apply Fluent Assertions to your generic dictionaries as well. Of course you can assert any dictionary to be
&lt;em&gt;null&lt;/em&gt; or not &lt;em&gt;null&lt;/em&gt;, and empty or not empty. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().BeNull();
dictionary.Should().NotBeNull();
dictionary.Should().BeEmpty();
dictionary.Should().NotBeEmpty();&lt;/pre&gt;
&lt;p&gt;You can also assert the equality of the entire dictionary, where the equality of the keys and values will be validated using their Equals implementation. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var dictionary1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt; },
    { 2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt; }
};

var dictionary3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
{
    { 3, &lt;span class="str"&gt;&amp;quot;Three&amp;quot;&lt;/span&gt; },
};

dictionary1.Should().Equal(dictionary2);
dictionary1.Should().NotEqual(dictionary3);&lt;/pre&gt;
&lt;p&gt;Or you can assert that the dictionary contains a certain key or value:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().ContainKey(1);
dictionary.Should().NotContainKey(9);
dictionary.Should().ContainValue(&lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContainValue(&lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can also assert that the dictionary has a certain number of items:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dictionary.Should().HaveCount(2);&lt;/pre&gt;
&lt;p&gt;And finally you can assert that the dictionary contains a specific key/value pair or not:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; item = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeyValuePair&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;(1, &lt;span class="str"&gt;&amp;quot;One&amp;quot;&lt;/span&gt;);

dictionary.Should().Contain(item);
dictionary.Should().Contain(2, &lt;span class="str"&gt;&amp;quot;Two&amp;quot;&lt;/span&gt;);
dictionary.Should().NotContain(9, &lt;span class="str"&gt;&amp;quot;Nine&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;h2&gt;Guids&lt;/h2&gt;
&lt;p&gt;The assertions you can do on Guids are simple. You can assert their equality to another Guid, or you can assert that a Guid is empty.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Guid theGuid = Guid.NewGuid();
Guid sameGuid = theGuid;
Guid otherGuid = Guid.NewGuid();

theGuid.Should().Be(sameGuid);
theGuid.Should().NotBe(otherGuid);
theGuid.Should().NotBeEmpty();

Guid.Empty.Should().BeEmpty();&lt;/pre&gt;
&lt;h2&gt;Exceptions&lt;/h2&gt;
&lt;p&gt;The following example verifies that the &lt;span style="font-family:consolas"&gt;Foo()&lt;/span&gt; method throws an I&lt;span style="font-family:consolas"&gt;nvalidOperationException&lt;/span&gt; which
&lt;span style="font-family:consolas"&gt;Message&lt;/span&gt; property has a specific value.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.Invoking(y =&amp;gt; y.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;))
     .ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithMessage(&amp;quot;Hello &lt;span class="kwrd"&gt;is&lt;/span&gt; not allowed at &lt;span class="kwrd"&gt;this&lt;/span&gt; moment”);&lt;/pre&gt;
&lt;p&gt;But if you, like me, prefer the &lt;em&gt;arrange-act-assert&lt;/em&gt; syntax, you can also use an action in your
&lt;em&gt;act&lt;/em&gt; part.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo2(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;);&lt;br&gt;
Act.ShouldThrow&amp;lt;InvalidOperationException&amp;gt;()
     .WithInnerException&amp;lt;ArgumentException&amp;gt;()
     .WithInnerMessage(&lt;span class="str"&gt;&amp;quot;whatever&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that the example also verifies that the exception has a particular inner exception with a specific message. in fact, you can even check the individual properties of the exception instance using the
&lt;em&gt;And&lt;/em&gt; property.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;));&lt;br&gt;
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
     .And.ParamName.Should().Equal(&lt;span class="str"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;An alternative syntax for doing the same is by chaining or more calls to the &lt;span style="font-family:consolas"&gt;
Where()&lt;/span&gt; method introduced in version 1.4.0:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act.ShouldThrow&amp;lt;ArgumentNullException&amp;gt;().Where(e =&amp;gt; e.Message.StartsWith(“did”));&lt;/pre&gt;
&lt;p&gt;However, we discovered that testing the exception message for a substring is so common, that we introduced some specialized methods for that.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“did”, ComparisonMode.StartWith);&lt;/pre&gt;
&lt;p&gt;Supported ComparisonModes are: &lt;span style="font-family:courier new"&gt;Exact&lt;/span&gt; (the default),
&lt;span style="font-family:courier new"&gt;Equivalent&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
StartWith&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;StartWithEquivalent&lt;/span&gt;,
&lt;span style="font-family:courier new"&gt;Substring&lt;/span&gt;, &lt;span style="font-family:courier new"&gt;
EquivalentSubstring&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;Wildcard&lt;/span&gt;. The latter can be used if you really want to get in the nitty gritty and allows you to compare the message with a wildcard expression.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="kwrd"&gt;null&lt;/span&gt;)); 
act
  .ShouldThrow&amp;lt;ArgumentNullException&amp;gt;()
  .WithMessage(“?did*”, ComparisonMode.Wildcard);&lt;/pre&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax. If you want to verify that a
&lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;If the method you are testing returns an &lt;span style="font-family:consolas"&gt;IEnumerable&lt;/span&gt; or
&lt;span style="font-family:consolas"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/span&gt; and it uses the &lt;a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx"&gt;
yield&lt;/a&gt; keyword to construct that collection, just calling the method will not cause the effect you expected. Because the real work is not done until you actually iterate over that collection. you can use the
&lt;span style="font-family:consolas"&gt;Enumerating()&lt;/span&gt; extension method to force enumerating the collection like this.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Func&amp;lt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;char&lt;/span&gt;&amp;gt;&amp;gt; func = () =&amp;gt; obj.SomeMethodThatUsesYield(&lt;span class="str"&gt;&amp;quot;blah&amp;quot;&lt;/span&gt;);
func.Enumerating().ShouldThrow&amp;lt;ArgumentException&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You do have to use the &lt;span style="font-family:consolas"&gt;Func&amp;lt;T&amp;gt;&lt;/span&gt; type instead of
&lt;span style="font-family:consolas"&gt;Action&amp;lt;T&amp;gt;&lt;/span&gt; then.&lt;/p&gt;
&lt;p&gt;On the other hand, you may want to verify that &lt;strong&gt;no&lt;/strong&gt; exceptions were thrown.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));
act.ShouldNotThrow();&lt;/pre&gt;
&lt;p&gt;I know that a unit test will fail anyhow if an exception was thrown, but this syntax returns a clearer description of the exception that was thrown and fits better to the AAA syntax.&lt;/p&gt;
&lt;p&gt;If you want to verify that a &lt;strong&gt;specific&lt;/strong&gt; exception is &lt;strong&gt;not&lt;/strong&gt; thrown, and want to ignore others, you can do that using an overload:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action act = () =&amp;gt; subject.Foo(&lt;span class="str"&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;));&lt;br&gt;act.ShouldNotThrow&amp;lt;InvalidOperationException&amp;gt;();&lt;/pre&gt;
&lt;h2&gt;Object graph comparison&lt;/h2&gt;
&lt;p&gt;Consider the class &lt;font face="Courier New"&gt;Order&lt;/font&gt; and its wire-transfer equivalent OrderDto (a so-called
&lt;a href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt;). Suppose also that an order has one or more Products and an associated Customer. Coincidentally, the OrderDto will have one or more ProductDtos and a corresponding CustomerDto. Now
 if you want to make sure that all the properties of all the objects in the OrderDto object graph match the equally named properties of the Order object graph, you can do this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order); &lt;/pre&gt;
&lt;p&gt;In contrast to the ShouldHave() extension method, the comparison is recursive by default and all properties of the OrderDto must be available on the Order. If not, an exception is thrown. You can override this behavior in different ways. For instance, you
 may only want to include the properties both object graphs have:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.ExcludingMissingProperties());&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also exclude certain (potentially deeply nested) properties using the Excluding() method.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Customer.Name));&lt;/pre&gt;
&lt;p&gt;Obviously, Excluding() and ExcludingMissingProperties() can be combined. Maybe farfetched, but you may even decide to exclude a property on a particular nested object by its index.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; 
    options.Excluding(o =&amp;gt; o.Products[1].Status)); &lt;/pre&gt;
&lt;p&gt;The Excluding() method on the options object also takes a lambda expression that offers a bit more flexibility for deciding what property to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Excluding(ctx =&amp;gt; ctx.PropertyPath == &lt;span class="str"&gt;&amp;quot;Level.Level.Text&amp;quot;&lt;/span&gt;)); &lt;/pre&gt;
&lt;p&gt;This expression has access to the property path, the property info and the subject’s run-time and compile-time type. You could also take a different approach and explicitly tell FA which properties to include.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Including(o =&amp;gt; o.OrderNumber)
    .Including(o =&amp;gt; o.Date)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Overriding and collections&lt;/strong&gt; &lt;br&gt;
In addition to influencing the properties that are including in the comparison, you can also override the actual assertion operation that is executed on a particular property.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000))
    .When(info =&amp;gt; info.PropertyPath.EndsWith(&lt;span class="str"&gt;&amp;quot;Date&amp;quot;&lt;/span&gt;))); &lt;/pre&gt;
&lt;p&gt;If you want to do this for all properties of a certain type, you can shorten the above call like this.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDto.ShouldBeEquivalentTo(order, options =&amp;gt; options 
    .Using&amp;lt;DateTime&amp;gt;(ctx =&amp;gt; ctx.Date.Should().BeCloseTo(ctx.Date, 1000)) 
    .WhenTypeIs&amp;lt;DateTime&amp;gt;(); &lt;/pre&gt;
&lt;p&gt;The original ShouldHave() extension method does support collections now, but it doesn’t allow you to influence the comparison based on the actual collection type. The new extension method ShouldAllBeEquivalentTo() does support that so you can now take the
 2nd example from the post and apply it on a collection of OrderDtos. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;orderDtos.ShouldAllBeEquivalentTo(orders, options =&amp;gt;   options.Excluding(o =&amp;gt; o.Customer.Name)); &lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Extensibility&lt;/strong&gt; &lt;br&gt;
Internally the comparison process consists of three phases. &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the properties of the subject object to include in the comparison. &lt;/li&gt;&lt;li&gt;Find a matching property on the expectation object and decide what to do if it can’t find any.
&lt;/li&gt;&lt;li&gt;Select the appropriate assertion method for the property’s type and execute it.
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Each of these phases is executed by one or more implementations of ISelectionRule, IMatchingRule and IAssertionRule that are maintained by the EquivalencyAssertionOptions. The ExcludePropertyByPredicateSelectionRule for example, is added to the collection
 of selection rules when you use the Excluding(property expression) method on the options parameter of ShouldBeEquivalentTo(). Even the Using().When() construct in the previous section is doing nothing more than inserting an AssertionRule&amp;lt;TSubject&amp;gt; in
 to the list of assertion rules. Creating your own rule is quite straightforward.&amp;nbsp;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Choose the appropriate phase that the rule should influence &lt;/li&gt;&lt;li&gt;Select the corresponding interface &lt;/li&gt;&lt;li&gt;Create a class that implements this interface &lt;/li&gt;&lt;li&gt;Add it to the ShouldBeEquivalentTo() call using the Using() method on the options parameters.
&lt;br&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldBeEquivalentTo(expected, options =&amp;gt; options.Using(&lt;span class="kwrd"&gt;new&lt;/span&gt; ExcludeForeignKeysSelectionRule()));&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;h2&gt;Property Comparison&lt;/h2&gt;
&lt;p&gt;You can assert the equality of entire objects by comparing their properties by name. This even works if the types of the properties differ but a built-in conversion exists (through the
&lt;span style="font-family:consolas"&gt;Convert&lt;/span&gt; class). As an example, consider a Customer entity from some arbitrary domain model and its
&lt;a href="http://en.wikipedia.org/wiki/Data_transfer_object"&gt;DTO&lt;/a&gt; counterpart &lt;span style="font-family:consolas"&gt;
CustomerDto&lt;/span&gt;. You can assert that the DTO has the same values as the entity using this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;As long as all properties of &lt;span style="font-family:consolas"&gt;dto&lt;/span&gt; are also available on
&lt;span style="font-family:consolas"&gt;customer&lt;/span&gt;, and their value is equal or convertible, the assertion succeeds. You can, however, exclude a specific property using a property expression, such as for instance the
&lt;span style="font-family:consolas"&gt;ID&lt;/span&gt; property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllPropertiesBut(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Which is equivalent to:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().AllProperties().But(d =&amp;gt; d.Id).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;The other way around is also possible. So if you only want to include two specific properties, use this syntax.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().Properties(d =&amp;gt; d.Name, d =&amp;gt; d.Address).EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;And finally, if you only want to compare the properties that both objects have, you can use the
&lt;span style="font-family:consolas"&gt;SharedProperties()&lt;/span&gt; method like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().EqualTo(customer);&lt;/pre&gt;
&lt;p&gt;Obviously, you can chain that with a &lt;span style="font-family:courier new"&gt;But()&lt;/span&gt; method to exclude some of the shared properties.&lt;/p&gt;
&lt;p&gt;Additionally, you can take structural comparison a level further by including the
&lt;span style="font-family:courier new"&gt;IncludingNestedObjects&lt;/span&gt; property. This will instruct the comparison to compare all (collections of) complex types that the properties of the subject (in this example) refer to. By default, it will assert that the
 nested properties of the subject match the nested properties of the expected object. However, if you do specify
&lt;span style="font-family:courier new"&gt;SharedProperties&lt;/span&gt;, then it will only compare the equally named properties between the nested objects. For instance:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;dto.ShouldHave().SharedProperties().IncludingNestedObjects.EqualTo(customer);&lt;/pre&gt;
&lt;h2&gt;Event Monitoring&lt;/h2&gt;
&lt;p&gt;Version 1.3.0 introduced a new set of extensions that allow you to verify that an object raised a particular event. Before you can invoke the assertion extensions, you must first tell Fluent Assertions that you want to monitor the object:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; EditCustomerViewModel();
subject.MonitorEvents();&lt;/pre&gt;
&lt;p&gt;Assuming that we’re dealing with a MVVM implementation, you might want to verify that it raised its
&lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; event for a particular property:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject
  .ShouldRaise(&lt;span class="str"&gt;&amp;quot;PropertyChanged&amp;quot;&lt;/span&gt;)&lt;br&gt;  .WithSender(subject)
  .WithArgs&amp;lt;PropertyChangedEventArgs&amp;gt;(args =&amp;gt; args.PropertyName == &lt;span class="str"&gt;&amp;quot;SomeProperty&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Notice that &lt;span style="font-family:consolas"&gt;WithSender()&lt;/span&gt; verifies that
&lt;strong&gt;all&lt;/strong&gt; occurrences had its &lt;span style="font-family:consolas"&gt;sender&lt;/span&gt; argument set to the specified object.
&lt;span style="font-family:consolas"&gt;WithArgs()&lt;/span&gt; just verifies that &lt;strong&gt;at least one&lt;/strong&gt; occurrence had a matching
&lt;span style="font-family:consolas"&gt;EventArgs&lt;/span&gt; object. In other words, event monitoring only works for events that comply with the standard two-argument
&lt;span style="font-family:consolas"&gt;sender&lt;/span&gt;/&lt;span style="font-family:consolas"&gt;args&lt;/span&gt; .NET pattern.&lt;/p&gt;
&lt;p&gt;Since verifying for &lt;span style="font-family:consolas"&gt;PropertyChanged&lt;/span&gt; events is so common, I’ve included a specialized shortcut to the example above:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;subject.ShouldRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/pre&gt;
&lt;p&gt;In version 1.4 you can also do the opposite; asserting that a particular event was not raised.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaisePropertyChangeFor(x =&amp;gt; x.SomeProperty);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Or, if your project is .NET 3.5 or 4.0 based:&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:consolas"&gt;subject.ShouldNotRaise(“SomeOtherEvent”);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Important Limitation&lt;/strong&gt;: Due to limitations in Silverlight, only the
&lt;span style="font-family:consolas"&gt;ShouldRaisePropertyChangeFor()&lt;/span&gt; and &lt;span style="font-family:consolas"&gt;
ShouldNotRaisePropertyChangeFor()&lt;/span&gt; methods are supported in the Silverlight version of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Type, Method and property assertions&lt;/h2&gt;
&lt;p&gt;Recently, we have added a number of assertions on types and on methods and properties of types. These are rather technical assertions and, although we like our unit tests to read as functional specifications for the application, we still see a use for assertions
 on the members of a class. For example when you use policy injection on your classes and require its methods to be virtual. Forgetting to make a method virtual will avoid the policy injection mechanism from creating a proxy for it, but you will only notice
 the consequences at runtime. Therefore it can be useful to create a unit test that asserts such requirements on your classes. Some examples.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Should().BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();

MethodInfo method = GetMethod();
method.Should().BeVirtual();

PropertyInfo property = GetSomeProperty();
property.Should().BeVirtual().And.BeDecoratedWith&amp;lt;SomeAttribute&amp;gt;();&lt;/pre&gt;
&lt;p&gt;You can also perform assertions on multiple methods or properties in a certain type by using the Methods() or Properties() extension methods and some optional filtering methods. Like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyPresentationModel).Methods()
  .ThatArePublicOrInternal 
  .ThatReturnVoid
  .Should()
  .BeVirtual(&lt;span class="str"&gt;&amp;quot;because this is required to intercept exceptions&amp;quot;&lt;/span&gt;);

&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyController).Methods()
  .ThatReturn&amp;lt;ActionResult&amp;gt;()
  .ThatAreDecoratedWith&amp;lt;HttpPostAttribute&amp;gt;()
  .Should()
  .BeDecoratedWith&amp;lt;ValidateAntiForgeryTokenAttribute&amp;gt;(&lt;br&gt;    &lt;span class="str"&gt;&amp;quot;because all Actions with HttpPost require ValidateAntiForgeryToken&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;You can even assert methods or properties from all types in an assembly that apply to certain filters, like this:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var types = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ClassWithSomeAttribute).Assembly.Types()
  .ThatAreDecoratedWith&amp;lt;SomeAttribute&amp;gt;()
  .ThatImplement&amp;lt;ISomeInterface&amp;gt;()
  .ThatAreInNamespace(&lt;span class="str"&gt;&amp;quot;Internal.Main.Test&amp;quot;&lt;/span&gt;);

var properties = types.Properties().ThatArePublicOrInternal;
properties.Should().BeVirtual();&lt;/pre&gt;
&lt;h2&gt;XML classes&lt;/h2&gt;
&lt;p&gt;Fluent Assertions has support for assertions on several of the LINQ-to-XML classes:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;xDocument.Should().HaveRoot(&lt;span class="str"&gt;&amp;quot;configuration&amp;quot;&lt;/span&gt;);
xDocument.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;settings&amp;quot;&lt;/span&gt;);

xElement.Should().HaveAttribute(&lt;span class="str"&gt;&amp;quot;age&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;36&amp;quot;&lt;/span&gt;);
xElement.Should().HaveElement(&lt;span class="str"&gt;&amp;quot;address&amp;quot;&lt;/span&gt;);

xAttribute.Should().HaveValue(&lt;span class="str"&gt;&amp;quot;Amsterdam&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;Note that these assertions require you to reference the &lt;span style="font-family:courier new"&gt;
System.Xml&lt;/span&gt; and &lt;span style="font-family:courier new"&gt;System.Xml.Linq&lt;/span&gt; assemblies.&lt;/p&gt;
&lt;h2&gt;Execution Time&lt;/h2&gt;
&lt;p&gt;New in version 1.4 is a method to assert that the execution time of particular method or action does not exceed a predefined value. To verify the execution time of a method, use the following syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;var subject = &lt;span class="kwrd"&gt;new&lt;/span&gt; SomePotentiallyVerySlowClass();
subject.ExecutionTimeOf(s =&amp;gt; s.ExpensiveMethod()).ShouldNotExceed(500.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Alternatively, to verify the execution time of an arbitrary action, use this syntax:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;Action someAction = () =&amp;gt; Thread.Sleep(510);
someAction.ExecutionTime().ShouldNotExceed(100.Milliseconds());&lt;/pre&gt;
&lt;p&gt;Since it doesn’t make sense to do something like that in Silverlight, it is only available in the .NET 3.5 and .NET 4.0 versions of Fluent Assertions.&lt;/p&gt;
&lt;h2&gt;Extensibility&lt;/h2&gt;
&lt;p&gt;Adding your own assertion extensions is quite straightforward and happens in my projects quite often. You have a few options though.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Extend one of the built-in classes such as CollectionAssertions&amp;lt;T&amp;gt;or ReferenceTypeAssertions&amp;lt;T&amp;gt; and expose them through a custom static class with extension methods named Should().
&lt;/li&gt;&lt;li&gt;Create extension methods that extend an assertion class: &lt;/li&gt;&lt;/ul&gt;
&lt;blockquote&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeWhatever&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; GenericCollectionAssertions&amp;lt;T&amp;gt; assertions, string reason, params object[] reasonArgs)
{ 
    Execute.Verification&lt;br&gt;       .ForCondition(&lt;em&gt;somecondition&lt;/em&gt;)&lt;br&gt;       .BecauseOf(reason, reasonArgs)&lt;br&gt;       .FailWith(&lt;span class="str"&gt;&amp;quot;Expected object not to be {0}{reason}&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create a custom assertions class and use the Verification class to verify conditions and create comprehensive failure messages using the built-in formatters.
&lt;/li&gt;&lt;/ul&gt;
&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>dennisdoomen</author><pubDate>Mon, 03 Sep 2012 17:47:31 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Documentation 20120903054731P</guid></item></channel></rss>