Thanks for bringing up the issue. One of the issue, i see in the test code is that during Mock.Arrange
a specific instance of SPWeb
Mock.Arrange(() => mockSPList.GetItems(new SPQuery())).Returns(mockSPListItemCollection);
The problem here is that you are telling mokSPList.GetItems
to return SpListItemCollection
for a particular instance of SPQuery
which is not the same as the one passed inside TestEntityRepository
. Therefore, the mock finds no match and returns null..
I tweaked the test using matcher and things are now working just fine.
var spWeb = Mock.Create<SPWeb>();
var spList = Mock.Create<SPList>();
var spListCollection = Mock.Create<SPListCollection>();
var spListItemCollection = Mock.Create<SPListItemCollection>();
Mock.Arrange(() => spWeb.Lists).Returns(spListCollection);
Mock.Arrange(() => spListCollection[Arg.AnyString]).Returns(spList);
Mock.Arrange(() => spList.GetItems(Arg.IsAny<SPQuery>())).Returns(spListItemCollection);
Additionally, I tried it both with Q2 (2010.1.713) and SP1 (2010.1.810.4). It is working for both the releases. However, there were some issues in the original Q2 version for mocking items from multiple projects. Therefore, I would recommend you to upgrade to the SP1 version, if not already.
Finally, I attached my test project, there are few other examples added as well. You might like to take a look at them as well.
Hope this solves your issue.
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking
system and vote to affect the priority of the items