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

Mocking SPContentType

1 Answer 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Resu
Top achievements
Rank 1
Resu asked on 15 Dec 2011, 05:36 PM
Hello together

I'm just trying to mock the SPContentType class out of the SharePoint assembly but I'm facing several problems because of its nested constructors. I've already searched for a solution but cannot find any information about the mocking of this class.

When simply trying to mock this class:

SPContentType mockedContentType = Mock.Create<SPContentType>();

I receive the following error:

Initialization method X.KeywordFinderTests.Initialize threw exception. System.MissingMethodException: System.MissingMethodException: Constructor on type 'Microsoft.SharePoint.SPContentType' not found..

After that I had a look at the SPContentType class using dotPeek; but it has an internal empty constructor. Well it has many internal calls so I tried the following code to avoid them:

SPContentType mockedContentType = Mock.Create<SPContentType>(SPContentTypeId.Empty);
 
SPContentType mockedContentType = Mock.Create<SPContentType>(new SPContentTypeId("0x01"));

SPContentType mockedContentType = Mock.Create<SPContentType>(Constructor.Mocked);

But those constructor calls fail with the same error message. Even trying to create a mock using any of the other public constructor always leads to an error message.

SPContentType mockedContentType = new SPContentType(new ContentTypeId("0x01"), mockedContentTypeCollection, "My Content Type");
Initialization method X.KeywordFinderTests.Initialize threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..

Can some one help me to mock this class?

Thanks,
Andreas

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 20 Dec 2011, 12:55 PM
Hi Resu,
Thanks again for reporting the issue.  There was a bug in resolving internal default constructor that we recently fixed. Should you need the internal build that contains the fix then please create a support ticket where I will send it over.

Once you have updated to the build, you will be able to do the following as expected:

SPContentType mockedContentType = Mock.Create<SPContentType>();

Kind Regards,
Mehfuz
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
Resu
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or