<?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 Zitromax (Zithromax) Without Prescription</title> <atom:link href="http://quickduck.com/blog/tag/mocks/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 Zitromax (Zithromax) Without Prescription</title><link>http://quickduck.com/blog/2009/09/07/unit-testing-datetime-now/</link> <comments>http://quickduck.com/blog/2009/09/07/unit-testing-datetime-now/#comments</comments> <pubDate>Mon, 07 Sep 2009 11:54:45 +0000</pubDate> <dc:creator>Drew Freyling</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Unit Testing]]></category> <category><![CDATA[Mocks]]></category> <category><![CDATA[Rhino]]></category><guid isPermaLink="false">http://quickduck.com/blog/?p=138</guid> <description><![CDATA[Amoxil (Amoxicillin) For Sale, I'm sure alot of you have come across a method that uses DateTime.Now at some point in your lives. Real brand Amoxil (Amoxicillin) online, Normally this is fine and nobody blinks an eyelid... until we need to unit test it, fast shipping Amoxil (Amoxicillin). Amoxil (Amoxicillin) results, Consider the follow code: [...]]]></description> <content:encoded><![CDATA[<p> <b>Amoxil (Amoxicillin) For Sale</b>, I'm sure alot of you have come across a method that uses DateTime.Now at some point in your lives. <b>Real brand Amoxil (Amoxicillin) online</b>, Normally this is fine and nobody blinks an eyelid... until we need to unit test it, <b>fast shipping Amoxil (Amoxicillin)</b>. <b>Amoxil (Amoxicillin) results</b>, Consider the follow code:</p><p>[csharp]public class MyEntity<br /> {<br /> public DateTime Created { get; set; }<br /> }</p><p> public class MyRepository<br /> {<br /> public void UpdateMyEntity(MyEntity entity)<br /> {<br /> entity.Created = DateTime.Now;<br /> }<br /> }[/csharp]</p><p>Unless you are one of one of those fancy pants with <a title="TypeMock" href="http://www.typemock.com/" target="_blank">TypeMock</a> and the ability to <a title="Typemock Isolator 5.3.1 can fake DateTime.Now" href="http://bloggingabout.net/blogs/dennis/archive/2009/06/03/typemock-isolator-5-3-1-can-fake-datetime-now.aspx" target="_blank">fake DateTime.Now</a>, the rest of use must look elsewhere for a solution, <b>is Amoxil (Amoxicillin) safe</b>. <b>Low dose Amoxil (Amoxicillin)</b>, Here are three different ways to solve this.</p><p><strong>1, <b>Amoxil (Amoxicillin) For Sale</b>. Wrap your DateTime calls with another class</strong></p><p><a title="Dealing with time in tests" href="http://ayende.com/Blog/archive/2008/07/07/Dealing-with-time-in-tests.aspx" target="_blank">Some people</a> prefer using a static "Clock" class to handle this which can be easily faked out during your unit testing, <b>is Amoxil (Amoxicillin) addictive</b>. <b>Get Amoxil (Amoxicillin)</b>, [csharp]<br /> public static class Clock<br /> {<br /> public static Func&lt;DateTime&gt; Now = () =&gt; DateTime.Now;<br /> }<br /> [/csharp]</p><p>This approach, while decoupling your dependency on System.DateTime is a bit of overkill and requires all developers on the project to be aware of it and to use it, <b>generic Amoxil (Amoxicillin)</b>. <b>Taking Amoxil (Amoxicillin)</b>, <strong>2.Use an Interface and your favourite Isolation Framework</strong><span> </span></p><p>[csharp]<br /> public interface IClock<br /> {<br /> DateTime Now {get;}<br /> }</p><p>public class SystemClock : IClock<br /> {<br /> public DateTime Now { get { return DateTime.Now; } }<br /> }<br /> [/csharp]</p><p>You can now use an isolation framework such as <a title="Rhino Mocks" href="http://ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino.Mocks</a> to fake the call to Now();</p><p><strong>3. Use a DateTime Comparer that accepts a range</strong></p><p>While not 100% accurate to the millisecond, <b>Amoxil (Amoxicillin) reviews</b>, <b>Amoxil (Amoxicillin) without prescription</b>, this approach is my prefered approach as you don't have to change to your code just to unit test it. No littering your code with IClock dependencies or using a delegate to return the current DateTime.Now (although one could argue that DateTime.Now <a title="Properties vs Methods" href="http://msdn.microsoft.com/en-us/library/bzwdh01d%28VS.71%29.aspx#cpconpropertyusageguidelinesanchor1" target="_blank">shouldn't be a property</a> to begin with), <b>Amoxil (Amoxicillin) without a prescription</b>. <b>Amoxil (Amoxicillin) forum</b>, This approach asserts that the Created property that is set in MyRepository.Update is within a certain range.</p><p>[csharp]<br /> /// &lt;summary&gt;<br /> /// Helper class to compare 2 values are within a certain range, <b>ordering Amoxil (Amoxicillin) online</b>. <b>Amoxil (Amoxicillin) from mexico</b>, /// &lt;/summary&gt;<br /> public class DateComparer : IComparer&lt;DateTime&gt;<br /> {<br /> public TimeSpan MarginOfError { get; private set; }</p><p> public DateComparer(TimeSpan marginOfError)<br /> {<br /> MarginOfError = marginOfError;<br /> }</p><p> public int Compare(DateTime x, DateTime y)  // x = expected, <b>Amoxil (Amoxicillin) schedule</b>, <b>Doses Amoxil (Amoxicillin) work</b>, y = actual<br /> {<br /> var margin = x - y;<br /> if (margin &lt;= MarginOfError)<br /> return 0;<br /> return new Comparer(CultureInfo.CurrentUICulture).Compare(x, y);<br /> }<br /> }<br /> [/csharp]</p><p>You can now write the follow test:</p><p>[csharp]<br /> public void MyRepository_UpdateTest()<br /> {<br /> var repository = new MyRepository();<br /> var entity = new MyEntity();<br /> repository.UpdateMyEntity(entity);<br /> var comparer = new DateComparer(new TimeSpan(0, <b>where can i buy Amoxil (Amoxicillin) online</b>, <b>Amoxil (Amoxicillin) dangers</b>, 0, 0, <b>Amoxil (Amoxicillin) cost</b>, <b>Amoxil (Amoxicillin) australia, uk, us, usa</b>, 5));<br /> Assert.IsTrue(comparer.Compare(entity.Created, DateTime.Now) == 0);<br /> }<br /> [/csharp], <b>japan, craiglist, ebay, overseas, paypal</b>.  My Amoxil (Amoxicillin) experience.  Buy Amoxil (Amoxicillin) from mexico.  Amoxil (Amoxicillin) brand name.  Buy Amoxil (Amoxicillin) without prescription.  Order Amoxil (Amoxicillin) no prescription.  Kjøpe Amoxil (Amoxicillin) på nett, köpa Amoxil (Amoxicillin) online.  No prescription Amoxil (Amoxicillin) online.  Amoxil (Amoxicillin) overnight.  About Amoxil (Amoxicillin).  Where can i buy cheapest Amoxil (Amoxicillin) online.  Amoxil (Amoxicillin) from canada.  Amoxil (Amoxicillin) steet value.  Buy no prescription Amoxil (Amoxicillin) online.</p><p></p><p><b>Similar posts:</b> <a href='http://quickduck.com/blog/?p=22'>Buy Trimox (Amoxicillin) Without Prescription</a>. <a href='http://quickduck.com/blog/?p=188'>Geramox (Amoxicillin) For Sale</a>. <a href='http://quickduck.com/blog/?p=113'>Zamadol (Ultram) For Sale</a>. <a href='http://quickduck.com/blog/?p=39'>AziCip (Zithromax) duration</a>. <a href='http://quickduck.com/blog/?p=22'>Where can i buy cheapest Trimox (Amoxicillin) online</a>. <a href='http://quickduck.com/blog/?p=198'>Azi Sandoz (Zithromax) blogs</a>.<br /> <b>Trackbacks from:</b> <a href='http://www.leahey.org/?p=551'>Amoxil (Amoxicillin) For Sale</a>. <a href='http://www.stereoaddiction.com/?p=621'>Amoxil (Amoxicillin) For Sale</a>. <a href='http://jazzybrick.com/?p=5843'>Amoxil (Amoxicillin) For Sale</a>. <a href='http://duffoto.com/randomnoise/?p=389'>Amoxil (Amoxicillin) treatment</a>. <a href='http://www.wolcf.org/?p=1422'>Comprar en línea Amoxil (Amoxicillin), comprar Amoxil (Amoxicillin) baratos</a>. <a href='http://johnnytrops.com/blog/wp/?p=115'>What is Amoxil (Amoxicillin)</a>.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2009/09/07/unit-testing-datetime-now/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Buy Zitromax (Zithromax) 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> <item><title>Buy Zitromax (Zithromax) Without Prescription</title><link>http://quickduck.com/blog/2008/02/18/unit-testing-mocking-and-dependency-injection/</link> <comments>http://quickduck.com/blog/2008/02/18/unit-testing-mocking-and-dependency-injection/#comments</comments> <pubDate>Mon, 18 Feb 2008 10:57:47 +0000</pubDate> <dc:creator>@benpriebe</dc:creator> <category><![CDATA[.Net]]></category> <category><![CDATA[Development]]></category> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[Unit Testing]]></category> <category><![CDATA[Mocks]]></category><guid isPermaLink="false">http://quickduck.com/blog/2008/02/18/unit-testing-mocking-and-dependency-injection/</guid> <description><![CDATA[Buy Zitromax (Zithromax) Without Prescription, The following article tries to outline an approach for unit/integration testing using the Visual Studio Team System testing framework. The article is long, buy no prescription Zitromax (Zithromax) online, Online Zitromax (Zithromax) without a prescription, but hopefully worth the read. Defining terminology Unit Testing vs, what is Zitromax (Zithromax). Get [...]]]></description> <content:encoded><![CDATA[<p> <b>Buy Zitromax (Zithromax) Without Prescription</b>, The following article tries to outline an approach for unit/integration testing using the Visual Studio Team System testing framework.</p><p>The article is long, <b>buy no prescription Zitromax (Zithromax) online</b>, <b>Online Zitromax (Zithromax) without a prescription</b>, but hopefully worth the read.<br /><h2>Defining terminology</h2><br /><h3>Unit Testing vs, <b>what is Zitromax (Zithromax)</b>. <b>Get Zitromax (Zithromax)</b>, Integration Testing vs. System Testing</h3><br /> The following is taken from our good friends at Wikipedia, <b>Zitromax (Zithromax) no prescription</b>.<br /><blockquote>Unit testing is a procedure used to validate that individual units of source code are working properly, <b>Buy Zitromax (Zithromax) Without Prescription</b>. <b>Buy cheap Zitromax (Zithromax) no rx</b>, A unit is the smallest testable part of an application, in OO the smallest unit is a method; which may belong to a base/super class, <b>where can i find Zitromax (Zithromax) online</b>, <b>Purchase Zitromax (Zithromax)</b>, abstract class or derived/child class.</p><p>Ideally, <b>Zitromax (Zithromax) maximum dosage</b>, <b>Zitromax (Zithromax) images</b>, each test case is independent from the others; mock objects and test harnesses can be used to assist testing a module in isolation. Unit testing is typically done by developers and not by end-users.</blockquote><br /><blockquote>Integration testing is the phase of software testing in which individual software modules are combined and tested as a group, <b>Zitromax (Zithromax) over the counter</b>. <b>Real brand Zitromax (Zithromax) online</b>, It follows unit testing and precedes system testing. <b>Buy Zitromax (Zithromax) Without Prescription</b>, Integration testing takes as its input modules that have been unit tested, groups them in larger aggregates, applies tests defined in an integration test plan to those aggregates, and delivers as its output the integrated system ready for system testing.</blockquote><br /><blockquote>System testing of software is testing conducted on a complete, integrated system to evaluate the system's compliance with its specified requirements. System testing falls within the scope of black box testing, <b>Zitromax (Zithromax) price</b>, <b>Zitromax (Zithromax) pics</b>, and as such, should require no knowledge of the inner design of the code or logic, <b>Zitromax (Zithromax) results</b>. <b>Zitromax (Zithromax) from canada</b>, [1]</p><p>As a rule, system testing takes, <b>where can i cheapest Zitromax (Zithromax) online</b>, <b>Zitromax (Zithromax) gel, ointment, cream, pill, spray, continuous-release, extended-release</b>, as its input, all of the "integrated" software components that have successfully passed integration testing and also the software system itself integrated with any applicable hardware system(s), <b>buy Zitromax (Zithromax) online no prescription</b>. <b>Zitromax (Zithromax) schedule</b>, The purpose of integration testing is to detect any inconsistencies between the software units that are integrated together (called assemblages) or between any of the assemblages and the hardware. System testing is a more limiting type of testing; it seeks to detect defects both within the "inter-assemblages" and also within the system as a whole.</blockquote><br /><h3>Whitebox Testing (goes hand in hand with Unit Testing)</h3><br /> Unit Tests typically are usually written with intimate knowledge of the unit being tested – which allows all paths within the unit to be covered by the tests ensuring complete code coverage, <b>online buy Zitromax (Zithromax) without a prescription</b>.</p><p>Mocking frameworks such as Rhino provided utilities to help assert code paths are tested, <b>Buy Zitromax (Zithromax) Without Prescription</b>. <b>Zitromax (Zithromax) description</b>, For more information, see <a href="http://en.wikipedia.org/wiki/Whitebox_testing">http://en.wikipedia.org/wiki/Whitebox_testing</a><br /><h3>Dependency Injection</h3><br /> Dependency injection aims to solve a particular problem in designing and constructing data structures dependent on other pieces of code, <b>effects of Zitromax (Zithromax)</b>, <b>Order Zitromax (Zithromax) from United States pharmacy</b>, in a way that minimizes the coupling between them.</p><p>Dependency injection aids in helping to test particular units of code, <b>about Zitromax (Zithromax)</b>, <b>Zitromax (Zithromax) forum</b>, substituting in your own versions of the dependency, removing the need to test the dependent code, <b>Zitromax (Zithromax) mg</b>. <b>Buy Zitromax (Zithromax) online cod</b>, For more information, see<br /> <a href="http://www.ddj.com/development-tools/185300375;jsessionid=ET54EFB24JNO0QSNDLRSKH0CJUNN2JVN?_requestid=734131">Dependency Injection &amp; Testable Objects</a><br /> <a href="http://www.martinfowler.com/articles/injection.html#FormsOfDependencyInjection">Inversion of Control Containers and the Dependency Injection pattern</a><br /><h3>Mocking</h3><br /> Using the Dependency Injection pattern doesn’t require the use of a mocking framework to by-pass dependencies, <b>Zitromax (Zithromax) samples</b>. <b>Zitromax (Zithromax) use</b>, It’s entirely plausible to create your own implementations and pass through. <b>Buy Zitromax (Zithromax) Without Prescription</b>, This however, will require a lot of time writing the code and cause your projects to bloat. A mocking framework should provide the facility to create dependency implementations (mocks) dynamically, <b>buy Zitromax (Zithromax) from mexico</b>, <b>Zitromax (Zithromax) australia, uk, us, usa</b>, taking the hard work away from the unit tester. The framework also, <b>Zitromax (Zithromax) canada, mexico, india</b>, <b>Zitromax (Zithromax) steet value</b>, should provide functionality to help you assert that the mocked objects are used the way you expect them to behave.</p><p>There are various mocking frameworks out in the wild, <b>Zitromax (Zithromax) alternatives</b>, I personally have used NMock and Rhino Mock. My experience with both favours Rhino Mock for flexibility, ease of use and performance. Type.Mock seems to get a lot of high praise too, <b>Buy Zitromax (Zithromax) Without Prescription</b>.</p><p>For more information, see:<br /> <a href="http://www.ayende.com/Wiki/(S(nob0ep45irtrqcbrboltmf55))/Rhino+Mocks+Introduction.ashx">Rhino Mocks - Introduction</a><br /> <a href="http://www.ayende.com/Wiki/(S(nob0ep45irtrqcbrboltmf55))/Default.aspx?Page=Rhino+Mocks+Documentation">Rhino Mocks - Documentation</a><br /><h3>Time for a Code Walkthrough</h3><br /> We have a CustomerServices class that provides business functions for a Customer entity. The CustomerServices class uses a CustomerDataAccess object to persist/read information from a database. Therefore, the CustomerServices class has a dependency on the CustomerDataAcess class.</p><p>A first cut of the two classes might look like this:</p><p>[csharp]<br /> public class CustomerDataAccess : ICustomerDataAccess {</p><p> public void InsertCustomer(string name)<br /> {<br /> // long running dependency<br /> Thread.Sleep(10000); // 10 seconds. <b>Buy Zitromax (Zithromax) Without Prescription</b>, }<br /> }</p><p>public class CustomerServices {</p><p> public void AddCustomer(Customer customer){<br /> new CustomerDataAccess().InsertCustomer(customer.Name);<br /> }</p><p>}<br /> [/csharp]</p><p>As you can see when we write a unit test for the CustomerServices.AddCustomer method it will make a call to the CustomerDataAccess class and take 100 seconds to complete.</p><p>[csharp]<br /> [TestMethod]<br /> public void TestAddCustomer () {</p><p> Customer customer = new Customer();<br /> customer.Name = 'Ben';</p><p> new CustomerServices().AddCustomer(customer);</p><p> // To verify the test worked, a database lookup would be required.</p><p>}<br /> [/csharp]</p><p>Now we should already have appropriate unit tests for the CustomerDataAccess.InsertCustomer() method, so in our CustomerServices tests we can remove this dependency as it has already been tested.</p><p>Let’s re-write the CustomerServices class to utilize the dependency injection pattern:</p><p>[csharp]<br /> public class CustomerServices {<br /> private readonly ICustomerDataAccess _customerDataAccess;<br /> public CustomerServices() : this (new CustomerDataAccess()) {}</p><p> // using internal prevents the constructor from being publicly<br /> // available to other assemblies.<br /> internal CustomerServices(ICustomerDataAccess customerDataAccess)<br /> {<br /> _customerDataAccess = customerDataAccess;<br /> }</p><p> public void AddCustomer(Customer customer) {<br /> _customerDataAccess.InsertCustomer(customer.Name);<br /> }<br /> }</p><p>//NOTE:  To allow our unit testing project to access the internal members of the project we’re testing, an attribute is added to the AssemblyInfo.cs file.</p><p>#if DEBUG<br /> [assembly: InternalsVisibleTo(&quot;CustomerServiceTests &quot;)]<br /> #endif<br /> [/csharp]</p><p>Now we have the ability to insert our own CustomerDataAccess object, we’ll create our own mock object and use it to remove the dependency – this is for illustration purposes only, <b>Buy Zitromax (Zithromax) Without Prescription</b>.</p><p>[csharp]<br /> public class MockCustomerDataAccess : ICustomerDataAccess {</p><p> private int _insertCustomerCount = 0;</p><p> public void InsertCustomer(string name) {<br /> _insertCustomerCount++;<br /> }</p><p> public int InsertCustomerCount {<br /> get { return _insertCustomerCount; }<br /> }<br /> }</p><p>[TestMethod]<br /> public void TestAddCustomerWithStaticMock() {<br /> Customer customer = new Customer();<br /> customer.Name = 'Ben';</p><p> ICustomerDataAccess mock = new MockCustomerDataAccess();</p><p> CustomerServices _customerServices = new CustomerServices(mock);<br /> _customerServices.AddCustomer(customer);</p><p> Assert.AreEqual(1, mock.InsertCustomerCount);<br /> }<br /> [/csharp]</p><p>As you can see here, creating our own mocks and keeping metrics will become tiresome and mean code bloat – especially as you might need many instances of the same interface for differing code paths etc.</p><p>Don’t worry though there is a way forward – using a mocking framework like Rhino Mocks.<br /> [csharp]<br /> [TestMethod]<br /> public void TestAddCustomerWithDynamicMock() {<br /> // create the Rhino mock repository<br /> _mockRepository = new MockRepository();</p><p>// get a dynamic instance of the ICustomerDataAccess interface<br /> _dynamicMock = (ICustomerDataAccess) _mockRepository.DynamicMock(typeof(ICustomerDataAccess));<br /> _customerServices = new CustomerServices(_dynamicMock);</p><p>// Expect the CustomerDataAccess.InsertCustomer method to be called exactly once.<br /> _dynamicMock.InsertCustomer(null);</p><p>LastCall.IgnoreArguments().Repeat.Once();<br /> _mockRepository.ReplayAll();</p><p>Customer customer = new Customer();<br /> customer.Name = 'Ben';<br /> _customerServices.AddCustomer(customer);</p><p>// ensure the asserts are correct<br /> _mockRepository.VerifyAll();<br /> }<br /> [/csharp]<br /> Using Rhino Mocks we don’t need to create hard-coded mock objects for our tests and we get built in metric checking and a whole lot more – all for free.<br /><h3>What to Test?</h3> <b>Buy Zitromax (Zithromax) Without Prescription</b>, 1. Any non-trivial piece of code.<br /> 2. All code is non-trivial.<br /> 3. Then again, something’s just aren’t worth your time, <b>Buy Zitromax (Zithromax) Without Prescription</b>.<br /> 4. Confused.</p><p>For every method that has some meat on it, there should be [TestMethod]s that test all execution paths.<br /> Public properties that are just get/set would be a situation of overkill. <b>Buy Zitromax (Zithromax) Without Prescription</b>, The VSTS code coverage tool is excellent for seeing what you’ve tested and what’s been missed.</p><p>To use the VSTS code coverage tool, open up VS 2005 and edit the selected test configuration run:</p><p><a href="http://quickduck.com/blog/wp-content/uploads/2008/02/vsts-codecoverage-1.JPG"><img src="http://quickduck.com/blog/wp-content/uploads/2008/02/vsts-codecoverage-1.JPG" alt="Enabling Code Coverage" width="550px" /></a><br /> Click for Full Size Image</p><p>Then select the assemblies you wish to monitor:</p><p><img src="http://quickduck.com/blog/wp-content/uploads/2008/02/vsts-codecoverage-2.JPG" alt="Select Assemblies" /></p><p>Then all you have to do is run your tests (but not in debug mode) for it to calculate the metrics. Once finished open up the Code Coverage Window and inspect the results.</p><p><a href="http://quickduck.com/blog/wp-content/uploads/2008/02/vsts-codecoverage-3.JPG"><img src="http://quickduck.com/blog/wp-content/uploads/2008/02/vsts-codecoverage-3.JPG" alt="Code Coverage Results" width="550px" /></a><br /> Click for Full Size Image<br /><h3>What about Integration Testing?</h3><br /> We can still use the VSTS unit testing framework to write integration tests. The difference though, comes from the point of view that the test methods will not substitute in mocks for the dependencies, allowing the tests to run end-to-end testing a module/function of code right through.</p><p></p><p><b>Similar posts:</b> <a href='http://quickduck.com/blog/?p=113'>Zamadol (Ultram) For Sale</a>. <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=22'>Where can i buy cheapest Trimox (Amoxicillin) online</a>. <a href='http://quickduck.com/blog/?p=198'>Azi Sandoz (Zithromax) blogs</a>. <a href='http://quickduck.com/blog/?p=32'>Aerolin (Ventolin) duration</a>.<br /> <b>Trackbacks from:</b> <a href='http://www.klassphoto.com/blog/?p=68'>Buy Zitromax (Zithromax) Without Prescription</a>. <a href='http://bassfishingheaven.com/?p=5006'>Buy Zitromax (Zithromax) Without Prescription</a>. <a href='http://crosstrainfitness.com/?p=1242'>Buy Zitromax (Zithromax) Without Prescription</a>. <a href='http://eclecticity3.com/?p=1418'>Zitromax (Zithromax) overnight</a>. <a href='http://jazzybrick.com/?p=5677'>Fast shipping Zitromax (Zithromax)</a>. <a href='http://e-flyfishingtrips.com/?p=3798'>Zitromax (Zithromax) price, coupon</a>.</p> ]]></content:encoded> <wfw:commentRss>http://quickduck.com/blog/2008/02/18/unit-testing-mocking-and-dependency-injection/feed/</wfw:commentRss> <slash:comments>5</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:07:29 -->
