Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Main issue here is that you mix different layers. Repository is a intermediate level between Business Logic and storage. If your case, repository performs actions which are the part of Business logic. That's why you're forced to mimic that in your tests.</p> <p>In general your entity should be fully constructed prior to saving. Repository should only save it (probably, invoking Validate method, if you need that).</p> <p>This code:</p> <pre><code>couple.Bride.Gender = Gender.Female; couple.Groom.Gender = Gender.Male; </code></pre> <p>should be moved to Couple business logic (constructor, for example).</p> <p>From the more global point of view, with TDD you make mocks <em>around</em> the functionality you want to test. With your current approach you'll probably have something like <code>IView -&gt; Couple class -&gt; IRepository</code> chain. That means that by mocking those interfaces, you intend to test Couple class (or business logic work in general).</p> <p>To test the repository, you need a structure like <code>Couple class -&gt; CoupleRepository -&gt; IDatabaseDriver</code> sequence. By mocking <code>IDatabaseDriver</code> you'll be able to verify SqlCommands or Queries generated by real implementation of CoupleRepository.</p> <p>In that case you'll write tests like (very simplistic sample):</p> <pre><code>var driver = new MockDatabaseDriver(); var repo = CoupleRepository(MockDatabaseDriver); repo.Add(new Couple()); Assert.AreEquals("Insert into COUPLES values ('bride', groom')", driver.SqlQueryText); </code></pre> <p>Here MockDatabaseDriver doesn't execute queries, just indicates actions performed by repository.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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