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
Sorry for the slightly criptic subject but I can't think of a short way to explain my problem.

If I have a method to test which does the following

TestClass1 TestObject1 = new TestClass1();
TestClass2 TestObject2 = new TestClass2();
TestObject1.TestMethod(TestObject2);


And I setup my mocks in my test as so

Mock MockTestClass1 = MockManager.Mock(typeof(TestClass1));
Mock MockTestClass2 = MockManager.Mock(typeof(TestClass2));
MockTestClass1.ExpectCall("TestMethod").Args((TestClass2)MockTestClass2.MockedInstance);


Then obviously this wont work as at the time I am setting my expectations the TestObject2 has not been created and therefore MockTestClass2.MockedInstance is null and so I cannot use this to validate the argument.

Has anyone any ideas How I can check that the method creates TestObject 2 and passes this as the parameter for TestMethod.
asked by Cnash (2.3k points)

1 Answer

0 votes
Use Check.IsMock()

MockTestClass1.ExpectCall("TestMethod").Args(Check.IsMock(MockTestClass2));


as usual using Natural Mocks make this a no brainer
using (RecordExpectation record = RecorderManager.StartRecording())
{
  TestClass1 mock1 = new TestClass1(); 
  TestClass2 mock2 = new TestClass2(); 
  mock1.TestMethod(mock2);
}
answered by scott (32k points)
...