Does Microsoft support abstract padding support methods?

I have a class setup as follows:

public abstract FooClass {
    public FooClass() {
        // init stuff;
    }

    public void RandomMethod() {
        // do stuff;
    }

    public abstract WhatIWantToShim();
}

What I want to do is install WhatIWantToShim on ShimFooClass like this:

ShimFooClass.AllInstances.WhatIWantToShim = () => Boo();

I can install RandomMethod just fine,

ShimFooClass.AllInstances.RandomMethod = () => CalculatePi();

However, it seems that the created ShimFooClass does not create the WhatIWantToShim property in the AllInstances ShimFooClass property.

I looked at http://msdn.microsoft.com/en-us/library/hh549176.aspx#bkmk_shim_basics , but I see nothing about abstract methods. The only thing I see, referring to what is not supported, is the finalizers. Does anyone know what is going on here and is this scenario supported?

+5
source share
2 answers

Ahhh ... bummer

. Stubs , . , .

http://msdn.microsoft.com/en-us/library/hh549175(v=vs.110).aspx

: , .

using (ShimsContext.Create())
{
    bool wasAbstractMethodCalled = false;
    var targetStub = new StubFooClass()
    {
        WhatIWantToShim01 = () => wasAbstractMethodCalled = true
    };
    var targetShim = new ShimFooClass(targetStub);
    targetShim.AllInstances.RandomMethod = () => CalculatePi();
    FooClass  target = targetShim.Instance;
    target.WhatIWantToShim();
    Assert.IsTrue(wasAbstractMethodCalled, "The WhatIWantToShim method was not called.");
}

WhatIWantToShim , stub . (: 01, WhatIWantToShim, , ).

, , .

+4

, , , .

-, . . , .

{
    bool wasAbstractMethodCalled = false;
    var targetStub = new StubFooClass()
    {
        WhatIWantToShim01 = () => wasAbstractMethodCalled = true
    };
    ShimFooClass.AllInstances.RandomMethod = @class => targetStub.CalculatePi();
    targetStub.WhatIWantToShim();
    Assert.IsTrue(wasAbstractMethodCalled, "The WhatIWantToShim method was not called.");
}

, . , .

, . , , . , , . , , - , .

, , , . . , , ; ( ) ( DI - !), , , , - .

0

All Articles