Using partial mocks to test the constructor of an abstract class,
testing for an ArgumentNullException when passed a null argument,
obviously. When the constructor throws the exception in the call to
PartialMock<T>(), Rhino wraps it in an Exception and throws it back
to the user from within MockRepository.MockClass(). I’m not sure if
this is by design, but I thought I would raise it just in case it is
not – whilst this behaviour might be desirable in other circumstances,
if you’re trying to test the constructor directly itself, it isn’t so
great :P.
Anyways, it’s no big issue, currently I can work around it as follows:
try
{
ScoredModel<double> model =
_mocks.PartialMock<ScoredModel<double>>(_db, null, _templateFactory,
_queryFactory);
}
catch (Exception e)
{
if (e.InnerException != null)
{
throw e.InnerException;
}
}
finally
{
_mocks.ReplayAll();
}
If you’re interested, the stack trace is also below:
at Rhino.Mocks.MockRepository.MockClass(CreateMockState
mockStateFactory, Type type, Type[] extras, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.CreateMockObject(Type type,
CreateMockState factory, Type[] extras, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMultiMock(Type type, Type[]
extraTypes, Object[] argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMock(Type type, Object[]
argumentsForConstructor)
at Rhino.Mocks.MockRepository.PartialMock[T](Object[]
argumentsForConstructor)
at
QLib.UnitTesting.QModels_test.ScoredModel_test.Test_ctor_NullIQueryFactory()
in C:\dev\QuantiumLibrary\Branches\20100120-NewZealand\QLib.UnitTesting
\QModels_test\ScoredModel_test.cs:line 115
--TearDown
at Rhino.Mocks.Impl.RecordMockState.get_VerifyState()
at Rhino.Mocks.MockRepository.Verify(Object obj)
at Rhino.Mocks.MockRepository.VerifyAll()
at QLib.UnitTesting.QModels_test.ScoredModel_test.TearDown() in C:\dev
\QuantiumLibrary\Branches\20100120-NewZealand\QLib.UnitTesting
\QModels_test\ScoredModel_test.cs:line 56
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.