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
Hi,

I've got a handful of tests that have started throwing a Typemock exception at various points on objects that are not mocked.

The exception details is as follows:

System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
Source="TypeMock"
StackTrace:
at bl..cctor()
InnerException:

Removing all references to Typemock resolves the issue, but of course I can no longer run the tests as I need to mock some objects.

I've tried Natural and AAA mocking.

Any ideas?

Thanks,
John
asked by Imaji (2.2k points)

3 Answers

0 votes
Hi John,

When did you start seeing these issues? was it following a version upgrade or some other change in the project?

Can you post a sample test that causes this issue here?

Thanks,
Doron
Typemock Support
answered by doron (16.5k points)
0 votes
Hi Doron,

Nope, no version upgrade we're still using 5.1.2 x64.

It was the beginning of this week. The only thing I've done is to change the way a Unity Container was being populated. It's moved from being from a config file to mocking.

I've also noted that all tests in this test class now throw this error when debugging, but pass when run :(

An example test method (with sanitised types):

[TestInitialize]
public void InitialiseWorkflowRuntime()
{
m_WorkflowRuntime = new WorkflowRuntime();

// By using a Manual Scheduler, we can make the Activity execute when we want
m_Scheduler = new ManualWorkflowSchedulerService();
m_WorkflowRuntime.AddService(m_Scheduler);

m_WorkflowRuntime.WorkflowCompleted += WorkflowCompleted;
m_WorkflowRuntime.WorkflowTerminated += WorkflowTerminated;

m_Exception = null;
m_Result = null;
}

[TestCleanup]
public void CleanupWorkflowRuntime()
{
m_WorkflowRuntime.WorkflowCompleted -= WorkflowCompleted;
m_WorkflowRuntime.WorkflowTerminated -= WorkflowTerminated;
m_WorkflowRuntime.Dispose();
}

[TestMethod]
[VerifyMocks]
public void TestMethod()
{
UnityContainer populatedContainer = GetPopulatedContainer();

using (RecordExpectations recorder = new RecordExpectations())
{
UnityContainer unity = new UnityContainer();
recorder.Return(populatedContainer);

populatedContainer.LoadConfigurationFiles("Container");
}

Dictionary<string> parameters = new Dictionary<string> { { PropertyName, m_Value } };

WorkflowInstance instance = m_WorkflowRuntime.CreateWorkflow(typeof(Activity), parameters);
instance.Start();
m_Scheduler.RunWorkflow(instance.InstanceId);

Assert.IsNull(m_Exception);
Assert.IsNotNull(m_Result);

Message outputMessage = m_Result[NewMessagePropertyName] as Message;

Assert.IsNotNull(outputMessage);

outputMessage.MessageText = TestMessage;

Assert.AreEqual(expectedResult, builtMessage);
}

The exception can occur on any of the non mocked object during the TestInitialise or Arrange or during setting the expectations.

Cheers,
John
answered by Imaji (2.2k points)
0 votes
Hi John,

It might be that Visual Studio debugs with notification on all exceptions.

Is it possible that this is the case when you debug? (In Visual Studio: Debug->Exceptions check if any check box is checked in the Thrown column).

Best Regards,
Elisha
Typemock Support Team
answered by Elisha (12k points)
...