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
0 votes
In 6.0.1, this code throws an unexpected ArgumentOutOfRangeException:

[ img ]
[TestClass, Isolated]
public class Tests
{
   public class A
   {
      public void Method(int x)
      {
      }
   }

   [TestMethod]
   public void Test()
   {
      A a = new A();
      Isolate.WhenCalled((int x) => a.Method(default(int)))
         .AndArgumentsMatch((int x) => x == 1).IgnoreCall();
   }
}


Expected is a TypemockException that says that

"Isolate.WhenCalled((int x) => a.Method(x)).AndArgumentsMatch((int x) => x == 1).IgnoreCall();"

is what is needed.
asked by Neil (27.7k points)

2 Answers

0 votes
Hi Neil,

There is a issue in the test - you haven't specified were 'x' is being used in the method call - and as a consequence Isolator does not know that the parameter passed to the method is actually x.

The test should be:
[TestClass, Isolated] 
public class Tests 
{ 
   public class A 
   { 
      public void Method(int x) 
      { 
      } 
   } 

   [TestMethod] 
   public void Test() 
   { 
      A a = new A(); 
      Isolate.WhenCalled((int x) => a.Method(x)) 
         .AndArgumentsMatch((int x) => x == 1).IgnoreCall(); 
   } 
}


As you can see by replacing default(int) with x makes the test pass.

I agree we need to improve the error message.
answered by dhelper (11.9k points)
0 votes
Thanks Dror.
answered by Neil (27.7k points)
...