Reputation: 8934
I'm doing some unit tests for an EntityEventListener
from NHibernate, and I'm got stuck trying to mock FlushEvent
or the EntityEntry
.
As EntityEntry doesn't have a public constructor, and type Mock must be an interface, an abstract or non-sealed class.
EntityEntry ee = new EntityEntry(); //NOT
_entityEntryMock = new Mock<EntityEntry>(); //NOT
Upvotes: 2
Views: 590
Reputation: 6090
Without some elaboration, I can't say if this makes sense for you specifically, but when I hit a situation like this (a class that I can't mock with Moq and I can't build), I call in the big guns with an isolation framework. I generally use Moles, but there are other options like Typemock Isolator, and I think Moles itself is being replaced in the next .NET framework with a built-in isolator called "Fakes". But suffice it to say, you're attempting to use Moq for something it's not intended to do -- it just creates mocks "naturally" without serving as an isolation framework.
Upvotes: 2