tags:

views:

79

answers:

1

Can anyone explain to me how to verify mocks if you don't have their Moq-wrapper? MockFactory.Verify() won't do. I want to be able to verify the mocks explicitly and mocks should be created using mockfactory! Please send in your comments.

+2  A: 

If you create your mocks using a factory, it doesn't mean you must verify them using it. Sometimes I use factory only to set up MockBehavior in one place for all my mocks. But I still verify some of my mocks separately.

var factory = new MockFactory(MockBehavior.Strict);
var fooMock = factory.Create<IFoo>();

fooMock.Setup(foo => foo.Bar());

fooMock.Verify(foo => foo.Bar, Times.Once());

Update In case if you only have mocked objects in your test method, you can get mock wrappers back like this:

IFoo foo = fooMock.Object;

//...

var fooMockAgain = Mock.Get(foo);
Yacoder
Actually I have a class in which functions are written to create required mocks using mockfactory along with the setups. These functions only return the real object i.e. mockedthing.object So in the main function i just call these functions to create the dummy objects. So here i seem to be able to verify only using mockfactory. I want to know if there is any other way.
MockedMan.Object
I updated the answer.
Yacoder