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
Is there a way to exclude recording for properties in the recording block ? Or exclude a type from mocking like CLR types are excluded ?

Let's say test class is TestClass and not to be mocked class is NotMockedClass.


class NotMockedClass
{
public string DontMockProperty { get; }
}

class TestClass
{
public int TestMethod(
}

[Test, VerifyMock]
public TestCase()
{
NotMockedClass nmObject = new NotMockedClass();
TestClass testObject = new TestClass();
    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        recorder.ExpectAndReturn(testObject.TestMethod(nmObject.DontMockProperty), 4);
    }
}


I don't want nmObject.DontMockProperty don't be mocked or set expectation.
asked by bhaveshbusa (1.2k points)

4 Answers

0 votes
Currently there is no way to prevent the class from being mocked, is there a specific reason why you would want to prevent mocking to that class?
answered by dhelper (11.9k points)
0 votes
Is there a reason that you couldn't get the class value outside of the recording block:
[TestFixture]
public class TestFixture
{
    [Test, VerifyMocks]
    public void TestCase()
    {
        NotMockedClass nmObject = new NotMockedClass();
        TestClass testObject = new TestClass();
        var dontMockProperty = nmObject.DontMockProperty;
        using (RecordExpectations recorder = RecorderManager.StartRecording())
        {
            recorder.ExpectAndReturn(testObject.TestMethod(dontMockProperty), 4);
        }
    }
}


ExpectAndReturn doesn't really "cares" what argument you're passing so any string will do
answered by dhelper (11.9k points)
0 votes
Is there a reason that you couldn't get the class value outside of the recording block:


The "NOT" to be tested class has lot of properties used in various other mocked objects. I don't want to create an equivalent primitive type variable for each property. It simply means lot of redundant coding.
answered by bhaveshbusa (1.2k points)
0 votes
Still - why not create the class outside of the recording scope?
answered by dhelper (11.9k points)
...