Hi,
I'm having trouble stubbing return values for 'out' parameters in my test class, following the instructions on the 'Learn' page for returning values for 'out' parameters from a method call on a mocked instance (the examples on the Learn page actually apply to a static rather than instance method, but I'm assuming the syntax shouldn't be any different). For example:
[TestFixture]
public class TypeMockTest
{
[Test]
public void Test()
{
//set up expectations
OutParameter stubReturnValue = new OutParameter("2");
OutParameter supplied = null ;
Mock stubbedClassMock = MockManager.Mock(typeof(StubbedClass));
stubbedClassMock.ExpectAndReturn("StubbedMethod", stubReturnValue).Args("ignored", new Assign(supplied));
//perform the test
ClassUnderTest classUnderTest = new ClassUnderTest();
string actual = classUnderTest.Call(new StubbedClass());
Assert.AreEqual(stubReturnValue.value + "1", actual);
}
}
public class ClassUnderTest
{
public string Call(StubbedClass ctlr)
{
OutParameter returnValue;
ctlr.StubbedMethod("ignored", out returnValue);
return returnValue.value + "1";
}
}
public class StubbedClass
{
public void StubbedMethod(string param1, out OutParameter outparam)
{
outparam = new OutParameter("2");
}
}
public class OutParameter
{
public string value;
public OutParameter(string value)
{
this.value = value;
}
}
I would expect the StubbedMethod to return the supplied stubReturnValue and for my test to pass, but instead I get:
TestCase 'TestSolution.TypeMockTest.Test'
failed: TypeMock.TypeMockException :
*** No method StubbedMethod in type TestSolution.StubbedClass returns TestSolution.OutParameter
at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Int32 A_4, Type[] A_5)
at TypeMock.Mock.ExpectAndReturn(String method, Object ret, Int32 timesToRun, Type[] genericTypes)
at TypeMock.Mock.ExpectAndReturn(String method, Object ret, Type[] genericTypes)
D:TestSolutionTypeMockTests.cs(56,0): at TestSolution.TypeMockTest.Test()
What am I doing wrong? I'm using the latest version of Typemock, 4.2.3.
Thanks,
Nick