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 might be a basic question as I don't have a lot of experience with the Isolator.
The following code is part of a unit test i was trying to run:

MockObject targetMock = MockManager.MockObject(typeof(Class_A_Accessor));
targetMock.ExpectGet("BaseProperty1", m_propertyValue);

I have to mock the accessor and not the class because I need to access a protected proerty. the problem is that when I try to call ExpectGet I get an exception because BasePrperty1 doesn't exists in the class but in the base-class. How can I call this property while using the accessor or maybe there's another solution?


asked by adamoren (1.1k points)

2 Answers

0 votes
Hi Adam,

First I would like to welcome you, I hope you will find the Isolator product useful.

In general, the Isolator has no problem mocking private/internal methods,
you can mock them the same way you mock public ones.
here's an example for what (i think) you are trying to do:

First the tested classes
public class BaseClass
    private string _MyProp;

    protected string MyProp
        get { return _MyProp; }
        set { _MyProp = value; }

public class UnderTest : BaseClass
    public string GetName()
        return MyProp;

and now here is the test method:
public void BaseClassPropertyMock()
    MockObject<UnderTest> mock = MockManager.MockObject<UnderTest>();
    mock.ExpectGet("MyProp", "John");

    UnderTest target = mock.Object as UnderTest;
    Assert.AreEqual("John", target.GetName());
answered by lior (13.2k points)
0 votes
Typemock Isolator also supports mocking accessors with NaturalMocks

Class_A_Accessor target = RecorderManager.CreateMockedObject<Class_A_Accessor>();
using (RecordExpectations recorder = RecorderManager.StartRecording())

This way you get goodies like code completion and refactoring
answered by eli (5.7k points)