Can I set expectations for role types created using Moles?

I need to not only perform the swap implementation, but also add the necessary verification to make sure that certain methods were called in the correct order. I can imagine that something like Mole + Mock will give me this option. Does anyone know if Moles has this feature?

This code should be useful:

// Verify if Dispose was called MDisposableObject.Constructor = delegate(DisposableObject instance) { MDisposableObject mole = new MDisposableObject(instance); ... // This doesn't work //objectContext.Expects(i => i.Dispose()).ToBeCalledOneTime(); }; 
+4
source share
1 answer

Goals strive to give butts (and not mocks ) for everything, even for static or private methods. The Moles manual says that they are not aimed at the mocking aspect, like other mocking frameworks: they offer isolation, not mockery. If you want to check calls to Mols, you have to make your own way. For instance:

  bool called = false; MDisposableObject.Constructor = (@this) => { var mole = new MDisposableObject(@this) { Dispose = () => { Assert.IsFalse(called); called=true; //if you want to call the original implementation: MolesContext.ExecuteWithoutMoles(() => (@this).Dispose()); //or do something else, even nothing } }; }; 

Only Typemock Isolator (powerful, but expensive) and JustMock Telerik (new simultaneous, as well as not free) allow ridiculous functions for everything.
If you have interfaces, delegates, and a virtual method, use a free fake infrastructure like Moq or RhinoMocks.

Warning about my example: so far I have not found how to call the orignal constructor, I mean something like

 var mole = new SDisposable(); (@this) = mole; new MDisposable(mole) {...}; 

Actually, from what I read on msdn, this is not possible ... I hope the following releases will allow this.

+4
source

All Articles