Mocking SPUser

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

    Posted 19 Apr 2012 Link to this post

    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. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 23 Apr 2012 Link to this post

    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 >>

  3. DevCraft R3 2016 release webinar banner
  4. Andreas
    Andreas  avatar
    5 posts
    Member since:
    Dec 2011

    Posted 24 Apr 2012 Link to this post

    Many thanks!
Back to Top