SPFarm.Local.Services.GetValue<SPWebApplication>(); RRS feed

  • Question

  • I am trying to use Pex and Moles for SharePoint unit testing. The first line of code in the method under test is the following:




    I get, as expected, a MoleNotImplementedException:

    --- Description

    failing test: MoleNotImplementedException, SPPersistedObjectCollection`1.GetValue() was not moled.

    Code in the test:

    MSPFarm.LocalGet = () => new MSPFarm
                        ServicesGet = () => new MSPServiceCollection { } 

    Now, how do one go about implementing a Mole for this method? The method is inherited and generic, so it doesn't exist on the SPFarm.Services which is a ServiceCollection. It comes from SPPersistedObjectCollection<T> - but then again SPWebApplication is not an SPPersistedObject.

    Seems I hit my head into the wall here on the first line of code, I tried working around it, playing with the "Mole Type" option, but never found my way around to the correct combination of types and places to mole.

    Any ideas how to reach a mole of the first line of code there?

    Tuesday, April 12, 2011 8:14 AM