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 Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
This is my code:


var mock = MockManager.Mock(typeof(LocationVersionViewModel));
mock.CallBase.ExpectAlways("AfterEditRevertBaseInputComponentVersion");

//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));

//act
fakeLocationVersion.AfterEditRevertBaseInputComponentVersion(null, newWipfakeLocationVersion);

//assert
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?

Thanks,
Busi
asked by baruchl (600 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
        base.AfterEditRevertBaseInputComponentVersion();
    }
}


The next test achieves your goal:

[TestMethod]
public void TestMethod2()
{
    //Arrange
    var mock = MockManager.Mock<LocationVersionViewModel>();
    mock.CallBase.ExpectCall("AfterEditRevertBaseInputComponentVersion");

    //Act
    var lvm = new LocationVersionViewModel();
    lvm.AfterEditRevertBaseInputComponentVersion();

    //Assert
    Assert.AreEqual( 0 , BaseInputComponentVersion.field);
}


Ignoring the base class's method is possible only with the Mock API.
When
mock.CallBase.ExpectCall("AfterEditRevertBaseInputComponentVersion");
is the line you were looking for.
answered by alex (17k points)
...