Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p>The first approach is feasible, I have done something similar in the past when I wrote my own mapping framework that targeted RDBMS and <code>XmlWriter</code>/<code>XmlReader</code>. You can use this sort of approach to ease unit testing, though I think now we have superior OSS tools for doing just that.</p></li> <li><p>The second approach is what I currently use now with <a href="http://ibatis.apache.org/dotnetdownloads.cgi" rel="nofollow noreferrer">IBATIS.NET mappers</a>. Every mapper has an interface and every mapper [could] provide your basic CRUD operations. The advantage is each mapper for a domain class also has specific functions (such as <code>SelectByLastName</code> or <code>DeleteFromParent</code>) that are expressed by an interface and defined in the concrete mapper. Because of this there's no need for me to implement separate repositories as you're suggesting - our concrete mappers target the database. To perform unit tests I use <a href="http://structuremap.sourceforge.net/Default.htm" rel="nofollow noreferrer">StructureMap</a> and <a href="http://code.google.com/p/moq/" rel="nofollow noreferrer">Moq</a> to create in-memory repositories that operate as your <code>Memory*Repository</code> does. Its less classes to implement and manage and less work overall for a very testable approach. For data shared across unit tests I use a builder pattern for each domain class which has <code>WithXXX</code> methods and <code>AsSomeProfile</code> methods (the <code>AsSomeProfile</code> just returns a builder instance with preconfigured test data).</p></li> </ol> <p>Here's an example of what I usually end up with in my unit tests:</p> <pre><code>// Moq mocking the concrete PersonMapper through the IPersonMapper interface var personMock = new Mock&lt;IPersonMapper&gt;(MockBehavior.Strict); personMock.Expect(pm =&gt; pm.Select(It.IsAny&lt;int&gt;())).Returns( new PersonBuilder().AsMike().Build() ); // StructureMap's ObjectFactory ObjectFactory.Inject(personMock.Object); // now anywhere in my actual code where an IPersonMapper instance is requested from // ObjectFactory, Moq will satisfy the requirement and return a Person instance // set with the PersonBuilder's Mike profile unit test data </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload