chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Faking CallBase is not working

0 votes
This is my code:

var mock = MockManager.Mock(typeof(LocationVersionViewModel));

//creating the fakes
var fakeLocationVersion = Isolate.Fake.Instance<LocationVersionViewModel>(Members.CallOriginal, ConstructorWillBe.Ignored, BaseConstructorWillBe.Ignored);
var newWipfakeLocationVersion = Isolate.Fake.Instance<LocationVersionViewModel>(Members.CallOriginal, ConstructorWillBe.Ignored, BaseConstructorWillBe.Ignored);

//fake static calls
Isolate.Fake.StaticMethods(typeof (LocationVersionViewModel));

fakeLocationVersion.AfterEditRevertBaseInputComponentVersion(null, newWipfakeLocationVersion);

Isolate.Verify.WasCalledWithAnyArguments(() => LocationVersionViewModel.AddEmptyLocationRowIfNeeded(newWipfakeLocationVersion));

LocationVersionViewModel inherits from BaseInputComponentVersion. BaseInputComponentVersion has a virtual method called AfterEditRevertBaseInputComponentVersion that is overrided by LocationVersionViewModel , and there, I call Base.AfterEditRevertBaseInputComponentVersion .

My goal is to ignore the call to Base.AfterEditRevertBaseInputComponentVersion within LocationVersionViewModel.

Although I have this line: mock.CallBase.ExpectCall("AfterEditRevertBaseInputComponentVersion")
The method AfterEditRevertBaseInputComponentVersion is being call on the base class of LocationVersionViewModel.

Am I doing something wrong?

asked Dec 11, 2012 by baruchl (3,100 points)

1 Answer

0 votes
Hi Busi,

I changed the code to simplify the example.

public class BaseInputComponentVersion
    public static int field = 0;
    public virtual void AfterEditRevertBaseInputComponentVersion()
        field = 5;

public class LocationVersionViewModel : BaseInputComponentVersion
    public override void AfterEditRevertBaseInputComponentVersion()
        //ignore this call

The next test achieves your goal:

public void TestMethod2()
    var mock = MockManager.Mock<LocationVersionViewModel>();

    var lvm = new LocationVersionViewModel();

    Assert.AreEqual( 0 , BaseInputComponentVersion.field);

Ignoring the base class's method is possible only with the Mock API.
is the line you were looking for.
answered Jan 7, 2013 by alex (17,950 points)