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
Let's say I have an abstract class
public abstract class VeryAbstract
{
  public int MyInt
{
get; private set;
}
   public VeryAbstract(int myint)
{
    MyInt = Math.Abs(myint);
}
}


The question is how to test the logic inside the constructor, using AAA syntax without manually subclassing the VeryAbstract class? Can AAA syntax do that?
________
GM 2300 engine
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon Hui,

I see a couple of limitations we have in testing the code you posted. One is that Math is a class in MSCorLib, and currently Isolator cannot fake behavior for types in MSCorLib. The second is that the AAA API does not support calling a c'tor with specific arguments yet.

If the code was something like
public abstract class VeryAbstract 
{ 
  public int MyInt 
{ 
get; private set; 
} 
   public VeryAbstract() 
{ 
    MyInt = MyClass.Foo(Random.Next());
} 
} 


we could do:
[TestMethod]
public void Test()
{
   Isolate.Fake.WhenCalled(() => MyClass.Foo(0)).WillReturn(10);
   // creating a fake object with CallOriginal causes its c'tor to be called
   var underTest = Isolate.Fake.Instance<VeryAbstract>(Members.CallOriginal);
   
   Assert.AreEqual(10, underTest.MyInt);
}


I hope this helps; I will update you once we have the c'tor arguments feature implemented with the syntax and its usage.

Thanks,
Doron
Typemock support
answered by doron (17.2k points)
...