This is a migrated thread and some comments may be shown as answers.

Error Mocking SPContentTypeCollection

1 Answer 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 19 Mar 2012, 08:48 AM
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?

Thanks
Andreas

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 22 Mar 2012, 11:09 PM
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. 

http://www.telerik.com/support/pits.aspx#/public/justmock/10404 

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,
Mehfuz
the Telerik team

Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
General Discussions
Asked by
Andreas
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or