Hi All,
A customer asked me to add some Unit test on his application. First Idea
=> Unit Test + Rhino Mock, because I had already used Mocking few years ago
and was satisfied by the quality of RM.
But I have a problem. I try since 2 days to find a solution on the web =>
no answer.
Here it is (Challenge! :)) :
I Try to mock a repository layer access class (ITemplateRepository)
accessed by a method of my Business Layer (ITemplateBl).
Here is the begining of my Business Layer method :
// --------------------------------------
public IEnumerable<TemplateProjectDto> GetTemplateProjects(CallContext
callContext)
{
var templateProjects = _templateRepository.GetTemplateProjects();
var templateProjectWorkOrders =
_templateRepository.GetTemplateProjectWorkOrders();
var templateProjectQuestions =
_templateRepository.GetTemplateProjectQuestions().OrderBy(x => x.OrderBy);
var templateQuestions = _templateRepository.GetTemplateQuestions();
.....
nothing very difficult.. I just load data from the repository.
Here is my test :
[TestMethod]
public void GetAllTemplateProject()
{
ITemplateRepository _templateRepositoryStub =
MockRepository.GenerateStub<ITemplateRepository>();
_templateRepositoryStub.Stub(repo => repo.GetTemplateProjects())
.IgnoreArguments()
.Return(TemplateProjectMock.GetList());
_templateRepositoryStub.Stub(repo => repo.GetTemplateWorkOrders())
.IgnoreArguments()
.Repeat
.Any()
.Return(TemplateWorkOrderMock.GetList());
_templateRepositoryStub.Stub(repo => repo.GetTemplateWorkOrderLinks())
.IgnoreArguments()
.Repeat
.Any()
.Return(TemplateWorkOrderLinkMock.GetList());
_templateRepositoryStub.Stub(repo => repo.GetTemplateProjectQuestions())
.IgnoreArguments()
.Repeat
.Any()
.Return(TemplateProjectQuestionMock.GetList());
var result = _templateBl.GetTemplateProjects(_callContext)
.OrderBy(x=>x.Id)
.ToList();
.....
Thus something very simple .. I just build stubs for repository methods
return and I do not take care of parameter at this time (there is only ony
and it is optional)..
On the call the code does not return a non visible value for the first
call, a null for the other and crash on that call with this error :
An exception of type 'System.InvalidOperationException' occurred in
Rhino.Mocks.dll but was not handled in user code
Additional information: Previous method
'ITemplateRepository.GetTemplateProjectWorkOrders(null);' requires a return
value or an exception to throw.
It seems clear .. but it is not, as the static class is returning an List
of 2 objects (tested, again and again) .. And If I switch 2 line, it still
crashing.
On another test with a single call to the repository, it works perfectly ..
If I add one, it crashs.
Any Idea about what i am doing wrong ?
Regards,
Frédéric
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/d/optout.