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
Does anyone know what could cause this to show up at the top of a stack trace?

at TypeMock.MethodDecorator.CallRealMethod()
at TypeMock.MethodDecorator.a()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)

It's getting called in my unit test method, and then goes on to ignore the static property that I have mocked.

I can post some of my code if necessary, but I'm guessing it's one of those really obvious things that people will just know.
asked by smitty3268 (760 points)

7 Answers

0 votes
Hi Smitty

Sorry the stack trace is not very helpful in this case :(
Please post the test code and the exception message you see.
answered by ohad (35.4k points)
0 votes
Well, this is what my code looks like:

//mock ServiceFactory<T>.Instance, a static property which returns an object of type T (and caches it after the 1st time when it gets created)

MockObject mockService = MockManager.MockObject<IMyCustomService>();
Mock mockFactory = MockManager.MockAll<ServiceFactory<IMyCustomService>>();
mockFactory.ExpectGetAlways("Instance", mockService.Object);

//mock all the methods in the service class
mockService.AlwaysReturn("MyCustomMethod", true);

//call the method in my business logic
ServiceFactory<IMyCustomService>.Instance.MyCustomMethod("", "");

//which throws the exception - a null reference exception that occurs inside the Instance property because it can't create the object since it expects it will be mocked instead.
answered by smitty3268 (760 points)
0 votes
And at a higher level:

[TestFixture, VerifyMocks]
public class MyTest {

[Setup]
public void Setup() {

MockManager.Init();
if(!MockManager.IsTypeMockedAll<ServiceFactory<IMyCustomService>>()) {
//create the mocked objects, setup expectations using ExpectGetAlways and AlwaysReturn.
}

}

[Test]
public void TestMethod() {
//call the ServiceFactory<T>.Instance property which is not mocked correctly
}

}
answered by smitty3268 (760 points)
0 votes
Hi Smitty,

Seem like I will need a code I can compile and run to solve this issue.

Lets take it offline.
answered by dhelper (11.9k points)
0 votes
My work email is blocking zip files :( but I can send you a test project tonight. I've managed to simplify the test code, though, so hopefully you can reproduce it with just the code listed below.

This throws the “not mocked” exception during the test:

[TestFixture, VerifyMocks]
public class FilterTests
{
[SetUp]
public void Setup()
{
MockManager.Init();
Mock test = MockManager.MockAll<Test>();
test.ExpectGetAlways("TestProperty", 1);
}

[Test]
public void MinimalTest()
{
int t = Test.TestProperty;
Assert.AreEqual(t, 1);
}

}

public class Test
{
public static int TestProperty
{
get { throw new Exception("not mocked!"); }
}
}
answered by smitty3268 (760 points)
0 votes
I think I've figured out the problem - I saw that static method support was only added in version 5.1, so I double checked and my project was still referencing the 5.0 version of the dll. I pointed it to the new 5.1.2 and I think it's now working.

A quick question - is it recommended to update to the new API even for 2.0 projects (example here: http://blog.typemock.com/2008/10/how-to ... s2005.html) or is the old API still fine?
answered by smitty3268 (760 points)
0 votes
I'm glad you worked things out.

Needless to say that the existing functionality of NAtural and Reflective APIs (old version) still exist and can be used.

The new AAA interface is based on using Lambda expressions which do not exist in .NET 2.0 but you can using anonymous delegates instead.

Soon when out new VB.NET API comes out it would not require using Lambda and could be used from C# .NET 2.0 as well!
answered by dhelper (11.9k points)
...