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

Exception trying to mock UserProfileManager

1 Answer 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nathanael
Top achievements
Rank 1
Nathanael asked on 13 Aug 2013, 05:36 PM
I'm trying to create a mock version of UserProfileManager in order to effectively unit test a Sharepoint 2010 Web Part
Every time I run this code, I get the the exception being thrown below. I've verified that the feature works when I debug the code that calls UserProfileManager on the Sharepoint machine - two different Sharepoint machines, in fact.
Here is the code in question:
var _mockServiceContext = Mock.Create<SPServiceContext>();
var _mockUserProfileManager = Mock.Create<UserProfileManager>(new object[] {_mockServiceContext});


Unable to create instance of class SharePoint.MyWebPart.Test.MyTest. Error: Microsoft.SharePoint.SPException: The trial period for this product has expired..
    at Microsoft.Office.Server.UserProfiles.ProfileManagerBase.ValidateLicensing()
   at Microsoft.Office.Server.UserProfiles.ProfileManagerBase..ctor(SPServiceContext serviceContext)
   at Microsoft.Office.Server.UserProfiles.ProfileManagerBase..ctor(SPServiceContext serviceContext, Boolean ignorePrivacy)
   at Microsoft.Office.Server.UserProfiles.UserProfileManager..ctor(SPServiceContext serviceContext, Boolean IgnoreUserPrivacy, Boolean backwardCompatible)
   at Microsoft.Office.Server.UserProfiles.UserProfileManager..ctor(SPServiceContext serviceContext)
   at Castle.Proxies.UserProfileManagerProxy..ctor(IEventsMixin, IMockReplicator, IMockMixin, IInterceptor[], SPServiceContext)
   at DynamicMethod_6f2d60ffa4f94cb4ba57556150461ef9(Object[])
   at “•.—.Ÿ.€()
   at “•.’•.Œ•[–](Func`1 ‹•)
   at “•.—.ˆ—(Type ‹, Object[] €)
   at –.”.(Type , List`1 ‘, Type Ž, Object[] “)
   at –.”.(Type Ž, Type[] , ProxyGenerationOptions Š“, Object[] “, IInterceptor[] )
   at Telerik.JustMock.Core.MocksRepository.Create(Type ‹, Object[] €, IEnumerable`1 ˆ–, IEnumerable`1 ‰–, IEnumerable`1 Š–, Type[] ‚–, Boolean ƒ–, Boolean €, IEnumerable`1 ˆ)
   at .‹–.Create(MocksRepository €–, Type ‹, Object[] –, Nullable`1 , Type[] ‚–, Nullable`1 ƒ–, IEnumerable`1 ˆ, List`1 ‰–, List`1 Š–, List`1 ˆ–)
   at Telerik.JustMock.Mock.›.’Ÿ()
   at “•.’•.Š•[–](Func`1 ‹•)
   at Telerik.JustMock.Mock.Create(Object[] args)

Has anyone else seen this issuue?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 14 Aug 2013, 08:47 AM
Hi Nathanael,

When you call the Mock.Create<T>(object[] args) overload, you essentially say that you want a loose mock but you still want the constructor of the mocked type to run. From the stack trace I see that it is in fact that constructor that throws the exception. Is that what you actually want? Because that's rarely useful.

If you need a true loose mock it is best that you bypass its constructor. Basically, use the Mock.Create<T>() overload, like so:

var _mockUserProfileManager = Mock.Create<UserProfileManager>();
Let us
var _mockUserProfileManager = Mock.Create<UserProfileManager>(); 
know if you need help with anything else during your trial.

Regards,
Stefan
Telerik
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Nathanael
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or