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
Unable to access a function using the mockobject created. Below is the sample code:
[DeploymentItem("xyz.dll")]
[TestMethod()]
public void UpdateXTest()
{
XSum mockXSum =RecorderManager.CreateMockedObject(typeof(XSum)) as XSum;


using (RecordExpectations recorder = RecorderManager.StartRecording())
{
mockXSum.UpdateX();
}

}

Whenever mockXSum.UpdateX() is executed, the code for test cleanup is executed and the test fails and the error message is,
*** Cannot return a value for AssemblyResolver.OnResolve() because no value was set. use recorder.Return().
*** Note: Cannot mock types from mscorlib assembly..

Code for test cleanup:
[TestCleanup()]
public void MyTestCleanup()
{
MockManager.Verify();
}


I am using TypeMock.NET version 4.1.0.0.
Note: I am able to call other function in XSum using the mockobject created.
asked by vani183 (1.7k points)

4 Answers

0 votes
The error message probably happens because you haven't set any return value on mockXSum.UpdateX():

using (RecordExpectations recorder = RecorderManager.StartRecording()) 
{ 
mockXSum.UpdateX(); 
recorder.Return(someValue);
//assuming UpdateX was returning bool you could write recorder.Return(false); 
}

I would also recommand using Verfiy as part of the test and not as part of TestCleanup and use [ClearMocks] attribute on your test method as well
answered by dhelper (11.9k points)
0 votes
The error message probably happens because you haven't set any return value on mockXSum.UpdateX():

using (RecordExpectations recorder = RecorderManager.StartRecording()) 
{ 
mockXSum.UpdateX(); 
recorder.Return(someValue);
//assuming UpdateX was returning bool you could write recorder.Return(false); 
}

I would also recommand using Verfiy as part of the test and not as part of TestCleanup and use [ClearMocks] attribute on your test method as well


But UpdateX() does not return any value.
answered by vani183 (1.7k points)
0 votes
Very interesting, I'd like to further investigate this issue let's take it offline
answered by dhelper (11.9k points)
0 votes
Hi,

What causing the error is the .NET CLR loading an assembly inside the recording block. this maks the isolator try to set an expectation on that call which fails wiuth the error you see.

The good news is that this defect as far as I know has been solved apparently in a more recent version then 4.1.0.
:?: Dror - can you verify that the defect has been indeed fixed?

:idea: I suggest that you try to upgrade to a newer version and check the same test again.

Hope this helps
_________________
Lior
Agile Consultant - AUT/TDD Expert
http://imistaken.blogspot.com
answered by error (6.6k points)
...