locked
How can I mock Monitor.Enter or lock(object) with Pex and Moles RRS feed

  • Question

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

     

    Wednesday, December 14, 2011 2:53 PM

All replies