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.
+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?
Thanks,
Paul
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:
[TestMethod]
public void TestCtor()
{
    using(var recorder = RecorderManager.StartRecording())
    {
        new DummyClass(1);
        recorder.CheckArguments();
    }
    DoSomething();
    MockManager.Verify();
}

[TestMethod]
public void TestGetNum()
{
    var fake = Isolate.Fake.Instance<DummyClass>();
    Isolate.Swap.NextInstance<DummyClass>().With(fake);
    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,
Elisha,
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.6k points)
...