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

Mocking SPUser

2 Answers 132 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 Apr 2012, 10:59 AM
Hello together

It seems that mocking the SPUser object out of the SharePoint 2010 assemblies is not working. I'm just calling the following line:

SPUser currentUser = Mock.Create<SPUser>();

Which leads to the following error in my test initialization method:

Initialization method XX.Presentation.Tests.LicensedPatents.AssociatedPatentsPresenterTests.InitalizeTest threw exception. System.MissingMethodException: System.MissingMethodException: Constructor on type 'System.Object[,]' not found..

Here is the call stack which refers to line 88 (the one posted above):

at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Telerik.JustMock.Utility.GetDefaultValue(Type target)
at Telerik.JustMock.Utility.ProcessArgument(Type target, BindingFlags flags, Object[] args)
at Telerik.JustMock.Utility.GetArgumentsWithDefaultValue(Type target)
at Telerik.JustMock.Utility.GetExtentedArguments(Type target, Object[] args)
at Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
at Telerik.JustMock.Mock.Create(Type target, Object[] args)
at Telerik.JustMock.Mock.Create()
at XX.Presentation.Tests.LicensedPatents.AssociatedPatentsPresenterTests.InitalizeTest() in AssociatedPatentsPresenterTests.cs: line 88

It would be nice to be able to mock the SPUser object. Thanks for any help!

Regards
Andreas

2 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 23 Apr 2012, 06:47 PM
Hi Andreas,
Thanks again for reporting the issue. Since there is no accessible default constructor for SPUser. I would recommend you to create the mock using Constructor.Mocked switch.

[TestMethod]
public void SharepointSPUserMocking()
{
    var spList = Mock.Create<SPUser>(Constructor.Mocked);
    Assert.IsNotNull(spList);
}


Once you have done it, things will  work as expected.

Kind Regards
Ricky
the Telerik team

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

0
Andreas
Top achievements
Rank 1
answered on 24 Apr 2012, 07:49 AM
Many thanks!
Tags
General Discussions
Asked by
Andreas
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or