moq - Mocking repository with Entity Framework -


i'm using mog mocking repository linq sql this:

public static iproductsrepository mockproductsrepository(params product[] prods){     // generate implementer of iproductsrepository @ runtime using moq     var mockproductsrepos = new mock<iproductsrepository>();     mockproductsrepos.setup(x => x.products).returns(prods.asqueryable());     return mockproductsrepos.object; }  public interface iproductsrepository{     iqueryable<product> products { get; }     void saveproduct(product product);     void deleteproduct(product product); } 

how can change function entity framework if using this:

public interface iproductsrepository : ientities{     entitystate getentrystate(object entry);     void setentrystate(object entry, entitystate state);     void commit(); }  public interface ientities{     dbset<product> products { get; set; } } 

now using dbset.

well, since iproductsrepository implements ientities should have

public dbset<product> products { get; set; } 

property in there, add fetch method iproductrepository like

public interface iproductsrepository : ientities {     entitystate getentrystate(object entry);     void setentrystate(object entry, entitystate state);     void commit();      // new method     iqueryable<product> fetchall(); } 

then, in mockproductsrepository change setup line follows:

mockproductsrepos.setup(x => x.fetchall()).returns(prods.asqueryable()); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -