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
   Dim recorder As New RecordExpectations

        Try
            SmartTextManager.GetInstance.SetProfileValue(Nothing)
            recorder.Repeat(3)
        Catch ex As Exception
        Finally
            recorder.Dispose()
        End Try

        SmartTextManager.GetInstance.SetProfileValues(aDocument)
        MockManager.Verify


The above code works as expected. However the following code tells me that Mockmanager expects two more calls to SetProfileValue and 2 more calls to GetInstance. Aren't the two pieces of code identical? I want to use the second form, because I want to be able to check the arguments:

   Dim recorder As New RecordExpectations

        Try
            SmartTextManager.GetInstance.SetProfileValue(Nothing)
            SmartTextManager.GetInstance.SetProfileValue(Nothing)
            SmartTextManager.GetInstance.SetProfileValue(Nothing)
        Catch ex As Exception
        Finally
            recorder.Dispose()
        End Try

        SmartTextManager.GetInstance.SetProfileValues(aDocument)
        MockManager.Verify
asked by diangy (2.4k points)

4 Answers

0 votes
Hi,

Actually its the below code that works as expected. Since you set the expectation to wait for the call to be executed 3 times. MockManager will give an error unless you call this code 3 times. In both th examples you called it just once, hence the missing 2 calls.

Can you also specify which version you are using. We had some issues with the repeat behavior that were solved in 4.0.2. In the meantime Ill check to see if this was one of them.
answered by lior (13.2k points)
0 votes
Hi,
Just to point out the two pieces of code are not identical.

This has to do with understanding the Repeat and Chained Statements.
:arrow: When using Repeat/Return TypeMock refers to the LAST statement in the chain.


So the first example expects 1 call to SmartTextManager.GetInstance and 3 calls to SetProfileValue on the returned instance.
While the second example expects 3 calls to SmartTextManager.GetInstance and each call expects 1 call to SetProfileValue.

Currently to repeat all the statements in the chain use:
recorder.DefaultBehavior.Repeat(3)
SmartTextManager.GetInstance.SetProfileValue(Nothing)


this will tell TypeMock to repeat all the methods in the chain.
answered by scott (32k points)
0 votes
Actually

SmartTextManager.GetInstance.SetProfileValues(aDocument)

(the method is SetProfileValues with an s at the end)

calls

SmartTextManager.GetInstance.SetProfileValue(Nothing) 

(the method is SetProfileValue without an s)

thrice within a loop. That's what I wanted to mock. I probably need the update. I have 4.0.1.
answered by diangy (2.4k points)
0 votes
I was reading through your reply and it made perfect sense. LOVE your product. Already bought it and it just made me able to test some legacy code that I absolutely HAVE to test before the month is out.

Thanks
answered by diangy (2.4k points)
...