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
We’re getting a problem (only on the build server). We have 100s of other tests running with TypeMock. But, when this test below runs, we get the below error message.

It seems as though it is not mocking the constructor for System.Drawing.Graphics even though I have the Constructor.Mocked passed to it.

Help?

Thanx

Tim Bassett

public void RenderCallsGraphics()
{
IMapObjectInternal target;
string text = "My Text";
PointF location = new PointF(100F, 100F);

target = new MapLabel(text, location);


MockObject<Graphics> graphicsMock = MockManager.MockObject<Graphics>(Constructor.Mocked);
MockObject<RenderContext> renderContextMock = MockManager.MockObject<RenderContext>(Constructor.Mocked);

using(RecordExpectations recorder = new RecordExpectations())
{
graphicsMock.MockedInstance.DrawString(string.Empty, null, null, location);
recorder.ExpectAndReturn( renderContextMock.MockedInstance.Mode, RenderMode.PostLabelling );
}

target.Render(graphicsMock.MockedInstance, renderContextMock.MockedInstance);


}



Error Message:

Test method Trimble.MobileSolutions.Map.Objects.MapLabelTest.RenderCallsGraphics threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: gdipNativeGraphics.


Error Stack Trace:
System.Drawing.Graphics..ctor(IntPtr gdipNativeGraphics)
System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
TypeMock.MockManager.MockObject[TMockedType](Constructor mockConstructors)
Trimble.MobileSolutions.Map.Objects.MapLabelTest.RenderCallsGraphics() in c:dTrimble.MobileSolutionsCurrent.Debug.ContinuousSourcesInfrastructureModulesMapTestObjectsMapLabelTest.cs: line 211
TypeMock.MethodDecorator.CallRealMethod()
TypeMock.DecoratorAttribute.CallDecoratedMethod()
TypeMock.VerifyMocksAttribute.Execute()
TypeMock.MethodDecorator.d()
TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
Trimble.MobileSolutions.Map.Objects.MapLabelTest.RenderCallsGraphics() in c:dTrimble.MobileSolutionsCurrent.Debug.ContinuousSourcesInfrastructureModulesMapTestObjectsMapLabelTest.cs: line 203
asked by tbassett (1.8k points)

1 Answer

0 votes
Hi,

It looks like your observation is correct this error is the result of the calling to the real ctor.

according to the stack trace it happens on the following line:
MockObject<Graphics> graphicsMock = MockManager.MockObject<Graphics>(Constructor.Mocked); 

can you try running a very simple test that contain only that line?

Since I cant reproduce this and you said that it only happens on the build server I guess this is more of a setup problem.
I suggest that you'll send us the logs and trace of the run. I'll send you an email with the details.
answered by lior (13.2k points)
...