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
+1 vote
Can I use the C# API / AAA to verify that a method calls a constructor with specific arguments? I know how to do it with the older API:
Mock mock = MockManager.Mock<T>();
mock.ExpectConstructor().Args(Check.NotNull(), Check.IsEqual(value),,,);

But, I'd like to use the C# API for faking and verifying subsequent calls on the constructed object.

If it's not possible, then is it possible to mix the old and new API?
asked by woodward (1.7k points)

2 Answers

0 votes
Hi Paul,

Verifying constructors with AAA API is not supported yet. I recommend to test separately the ctor and the rest of the functionallity.

For example:
public void TestCtor()
    using(var recorder = RecorderManager.StartRecording())
        new DummyClass(1);

public void TestGetNum()
    var fake = Isolate.Fake.Instance<DummyClass>();
    var expected = 2;
    Isolate.WhenCalled(() => fake.GetNum()).WillReturn(expected);

    var actual = DoSomething();
    Assert.AreEqual(expected, actual);

private static int DoSomething()
    var dummyClass = new DummyClass(1);
    return dummyClass.GetNum();

Best Regards,
Typemock Support Team
answered by Elisha (12k points)
0 votes
Hi Paul,

We also added this ability in our new version.
answered by Bar (3.3k points)