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:
I receive the following error:
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:
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.
Can some one help me to mock this class?
Thanks,
Andreas
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