Mocking SPListItemCollection Error JustMock

2 posts, 0 answers
  1. Gary
    Gary avatar
    2 posts
    Member since:
    Jan 2011

    Posted 23 Feb 2011 Link to this post

    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



  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 24 Feb 2011 Link to this post

    Hi Gary,

    Thanks again for making the post. Unfortunately it is occurring due to some changes in the Q3 build. Good news is that we already identified and fixed the problem.  In that regard, please open up a support ticket (referencing this post) and we will attach an internal build for you.

    However, the build will be available in the coming Q1 release. Please let us know if the above mentioned solution works for you as well.

    P.S. Opening up a support ticket is just a policy for providing internal builds to fast address customer exceptions.


    Kind Regards,
    Ricky
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. DevCraft R3 2016 release webinar banner
Back to Top