Hi all,
I have been researching what Mocking framework to use that will allow me to mock SharePoint classes, and as a result I am evaluating Telerik JustMock.
I am using SharePoint 2007 and Visual Studio 2008
I am attemting to Mock a SPList and a SPListItemCollection (see test method below) and I am getting the following error
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.MethodAccessException: Microsoft.SharePoint.SPListItemCollection..ctor()."
when attempting to execute the bold line below;
[TestMethod]
public void Should_Assert_FakingOfSpList()
{
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);
Assert.AreEqual(spListCollection, spWeb.Lists);
Assert.AreEqual(spList, spWeb.Lists["myList"]);
Assert.AreEqual(spListItemCollection, spWeb.Lists["myList"].GetItems(new SPQuery()));
}
}
I was wondering if the error was in the trial version and not in the full blown version but as you can imagine, I am not keen to purchase JustMock if I am going to come across the same issue.
I would appreciate any help on this matter.
Many thanks
Gary Hoggart
Senior IT Specialist
I have been researching what Mocking framework to use that will allow me to mock SharePoint classes, and as a result I am evaluating Telerik JustMock.
I am using SharePoint 2007 and Visual Studio 2008
I am attemting to Mock a SPList and a SPListItemCollection (see test method below) and I am getting the following error
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
System.MethodAccessException: Microsoft.SharePoint.SPListItemCollection..ctor()."
when attempting to execute the bold line below;
[TestMethod]
public void Should_Assert_FakingOfSpList()
{
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);
Assert.AreEqual(spListCollection, spWeb.Lists);
Assert.AreEqual(spList, spWeb.Lists["myList"]);
Assert.AreEqual(spListItemCollection, spWeb.Lists["myList"].GetItems(new SPQuery()));
}
}
I was wondering if the error was in the trial version and not in the full blown version but as you can imagine, I am not keen to purchase JustMock if I am going to come across the same issue.
I would appreciate any help on this matter.
Many thanks
Gary Hoggart
Senior IT Specialist