c# - Rhino Mock Entity Framework using UnitofWork Pattern not working -


This is my first attempt, so hopefully it's easy.

I have created a WCF service that uses the unit framework to access the database. I have implemented an unitoffice interface, so my service can still use EF if it is still tested.

Here is my service:

  Public class ProjectService: IProjectService {Private IUnitOfWork db = null; Public Project Service (IUnitOfWork unitofwork) {db = unitofwork; } Public Entry Register Site {Int (CPU) • If (DB Server.Count (x = & gt; x.CPUID == CPUID)> 0} {// do something} return 0; }}   

Here is my unitoffice interface:

  Public Interface IUnitOfWork {IObjectSet & lt; TblClient & gt; Customer {Received; } IObjectSet & lt; TblServer & gt; Server {received; } IObjectSet & lt; TblSite & gt; Sites {Get; } IObjectSet & lt; TblServerLog & gt; Get server lock {get; } Zero commit (); }   

When I InMemoryUnitOfWork with a use this service with a concrete implementation of both SQLUnitOfWork (using EF) or the < / Code> (just objects in memory) so it works fine

In memory objects right after the test I tried this test

  [Test] public void RegisterAnExistingServer () {MockRepository of humors = new MockRepository () .; IUnitOfWork MockUnitOfWork = Mox. Dynamicmock & lt; IUnitOfWork & gt; (); Project Services Service = New Project Service (MockNet Offwork); Hope. Call (mockyanate work survers number (x = & gt; x.CPUID == 1234)). Return (0); Mocks.ReplayAll (); Int NewSiteID = service.RegisterSite (1234); Mocks.VerifyAll (); }   

But when I try to use it in duplicate Rhino, with an expectation on Servers.Count I get the following error:

  System.ArgumentNullException : value can not be null parameter name: System.Linq.Expressions.Expression.RequiresCanRead (expression on System.Linq.Expressions.Expression.ValidateOneArgument on System.Linq.Expressions, string paramName) (MethodBase method, ExpressionType nodeKind, expression args, ParameterInfo pI) debate .Expression.ValidateArgumentTypes (MethodBase method, ExpressionType nodeKind, referee ReadOnlyCollection`1 logic) System.Linq.Query On able.Count on System.Linq.Expressions.Expression.Call (expression example, MethodInfo method, IEnumerable`1 logic) (IQueryable` 1 source, the word `1 Plaintiff)   

I Am wrong ??

Mike East right Rainokmoks does not recurring joke (; TblServer & gt; and set him Make a blank IObjectSet as the value entered & lt)

Besides, you do not want to set expectations on lambdas. You will render anything for duplicate server property. Once everything is compiled, in your code testing, Lambda and Lambda will have two completely different methods (and your expectation will always fail) in your unit test. See for more information.

Comments