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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi

I'm trying to mock a interface, these are the expectations:

Using recorder As New RecordExpectations

mockedDataContext.GetCycleByBarn(Nothing)
recorder.Return(cycle)

mockedDataContext.GetActiveProductForCorral(5, today)
recorder.Return(product1)

mockedDataContext.GetLastFeedingDateByProduct(1, today)
recorder.Return(yesterdayAsSqlDateTime)

mockedDataContext.GetActiveProductForCorral(5, today)
recorder.Return(product2)

mockedDataContext.GetLastFeedingDateByProduct(1, today)
recorder.Return(yesterdayAsSqlDateTime)

mockedDataContext.GetActiveProductForCorral(-5, today)
recorder.Return(Nothing)

mockedDataContext.GetActiveProductForCorral(-10, today)
recorder.Return(Nothing)

End Using

As you can see, I only return prebuilt objects. These are the definitions of the dates I'm using:

Private today As DateTime = DateTime.Today
Private yesterday As DateTime = DateTime.Today.AddDays(-1)
Private yesterdayAsSqlDateTime As SqlDateTime = New SqlDateTime(yesterday)

The mockedDataContext object is created this way in a setup method:

mockedDataContext = DirectCast(MockManager.MockObject(GetType(IFeedDistributionCalculatorDataContext)).Object, IFeedDistributionCalculatorDataContext)

The problem is that when I run my test, it fails with the following message:

TypeMock.VerifyException:
TypeMock Verification: Method System.Data.SqlTypes.SqlInt32.op_Implicit() has 2 more expected calls
Method System.Data.SqlTypes.SqlDateTime.op_Implicit() has 2 more expected calls

I don't know which calls it's talking about! Am I missing something? I tried reproducing this with a small example, but it works, so I guess I'm doing something wrong.

Thanks in advance,
Julián
asked by Julian (1.8k points)

4 Answers

0 votes
Hi Julian,

Since you haven't posted the entire code, I couldn't reproduce it, so I'm a bit guessing here. But it looks like there are hidden calls within the recording block (SQLDateTime maybe that are being recorded, without you knowing it.

I'll go with the easy solution: Try reflective mocks:
Dim mock As MockObject
mock = MockManager.MockObject(GetType(IFeedDistributionCalculatorDataContext))
mock.ExpectAndReturn("GetCycleByBarn", cycle) '.Args(Nothing)
mock.ExpectAndReturn("GetActiveProductForCorral", product1) '.Args(5, today)
mock.ExpectAndReturn("GetLastFeedingDateByProduct", yesterdayAsSqlDateTime) '.Args(1, today)
mock.ExpectAndReturn("GetActiveProductForCorral", product2) '.Args(5, today)
mock.ExpectAndReturn("GetLastFeedingDateByProduct", yesterdayAsSqlDateTime) '.Args(1, today)
mock.ExpectAndReturn("GetActiveProductForCorral", Nothing) '.Args(-5, today)
mock.ExpectAndReturn("GetLastFeedingDateByProduct", yesterdayAsSqlDateTime) '.Args(-10, today)
mockedDataContext = DirectCast(mock.Object, IFeedDistributionCalculatorDataContext)


I've commented out the Args part in case you don't want to check the arguments.

Let me know if this works for you.
answered by gilz (14.5k points)
0 votes
Hi!

Thanks for replying.

>But it looks like there are hidden calls within the recording block(SQLDateTime maybe that are being recorded, without you knowing it.

I don't see how. I'm not using any expression other than the method calls. I'll try what you suggest and tell you how it goes (I'm not not keen on using reflective mocks however).

Regards,
Julián
answered by Julian (1.8k points)
0 votes
Hi Julian,

You are right,
basically this shouldn't happen and it is probably caused by something that happens in the background or by a problem in the Isolator framework itself.

However from your previous post we were unable to reconstruct and reproduce the issue.
Would it be possible to get a more complete example of the test in which this is happening?
Basically what we require is a small SLN containing just this test demonstrating the failure.

If thats not possible what might also be helpful is getting the logs and trace data. We might be able to understand from them what has gone wrong.

In any case ill send you an email with details on how to produce the logs.
answered by lior (13.2k points)
0 votes
With reflective mocks it works. I'm puzzled. I received an e-mail from Lior, I'll try to reproduce the problem again with a smaller project or else I'll send the trace logs he requested.
answered by Julian (1.8k points)
...