<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Buy Amoksiklav (Amoxicillin) Without Prescription</title> <atom:link href="http://quickduck.com/blog/tag/equality/feed/" rel="self" type="application/rss+xml" /><link>http://quickduck.com/blog</link> <description>Straight from the mind of geniuseseses....</description> <lastBuildDate>Mon, 05 Mar 2012 22:26:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Buy Amoksiklav (Amoxicillin) Without Prescription</title><link>http://quickduck.com/blog/2009/08/25/unit-testing-expression-tree-equality/</link> <comments>http://quickduck.com/blog/2009/08/25/unit-testing-expression-tree-equality/#comments</comments> <pubDate>Tue, 25 Aug 2009 03:31:02 +0000</pubDate> <dc:creator>@benpriebe</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Unit Testing]]></category> <category><![CDATA[Comparison]]></category> <category><![CDATA[Equality]]></category> <category><![CDATA[Expression Trees]]></category> <category><![CDATA[Mocks]]></category> <category><![CDATA[Rhino]]></category><guid isPermaLink="false">http://quickduck.com/blog/?p=131</guid> <description><![CDATA[Buy Amoksiklav (Amoxicillin) Without Prescription, Sometimes you need to test whether two expressions are the same. Buy generic Amoksiklav (Amoxicillin), However when you do a simple AreEqual() test on two expressions that look the same you get a negative result. This method will fail [csharp] [TestMethod] public void TestDoesNotWork() { Expression&#60;Func&#60;int, buying Amoksiklav (Amoxicillin) online [...]]]></description> <content:encoded><![CDATA[<p> <b>Buy Amoksiklav (Amoxicillin) Without Prescription</b>, Sometimes you need to test whether two expressions are the same. <b>Buy generic Amoksiklav (Amoxicillin)</b>, However when you do a simple AreEqual() test on two expressions that look the same you get a negative result.</p><p><strong>This method will fail</strong><br /> [csharp]<br /> [TestMethod]<br /> public void TestDoesNotWork()<br /> {<br /> Expression&lt;Func&lt;int, <b>buying Amoksiklav (Amoxicillin) online over the counter</b>, <b>Amoksiklav (Amoxicillin) price, coupon</b>, int&gt;&gt; expressionA = x =&gt; x + 1;<br /> Expression&lt;Func&lt;int, int&gt;&gt; expressionB = x =&gt; x + 1;</p><p> Assert.AreEqual(expressionA, <b>Amoksiklav (Amoxicillin) treatment</b>, <b>Amoksiklav (Amoxicillin) use</b>, expressionB);<br /> }<br /> [/csharp]</p><p>This looks like it should work however it doesn't. This is because when using anonymous expressions/delegates the CLR does some magic behind the scene to add a method on the fly, <b>Amoksiklav (Amoxicillin) natural</b>, <b>Amoksiklav (Amoxicillin) coupon</b>, creating a new instance for every anonymous expression/delegate.</p><p>So if you have two expressions that are syntactically the same but not the same reference the easiest way to ensure they are the same is to compile the expression and invoke it comparing the resultant value, <b>cheap Amoksiklav (Amoxicillin)</b>.</p><p>[csharp]<br /> [TestMethod]<br /> public void TestDoesWork()<br /> {<br /> Expression&lt;Func&lt;int, int&gt;&gt; expressionA = x =&gt; x + 1;<br /> Expression&lt;Func&lt;int, int&gt;&gt; expressionB = x =&gt; x + 1;</p><p> Assert.AreEqual(expressionA.Compile().Invoke(3), expressionB.Compile().Invoke(3));<br /> }<br /> [/csharp]</p><p>An alternate approach would be to de-construct each constituent part of the expression trees comparing each part as you go, <b>Buy Amoksiklav (Amoxicillin) Without Prescription</b>. <b>Amoksiklav (Amoxicillin) no rx</b>, This however is far more complex.</p><p>For a more real world example that involves using Rhino mocks and Expect calls please read on:</p><p></p><p></p><p>When using Rhino Mocks and setting up an Expect call on a method that takes an expression you will most likely find that the Expect assertion always fails, <b>after Amoksiklav (Amoxicillin)</b>. <b>Amoksiklav (Amoxicillin) for sale</b>, <strong> The class that will be mocked out.</strong><br /> This class will have the method on it that takes an expression.<br /> [csharp]<br /> public class Repository<br /> {<br /> public virtual void Get&lt;TEntity&gt;(Expression&lt;Func&lt;TEntity, <b>Amoksiklav (Amoxicillin) gel, ointment, cream, pill, spray, continuous-release, extended-release</b>, <b>Buy Amoksiklav (Amoxicillin) from canada</b>, bool&gt;&gt; whereCondition)<br /> {<br /> // Actual logic.<br /> }<br /> }<br /> [/csharp]</p><p><strong>The class we are unit testing</strong><br /> [csharp]<br /> public class UserManager<br /> {<br /> public Repository Repo { get; set; }</p><p> public void GetUserById(int id)<br /> {<br /> Repo.Get&lt;User&gt;(x =&gt; x.Id == id);<br /> }<br /> }<br /> [/csharp]</p><p><strong>Supporting classes</strong><br /> [csharp]<br /> public class User<br /> {<br /> public int Id { get; set;  }<br /> public int Name { get; set; }<br /> }<br /> [/csharp]</p><p>For our unit test we want to test that when we call the GetUserById() method on the UserManager class that we Expect the Repository.Get<TEntity>() method will be called with an expected expression value, <b>where can i buy cheapest Amoksiklav (Amoxicillin) online</b>. <b>Where can i buy Amoksiklav (Amoxicillin) online</b>, <strong>Unit Test</strong><br /> [csharp]<br /> [TestMethod]<br /> public void Test()<br /> {<br /> // Arrange<br /> UserManager manager = new UserManager { Repo = MockRepository.GenerateMock&lt;Repository&gt;() };<br /> manager.Repo.Expect(r =&gt; r.Get&lt;User&gt;(x =&gt; x.Id == 3));</p><p> // Act<br /> manager.GetUserById(3);</p><p> // Assert<br /> manager.Repo.VerifyAllExpectations();<br /> }<br /> [/csharp]</p><p>This looks like it should work however it won't.</p><p>So using the approach listed earlier we can test that the method with an expression is called with the correct value by compiling and invoking the expected expression and the actual expression that was called and comparing their values, <b>Amoksiklav (Amoxicillin) treatment</b>. <b>Amoksiklav (Amoxicillin) dose</b>, [csharp]<br /> [TestMethod]<br /> public void TestExpressionCalled()<br /> {<br /> // Arrange<br /> UserManager manager = new UserManager { Repo = MockRepository.GenerateMock&lt;Repository&gt;() };</p><p> // Act<br /> manager.GetUserById(3);</p><p> // Assert<br /> Expression&lt;Func&lt;User, bool&gt;&gt; expected = x =&gt; x.Id == 3;<br /> Expression&lt;Func&lt;User, <b>order Amoksiklav (Amoxicillin) from mexican pharmacy</b>, <b>Amoksiklav (Amoxicillin) dangers</b>, bool&gt;&gt; actual = (Expression&lt;Func&lt;User, bool&gt;&gt;)manager.Repo.GetArgumentsForCallsMadeOn(r =&gt; r.Get&lt;User&gt;(null))[0][0];</p><p> User user = new User { Id = 3 };<br /> Assert.AreEqual(expected.Compile().Invoke(user), <b>Amoksiklav (Amoxicillin) photos</b>, <b>Is Amoksiklav (Amoxicillin) addictive</b>, actual.Compile().Invoke(user));<br /> }<br /> [/csharp]<br /> .  Cheap Amoksiklav (Amoxicillin).  Amoksiklav (Amoxicillin) brand name.  Generic Amoksiklav (Amoxicillin).  Order Amoksiklav (Amoxicillin) from United States pharmacy.  Online buying Amoksiklav (Amoxicillin).  Purchase Amoksiklav (Amoxicillin) online no prescription.  Amoksiklav (Amoxicillin) steet value.  Online Amoksiklav (Amoxicillin) without a prescription.  Order Amoksiklav (Amoxicillin) online overnight delivery no prescription.  Amoksiklav (Amoxicillin) use.  Amoksiklav (Amoxicillin) mg.  Buy generic Amoksiklav (Amoxicillin).  Real brand Amoksiklav (Amoxicillin) online.  Amoksiklav (Amoxicillin) dosage.</p><p></p><p><b>Similar posts:</b> <a href='http://quickduck.com/blog/?p=412'>Buy Amoxycillin (Amoxicillin) Without Prescription</a>. <a href='http://quickduck.com/blog/?p=9'>Buy Ultracet (Ultram) Without Prescription</a>. <a href='http://quickduck.com/blog/?p=42'>Finara (Propecia) For Sale</a>. <a href='http://quickduck.com/blog/?p=32'>Aerolin (Ventolin) duration</a>. <a href='http://quickduck.com/blog/?p=402'>My Albuterol (Ventolin) experience</a>. <a href='http://quickduck.com/blog/?p=4'>Where can i order Ultram ER (Tramadol) without prescription</a>.<br /> <b>Trackbacks from:</b> <a href='http://e-flyfishingtrips.com/?p=3934'>Buy Amoksiklav (Amoxicillin) Without Prescription</a>. <a href='http://bassfishingheaven.com/?p=4883'>Buy Amoksiklav (Amoxicillin) Without Prescription</a>. <a href='http://gastonalive.com/?p=195'>Buy Amoksiklav (Amoxicillin) Without Prescription</a>. <a href='http://lowechiro.com/?p=382'>Amoksiklav (Amoxicillin) recreational</a>. <a href='http://crosstrainfitness.com/?p=1001'>What is Amoksiklav (Amoxicillin)</a>. <a href='http://weblog.cazucito.com/?p=584'>Generic Amoksiklav (Amoxicillin)</a>.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2009/08/25/unit-testing-expression-tree-equality/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: quickduck.com @ 2012-05-22 12:01:58 -->
