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
I was trying to use Natural Mocks to mock the following

Public Sub TestSub()
Using recorder As New RecordExpectations
Dim instanceClass As ClassUnderTest = ClassUnderTest.NewClass
Dim returnString As String = instanceClass.Name
recorder.Return("My Name")
End Using
End Sub

Public Class ClassUnderTest
Private Sub New()

End Sub

Public Shared Function NewClass() As ClassUnderTest
Return New ClassUnderTest
End Function

Public ReadOnly Property Name() As String
Get
Return "TestName"
End Get

End Property
End Class

Unfortunately, I keep getting "Cannot use Return in this sequence, there must be a mocked statement first".
I don't understand why. If the ClassUnderTest is a normal class with public constructors, I don't get the error.
While I can use Reflective Mocks, I'd like to learn why Natural Mocks don't work in this instance.

Thanks.
asked by jimmyseow123 (4.6k points)

10 Answers

0 votes
Hi,

Actually this is weird, cause Ive just duplicated your example and it works fine on our side.

Try rewriting your test as follows and let me know if this helps or not:
<TestMethod(), VerifyMocks()> _
    Public Sub CtorTest()
        Dim mock1 As ClassUnderTest = RecorderManager.CreateMockedObject(Of ClassUnderTest)()
        Using recorder As New RecordExpectations
            Dim instanceClass As ClassUnderTest = ClassUnderTest.NewClass
            recorder.Return(mock1)
            Dim returnString As String = mock1.Name
            recorder.Return("My Name")
        End Using
        Dim target As ClassUnderTest = ClassUnderTest.NewClass
        Assert.AreEqual("My Name", target.Name)
    End Sub


If that still doesn't help, let us know what version you are working on.
and we will take it offline fur further investigation.
answered by lior (13.2k points)
0 votes
I've found out what was wrong.
I was using the debugger to step through the RecordExpectations code. If I set the breakpoint AFTER the RecordExpections code, then everything works fine.
It wasn't very clear that I cannot use the debugger to step through the RecordExpectations code.

Thanks and regards,
Jimmy
answered by jimmyseow123 (4.6k points)
0 votes
Hi Jimmy,

We had a bug fixed relating to this starting in Isolator version 4.2. What version of are you using?
answered by gilz (14.5k points)
0 votes
I just downloaded the latest version from Web and hit the same bug.
Thanks for the workaround from Jimmy to unblock me.

On the other hand you can only repro this bug if the RecodrdExpactations code is in Vs 2008 unittest project.

Let me know if you need more info to repro the issue.
answered by bertan (180 points)
0 votes
I'm using Typemock 4.1.0.0.
My unit testing framework is MBUnit 2.4.197.
answered by jimmyseow123 (4.6k points)
0 votes
Jimmy,

Can you try upgrading to Typemock version 4.3 (released yesterday, you can get it from our site) and let me know if the problem recurs?

Bertan,

I'd like to repro this issue, lets will take this offline with you via email.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Thanks but as I don't have the license for the latest version, I'd rather not reinstall as I would have to again reinstall my present version after testing.
I'd rather just leave it as is as it's not something major for me.

Thanks for all your help.
answered by jimmyseow123 (4.6k points)
0 votes
Hi Jimmy,

I want to make sure you're running into the problem we fixed in 4.2.

I'd like you to reproduce it with the Tracer application on. Run it first from Program Files->Typemock Isolator->Isolator Tracer.
Reproduce the problem, and then after you complete, export the files and send it to us: support AT typemock dot com. I'd like to get a look at that.

While I understand you'd like to remain with the old version, I recommend moving to the latest version. It has more fixes and it will probably fix this.
answered by gilz (14.5k points)
0 votes
Doron,

Have you contacted with me vie e-mail? I don't see any e-mail.

Thanks
answered by bertan (180 points)
0 votes
Bertan,

I sent you an email last week, don't know how come it wasn't delivered. I forwarded it again to the email address you registered with, and I hope it will come through this time. Please let me know if you didn't get it again and we'll work it out.

Doron
Typemock Support

Doron,

Have you contacted with me vie e-mail? I don't see any e-mail.

Thanks
answered by doron (17.2k points)
...