Hi Daniel,
Thanks for replying.
I'm not trying to unit test DbContext, no. I'm just trying to unit
test my code, the code in class 'A'.
But yes, after I posted that question I realized it could be
misleading. Let me try to clarify.
(I actually used that very blog post of yours to model my code)
I guess the problem was with my phrasing of the problem. Note that I
used the word "_my_" (DbContext) to refer to the class under test:
'A' (which extends from DbContext)
If you compare the code in your post:
internal class DomainContext : DbContext, IDomainContext
{
public void Save<T>(T entity) where T : IEntity
{ this.Set<T>().Add(entity); }
}
with my code above, I'm sure you will see that they look alike :):
public class A : DbContext{
public void Save<T>(T entity) where T : class, IEntity
{ this.GetSet<T>().Add(entity); }
protected virtual IDbSet<T> GetSet<T>() where T :
class,IEntity { return this.Set<T>(); }
}
So, now that that's out of the way, let me rephrase what I'm trying to
achieve: I want to mock 'GetSet()' so I can Assert that the Add()
method of the IDbSet has been called. But GetSet() is generic, thus my
question:
Is it possible to mock a protected generic method?
Thanks,
Eduardo
On Oct 7, 7:00 am, Daniel Cazzulino <
dan...@cazzulino.com> wrote:
> Testing a DbContext seems wrong, as you'd be testing EF itself? (it's like
> creating a test for system.string and trying to override stuff there ;)).
>
> This might be useful:
http://blogs.clariusconsulting.net/kzu/how-to-design-a-unit-testable-...