AI OnAI Off
The method you are trying to mock is not actully on the interface but is an extension method to the interface. Try mock method with following signature instead:
EPiServer.Core.PageDataCollection FindPagesWithCriteria(EPiServer.Core.PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, EPiServer.Core.ILanguageSelector selector)
That's worked!! I would not have got that at all. I had to change the signature of FindPagesWithCriteria to include the languageBranch string but that's not a problem.
Thank you for that
Hi all
I'm trying to mock IPageCriteriaQueryService with RhinoMocks. At the moment I've got this (failing code)
// Create a mock repository var mockRepository = MockRepository.GenerateMock<IPageCriteriaQueryService>(); //.. setup stubs mockRepository.Stub(x => x.FindPagesWithCriteria(Arg<PageReference>.Is.Anything, Arg<PropertyCriteriaCollection>.Is.Anything)).Return(new PageDataCollection()); // mock service locator var mockLocator = MockRepository.GenerateMock<IServiceLocator>(); mockLocator.Stub(x => x.GetInstance<T>()).Return(mockRepository); ServiceLocator.SetLocator(mockLocator);
But it fails when setting up the mocks. It seems to want a language to be set i.e. this line in the stack trace - EPiServer.Globalization.ContentLanguage.get_PreferredCulture()
The full trace is
at EPiServer.BaseLibrary.ClassFactory.get_Instance()
at EPiServer.Globalization.ContentLanguage.get_PreferredCulture()
at EPiServer.Core.PageCriteriaQueryServiceExtensions.FindPagesWithCriteria(IPageCriteriaQueryService queryService, PageReference pageLink, PropertyCriteriaCollection criterias)
at NitbWebNUnit.Setup.ServiceLocatorSetup.<InitPageQueryService>b__3(IPageCriteriaQueryService x) in c:\code\NITB\Cds.Nitb.Web.NUnit\Setup\ServiceLocatorSetup.cs:line 68
at Rhino.Mocks.RhinoMocksExtensions.Expect[T,R](T mock, Function`2 action)
at Rhino.Mocks.RhinoMocksExtensions.Stub[T,R](T mock, Function`2 action)
at NitbWebNUnit.Setup.ServiceLocatorSetup.InitPageQueryService() in c:\code\NITB\Cds.Nitb.Web.NUnit\Setup\ServiceLocatorSetup.cs:line 68
at NitbWebNUnit.TidiMigrationTest.CanMigrateOneRecord() in c:\code\NITB\Cds.Nitb.Web.NUnit\TidiMigrationTest.cs:line 16
Can anyone cast any light on this.
Many thanks for any/all help
Tim B