Very strange (In English ^^)

59 views
Skip to first unread message

Charliers Frédéric

unread,
Feb 3, 2015, 6:17:56 AM2/3/15
to rhino...@googlegroups.com
Hi All,

 I Try to stub a Business Layer methods with Rhino Mock and have a very strange result :

 
/// <summary>
/// This method return a complete list of all TemplateProjects
/// </summary>
/// <param name="callContext"></param>
/// <returns></returns>
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();
....
///
I Just try to get some data from the repository (very simple)
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();

 Assert.IsNotNull(result);
...
//////
Very simple too .. I stub all calls to repository to force RM to return result of static methodes (GetList()) to me.
When I debug the code, I see the following message on execution of the _templateRepository.GetTemplateProjectQuestions() methods (the 3th line)

It is strange because, I try to execute the GetTemplateProjectQuestions method of my Business layer, and the exception of RM is based on the previous method!

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.

Other very strange thing : The GetList() method was tested at least 10 times and return the expected result! And If I switch 2 calls into the BL methods, that does not change anything.
Someone see what I did wrong?

 Regards,
 
  f.
Reply all
Reply to author
Forward
0 new messages