tags:

views:

31

answers:

1

Here's the code. GetParentPath is called as per normal!

    [TestMethod]
    [HostType("Moles")]
    public void GetParentPath_slashOnEnd_returns()
    {
        var sapi = new MPhotobucketApi();
        sapi.GetParentPathString = s => s;

        var api = new PhotobucketApi();
        var parentPath = api.GetParentPath("hello/world/");

        Assert.AreEqual(parentPath, "hello");
    }
+1  A: 

The way you wrote your test, your redirection only applies to the runtime instance embeded in sapi. You need to intercept the constructor of PhotobucketApi and intercept 'future' instance of PhotobucketApi in there:

MPhotobucketApi.Contructor = (me) => {
    new MPhotobucketApi { GetParentPathString = s => s }; 
};
...

The other aproach is to redirect GetParentPath for all instance by doing this:

MPhotobucketApi.AllInstances.GetParentPathString = (me, s) => s;
...
Peli
Thanks for your reply Peli. The 'AllInstances' snippet worked in place of my original code but the 'Constructor' snippet didn't have any effect.What I'm more baffled by is the code on page 17 here... http://research.microsoft.com/en-us/projects/pex/molestutorial.docx .It seems to be just like my original code.
Ian Warburton
Aarg my bad, forgot to pass me to the Moles constructor. new MPhotobucketApi(me) { GetParentPathString = s => s };
Peli