How can I mock Monitor.Enter or lock(object) with Pex and Moles
-
Wednesday, December 14, 2011 2:53 PM
This is my method:
public static bool VoteT(string currentUserId, string surveyId, string answerId) { bool retVal = false; lock (_lock) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { // code } }); return retVal; } }
This is my Pex test:
[PexMethod, PexAllowedException(typeof(ArgumentNullException))] public void VoteTest(string currentUserId, string surveyId, string answerId) { // traps MSPContext.BehaveAsNotImplemented(); MSPSecurity.BehaveAsNotImplemented(); MMonitor.BehaveAsNotImplemented(); // arrange MSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = (code) => code(); MSPContext.CurrentGet = () => new MSPContext() { SiteGet = () => new MSPSite() { IDGet = () => Guid.NewGuid() } }; // act SafeSurveyVoteUtil.VoteT(currentUserId, surveyId, answerId); }
This is my error:
"MoleNotImplementedException" "Monitor.Enter(Object, Boolean&) was not moled."
How can I correct this?
All Replies
-
Saturday, March 31, 2012 3:13 AM
Hi,
Your question falls into the paid support category which requires a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs.
http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophoneThanks!
Sophia Lu [MSFT]

