I\'m trying to set up a mock DbSet for testing purposes. I used the tutorial here, http://www.loganfranken.com/blog/517/mocking-dbset-queries-in-ef6/ and slightly modified i
To handle .Find(), we can use reflection in a similar manner, with a few assumptions about conventions when utilizing Find.
(hopefully this isn't out of line, I've had this Q/A bookmarked for years, and was looking for a Find implementation...)
Implement another helper as so:
static object find(IEnumerable
and in the mock setup example provided by Daniel above:
dbSet.Setup(d => d.Find(It.IsAny
Beacuse we have no way (or desire, usually) to determine the primary key in the way that EF would, I'm making the assumption that "ID" is the key field name (which matches my own conventions), but this could be expanded upon to accept a number of variations. I'm also assuming that only one integer is passed to Find (as is my standard convention), but this could also be expanded on for more robust support.