How can I mole the DataContext that I'm using in a class to write messages to a table. I'd like to assert that the table LINQ is writing to has the expected count of messages. Here's what i have so far.
var context = new MJustTestingDataContext();
MyMessagewriter writer = new MyMessageWriter(context);
var messageList = new List<MIncmoingMessage>();
MTable<MIncomingMessage> messageTable = new MTable<MIncomingMessage>();
messageTable.Bind(messagesLinqList.AsQueryable());
If I use this code with xUnit in my class under test I'll get this exception
Microsoft.Moles.Framework.Moles.MoleNotImplementedException: DataContext.Dispose() was not moled.
What am I missing here and how to implement DataContext.Dispose() on the mole? I'm using moles standalone without Pex.
When you create a new Mole the default behavior for its methods and properties is to throw a
MoleNotImplementedException
whenever they are called.To implement the mole you can doI reread the question and you probably are having a problem sincecontext.Dispose = () => {};
which means that nothing happens when theDispose
method gets called on the moled instance.Dispose
is defined in a base class. To mole base method you need to do the following:You'll need to implement every property/method that gets called by the code under test or you can set the default behavior for the mole instance globally using the method
BehaveAsDefaultValue
. This way every method in the mole will do nothing and return the default value for it's return type if one exists instead of throwing aMoleNotImplementedException
. However if you require this behavior it's better to use a stub than a mole.