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
My test initialization looks like this:
BaseController mockedController = new BaseController();
         using (RecordExpectations recorder = RecorderManager.StartRecording()) {
            DashboardConfig mockDashboardConfig = new DashboardConfig("UnitTests");
            DashboardConfig dummy = mockedController.Config; /* line 694 */
            recorder.Return(mockDashboardConfig);
            recorder.RepeatAlways();
         }


The exception I'm getting is this:

TetraData.BaseControllerTests.BaseControllerMethods.TestDbConn : System.MissingMethodException : Constructor on type 'TetraData.Dashboard.Base.DashboardConfig' not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.a(Type A_0, Constructor A_1, Object[] A_2)
at TypeMock.RecorderManager.b(Type A_0)
at TypeMock.RecorderManager.a(String A_0, Object A_1, Object[] A_2, MethodBase A_3, Boolean A_4, Type A_5)
at TypeMock.RecorderManager.a(String A_0, String A_1, Object A_2, Object[] A_3, MethodBase A_4, Object A_5)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Object[] A_4)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters)
at TetraData.Dashboard.Base.BaseController.get_Config() in c:dev7SourceDashPortalBaseControllerControllersBaseController.cs:line 187
at TetraData.BaseControllerTests.BaseControllerMethods.TestDbConn() in c:dev7SourceTestsBaseControllerTestsControllersBaseControllerTests.cs:line 694


Notice that the exception happens at line 694 (notice comment in code). This is happening before any method is actually tested, so the Tracer doesn't help me.

The DashboardConfig class has two constructors, one that takes a string:
public DashboardConfig(string name);

and another constructor that takes an ISerializable type constructor:
protected DashboardConfig(SerializationInfo si, StreamingContext context)

I can't figure out why setting up this expectation throws an exception. Anyone able to help?
asked by ksummerlin (4k points)

2 Answers

0 votes
Adding a default constructor to the DashboardConfig class:
   public DashboardConfig() : this(string.Empty) { }
   


got rid of the exception. But I don't want this constructor on my class. Does TypeMock.Net require you to have a default constructor for setting up expectations for NaturalMocks?
answered by ksummerlin (4k points)
0 votes
Will send patch offline
answered by scott (32k points)
...