Very strange ..

148 views
Skip to first unread message

Charliers Frédéric

unread,
Feb 3, 2015, 6:07:09 AM2/3/15
to rhino...@googlegroups.com
 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


 

Patrick Steele

unread,
Feb 3, 2015, 11:31:59 AM2/3/15
to rhino...@googlegroups.com
It's difficult to diagnose since you don't have a complete code sample.

What is "_templateBl"?  How is it created?  How does it get a reference to your mock?


--
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 rhinomocks+...@googlegroups.com.
To post to this group, send email to rhino...@googlegroups.com.
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/d/optout.

bill richards

unread,
Jul 8, 2015, 12:37:17 PM7/8/15
to rhino...@googlegroups.com
There is nothing in your code to suggest that your _templateBI is even using the Mock object.

But also you have not stubbed the call to

ITemplateRepository.GetTemplateProjectWorkOrders(null)
Reply all
Reply to author
Forward
0 new messages