Error Mocking SPContentTypeCollection

2 posts, 0 answers
  1. Andreas
    Andreas  avatar
    5 posts
    Member since:
    Dec 2011

    Posted 19 Mar 2012 Link to this post

    Hello together

    I'm just trying to mock the SPContentTypeCollection class out of the SharePoint 2010 assembly but I'm facing a problem arranging a mock for the "BestMatch" method. I've already searched for a solution but cannot find any information about it.

    This is my testcode:

    SPContentTypeCollection mockedContentTypeCollection = Mock.Create<SPContentTypeCollection>();
    Mock.Arrange(() => mockedList.ContentTypes).Returns(mockedContentTypeCollection);
    SPContentTypeId mockedContentTypeId = Mock.Create<SPContentTypeId>();
    Mock.Arrange(() => mockedContentTypeCollection.BestMatch(Arg.IsAny<SPContentTypeId>())).Returns(mockedContentTypeId).MustBeCalled();

    The first three lines work perfectly, but an error is thrown for the fourth line. The mockedList is being creatd within a "TestInitialize" method.

    This ist the call stack for the error occuring:

    Test method XX.XX.Data.Tests.Repositories.XXRepositoryTests.AddPaymentSucceedsTest threw exception:
    System.NullReferenceException: Object reference not set to an instance of an object.
    at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.GetRuntimeMethod(IInvocation invocation)
    at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.Telerik.JustMock.Weaver.Interceptors.Abstraction.IWeaverInterceptor.Intercept(IInvocation invocation)
    at SPContentTypeId_Interceptor_d2e70383884d4efca5b3ddb76451ab0c.Intercept(Object, SPContentTypeId, ref Boolean)
    at Microsoft.SharePoint.SPContentTypeId.Equals(Object o)
    at Telerik.JustMock.Utility.IsDefault(Type valueType, Object value)
    at Telerik.JustMock.Setup.MethodCall.GetNewInstance(Object[] arguments, Type[] argumentTypes)
    at Telerik.JustMock.Interceptors.MockInterceptor.CreateMethodInstance(Object[] userArgs, Type[] types)
    at Telerik.JustMock.Interceptors.MockInterceptor.CreateMethodInstance(Object[] userArgs, Type[] types, Instruction instruction)
    at Telerik.JustMock.Interceptors.MockInterceptor.Intercept(MockInvocation invocation)
    at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.Telerik.JustMock.Weaver.Interceptors.Abstraction.IWeaverInterceptor.Intercept(IInvocation invocation)
    at Telerik.JustMock.Handlers.WeaverInterceptorHandler.Invoke(Object[] args)
    at Telerik.JustMock.MockContext`1.SetupMock(MockExpression`1 expression)
    at Telerik.JustMock.MockContext`1.SetupMock(Expression`1 expression)
    at Telerik.JustMock.Mock.<>c__DisplayClass1`1.<Arrange>b__0(MockContext`1 x)
    at Telerik.JustMock.MockContext.Setup(Instruction instruction, Func`2 function)
    at Telerik.JustMock.Mock.Arrange(Expression`1 expression)
    at XX.XX.Data.Tests.Repositories.XXRepositoryTests.AddPaymentSucceedsTest() in XXRepositoryTests.cs: line 163

    Has someone face the same problem already and / or can someone help me finding a solution?

  2. Ricky
    Ricky avatar
    467 posts

    Posted 22 Mar 2012 Link to this post

    Hi Andreas,

    Thanks again for reporting the issue. Unfortunately, this is a bug in processing the SPContentTypeId argument that is throwing the exception. I am entering a task into our system which you can track here. 

    However, I managed to find a solution for it as well and if you need it urgently then please open a support ticket where i will send the latest internal build that should resolve it.

    Kind Regards,
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft R3 2016 release webinar banner
Back to Top