7

Hi I'm trying to run a simple test replacing Features.Count on every SPSite, but I can't. Can you help me?

I have this code:

[TestMethod]
public void AllInstances()
{
    using (var context = new SPEmulationContext(IsolationLevel.Fake))
    {
        ShimSPSite.AllInstances.FeaturesGet = (item) =>
        {
            return new ShimSPFeatureCollection()
            {
                CountGet = () => 1
            }.Instance;
        };
        var tSite = new SPSite("http://fakesite");
        Assert.AreEqual(1, tSite.Features.Count);

    }
}

but it fails with this exception:

Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotImplementedException: Exception of type 'Microsoft.QualityTools.Testing.Fakes.Shims.ShimNotImplementedException' was thrown.

This one which is similar works fine

[TestMethod]
public void Shim()
{
    using (var context = new SPEmulationContext(IsolationLevel.Fake))
    {
        var tSite = new ShimSPSite()
        {
            FeaturesGet = () =>
            {
                return new ShimSPFeatureCollection()
                {
                    CountGet = () => 1
                }.Instance;
            }
        }.Instance;
        Assert.AreEqual(1, tSite.Features.Count);
    } 
}

Can you tell me what I'm doing wrong? Thanks

Tom
  • 4,257
  • 6
  • 33
  • 49
Maurizio Pozzobon
  • 3,044
  • 7
  • 34
  • 44
  • Have you seen and tried the accepted answer here: http://stackoverflow.com/questions/11632108/shimnotsupportedexception-in-ms-visualstudio-2012 ? – Markus May 03 '15 at 11:09

0 Answers0