Note that there are some explanatory texts on larger screens.

plurals
  1. PORhino Mock Entity Framework using UnitofWork Pattern not working
    primarykey
    data
    text
    <p>This is my first attempt at something like this, so hopefully this is simple.</p> <p>I have created a WCF service which uses Entity Framework to access the database. I have implemented a <em>UnitOfWork</em> interface so my service can use EF while still being testable.</p> <p>Here is my service:</p> <pre><code>public class ProjectService : IProjectService { private IUnitOfWork db = null; public ProjectService(IUnitOfWork unitofwork) { db = unitofwork; } public int RegisterSite(int CPUID) { if (db.Servers.Count(x =&gt; x.CPUID == CPUID) &gt; 0) { // do something } return 0; } } </code></pre> <p>Here is my UnitOfWork interface:</p> <pre><code>public interface IUnitOfWork { IObjectSet&lt;tblClient&gt; Clients { get; } IObjectSet&lt;tblServer&gt; Servers { get; } IObjectSet&lt;tblSite&gt; Sites { get; } IObjectSet&lt;tblServerLog&gt; ServerLogs { get; } void Commit(); } </code></pre> <p>When I use this Service with either concrete implementations of a <code>SQLUnitOfWork</code> (using EF) or with a <code>InMemoryUnitOfWork</code> (just in memory objects) then it works fine. </p> <p>After testing fine with my in memory objects i tried this test.</p> <pre><code>[Test] public void RegisterAnExistingServer() { MockRepository mocks = new MockRepository(); IUnitOfWork MockUnitOfWork = mocks.DynamicMock&lt;IUnitOfWork&gt;(); ProjectService service = new ProjectService(MockUnitOfWork); Expect.Call(MockUnitOfWork.Servers.Count(x =&gt; x.CPUID == 1234)).Return(0); mocks.ReplayAll(); int NewSiteID = service.RegisterSite(1234); mocks.VerifyAll(); } </code></pre> <p>But when I try using it in Rhino Mock with an Expectation on Servers.Count I get the following error:</p> <pre><code>System.ArgumentNullException : Value cannot be null. Parameter name: arguments at System.Linq.Expressions.Expression.RequiresCanRead(Expression expression, String paramName) at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi) at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ref ReadOnlyCollection`1 arguments) at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments) at System.Linq.Queryable.Count(IQueryable`1 source, Expression`1 predicate) </code></pre> <p>What am I doing wrong??</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.
 

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