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