entity framework - Mocking or faking DbEntityEntry or creating a new DbEntityEntry -


following on heels of other question mocking dbcontext.set i've got question mocking ef code first.

i have method update looks like:

if (entity == null)     throw new argumentnullexception("entity");  context.getidbset<t>().attach(entity); context.entry(entity).state = entitystate.modified; context.commitchanges();  return entity; 

context interface of own dbcontext.

the problem i'm running in is, how handle the

context.entry(entity).state.

i've stepped through code , works when have real live dbcontext implementation of context interface. when put fake context there, don't know how handle it.

there no constructor dbentityentry class, can't create new 1 in fake context.

has had success either mocking or faking dbentityentry in codefirst solutions?

or there better way handle state changes?

just other case, need add additional level of indirection:

interface isalescontext {     idbset<t> getidbset<t>();     void setmodified(object entity) }  class salescontext : dbcontext, isalescontext {     public idbset<t> getidbset<t>()     {         return set<t>();     }      public void setmodified(object entity)     {         entry(entity).state = entitystate.modified;     } } 

so, instead of calling implementation, call setmodified.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -