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
Post a Comment