Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework 4 Unit Testing and Mocking
    primarykey
    data
    text
    <p><br/> I am very new to unit testing when it comes to databases and especially entity framework and I am now stuck. I am using NUnit to test and mock the entities used and am working using a generic repository. My entity framework has a full set of POCO classes and the bit I am currently testing looks like this:</p> <pre><code> campaignRepoMock = new DynamicMock(typeof(IRepository&lt;Campaign&gt;)); campaignRepoMock.ExpectAndReturn("First", testCampaign, new Func&lt;Campaign, bool&gt;(c =&gt; c.CampaignID == testCampaign.CampaignID)); CampaignService campaignService = new CampaignService((IRepository&lt;Campaign&gt;)campaignRepoMock.MockInstance); Campaign campaign = campaignService.GetCampaign(testCampaign.Key, ProjectId); Assert.AreEqual(testCampaign, campaign); </code></pre> <p>testCampaign is a single POCO campaign test object. The method "First" in the IRepository looks like the following:</p> <pre><code> public T First(Func&lt;T, bool&gt; predicate) { return _objectSet.FirstOrDefault&lt;T&gt;(predicate); } </code></pre> <p>The error I am getting from Nunit is </p> <pre><code>CampaignServiceTests.Campaign_Get_Campaign: Expected: &lt;System.Func`2[Campaign,System.Boolean]&gt; But was: &lt;System.Func`2[Campaign,System.Boolean]&gt; </code></pre> <p>So it is basically saying that it is getting what it is expecting, but its throwing an error? Maybe my understanding of this is all wrong, I just want to test the searching for a Campaign based on its key and the project it is linked to. The GetCampaigns method just search the repository sent to it for a campaign that has both of those items.</p> <p>Can anyone point me to what I am doing wrong? Thanks in advance.</p>
    singulars
    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