c# - The model backing the 'EFDbContextProxy' context has changed - Testing cache? -
i made change entity, ran migration , updated database. re-ran test , it's throwing error:
the model backing 'efdbcontextproxy' context has changed since database created. consider using code first migrations update database
if run application, not error. seems efdbcontextproxy (whatever hell is) using old cache of data structure.
any ideas how resolve this?
this how prepare db context in test:
public class effieldviewerrepository_setup { protected datetime now; protected mock<efdbcontext> mockdbcontext; protected effieldviewerrepository fieldviewerrepository; protected idbset<fieldviewer> fieldviewerdbset; public effieldviewerrepository_setup() { this.now = datetime.now; this.mockdbcontext = new mock<efdbcontext>() { callbase = true }; this.fieldviewerrepository = new effieldviewerrepository( this.mockdbcontext.object ); ... }
here stack trace: http://pastebin.com/kaumhi3j
i had create mockefdbcontext , extend off of efdbcontext. inside construct run database.setinitializer<efdbcontext>(null)
:
public class mockefdbcontext : efdbcontext { public mockefdbcontext() { database.setinitializer<efdbcontext>(null); } }
i used new mockefdbcontext
in tests rather normal one:
this.mockdbcontext = new mock<mockefdbcontext>() { callbase = true };
sources:
- http://gaui.is/how-to-mock-the-datacontext-entity-framework/
- https://msdn.microsoft.com/en-us/library/gg679461(v=vs.113).aspx
Comments
Post a Comment