mercredi 31 décembre 2014

Using RhinoMocks stub to return a value then an exception

I have the following scenario.


I'm using RhinoMocks to mock one of my services. The initial action of a stub is to increment a call count, on subsequent call i would like to throw an exception ... how would i do that?


This is what i currently have and i'm setting this up in the TestFixtureSetup method



var mockBLL = MockRepository.GenerateMock<IBLL>();

mockBLL.Stub(x => x.SaveOrUpdateDTO(null, null)).IgnoreArguments().WhenCalled
(invocation =>
{
nSaveOrUpdateCount++;
});

SimpleIoc.Default.Register<IBLL>(() => mockBLL);


In my test cases, one of my object will read from the IoC and then perform a call to the "SaveOrUpdateDTO" method. The first test case checks the count which is correct, the second test case will try to catch an exception.


My initial though is to create another mock, then re-register it before the second test case, but i don't think that the best way to go about it.


Any thoughts on how to generate two different stubs, one calling an action and another throwing an exception?


Aucun commentaire:

Enregistrer un commentaire