0

I have a function TryGetValues that receives a TKey and ByRef a TValue, and I need when I mock this function to return me something. I need the value of TValue because later in the method I'm testing I'm going to need this. The way I use to test it is:

Dim agent = Mock.Get(Of ICalcAgent)()
Dim connections As IList(Of ICalcMapConnection) = Nothing
agent.CalcMap = Mock.Get(Of ICalcMap)()
agent.CalcMap.Stub(Function(x) x.TryGetCategoryChildren(agent, connections)).IgnoreArguments().OutRef(agent, connections).Repeat.Once().Return(True)

In this case I need Connections to be something. How do I do that with Rhino?

Sub AddConnection(ByRef cnn As ICalcMapConnection)
Sub AssignWeightToConnections()
Function TryGetCategoryParents(ByRef agent As ICalcAgent, ByRef parentsList As IList(Of ICalcMapConnection)) As Boolean
Function TryGetCategoryChildren(ByRef agent As ICalcAgent, ByRef childrenList As IList(Of ICalcMapConnection)) As Boolean
ReadOnly Property MapType() As MapType
Function GetMaxWeight(ByVal categoryId As Integer) As Integer
Function HasConnection(ByVal connection As ICalcMapConnection) As Boolean
Function HasCategory(ByVal categoryId As Integer) As Boolean
Function GetLeafCategories() As IEnumerable(Of Integer)
Function GetCategoryDefinition(ByRef agent As Interfaces.ICalcAgent) As ICalcMapConnection
Function GetLeafConnection(ByVal categoryId As Integer) As ICalcMapConnection
Sub RegisterCostCollectorCategory(ByVal connection As ICalcMapConnection)
Sub RegisterWBSCategory(ByVal connection As ICalcMapConnection)
Sub RegisterManualCategory(ByVal connection As ICalcMapConnection)

Function GetCostCollectorLeafCategories() As IList(Of ICalcMapConnection)
Function GetWBSLeafCategories() As IList(Of ICalcMapConnection)
Function GetManualCategories() As IList(Of ICalcMapConnection)


Sub AddWbs(ByVal wbsId As Integer)
Function HasWbs(ByVal wbsId As Integer) As Boolean

Sub AddCostCollector(ByVal costCollectorId As Integer)
Function HasCostCollector(ByVal costCollectorId As Integer) As Boolean
juan
  • 1
  • 1
  • Can you provide the definition for ICalcMap? At least the TryGetCategoryChildren method. – PatrickSteele Jun 29 '12 at 20:32
  • the TryGetCategoryChildren calls the function TryGetValue that is a function by default of VB.net – juan Jun 29 '12 at 20:44
  • I didn't ask what it does. It would be easier to help you if you showed the interface definition (since that is what you need help mocking). Implementation details are irrelevant. – PatrickSteele Jun 29 '12 at 23:18
  • Sub AddConnection(ByRef cnn As ICalcMapConnection) Sub AssignWeightToConnections() Function TryGetCategoryParents(ByRef agent As ICalcAgent, ByRef parentsList As IList(Of ICalcMapConnection)) As Boolean Function TryGetCategoryChildren(ByRef agent As ICalcAgent, ByRef childrenList As IList(Of ICalcMapConnection)) As Boolean ReadOnly Property MapType() As MapType Function GetMaxWeight(ByVal categoryId As Integer) As Integer – juan Jun 30 '12 at 00:05
  • Function HasConnection(ByVal connection As ICalcMapConnection) As Boolean Function HasCategory(ByVal categoryId As Integer) As Boolean Function GetLeafCategories() As IEnumerable(Of Integer) Function GetCategoryDefinition(ByRef agent As Interfaces.ICalcAgent) As ICalcMapConnection Function GetLeafConnection(ByVal categoryId As Integer) As ICalcMapConnection Sub RegisterCostCollectorCategory(ByVal connection As ICalcMapConnection) Sub RegisterWBSCategory(ByVal connection As ICalcMapConnection) Sub RegisterManualCategory(ByVal connection As ICalcMapConnection) – juan Jun 30 '12 at 00:05
  • Function GetCostCollectorLeafCategories() As IList(Of ICalcMapConnection) Function GetWBSLeafCategories() As IList(Of ICalcMapConnection) Function GetManualCategories() As IList(Of ICalcMapConnection) Sub AddWbs(ByVal wbsId As Integer) Function HasWbs(ByVal wbsId As Integer) As Boolean Sub AddCostCollector(ByVal costCollectorId As Integer) Function HasCostCollector(ByVal costCollectorId As Integer) As Boolean – juan Jun 30 '12 at 00:06
  • those are all the functions that this interface implements – juan Jun 30 '12 at 00:06
  • Sorry @juan -- could you please add them to the question (easier to read that way). – PatrickSteele Jun 30 '12 at 12:37
  • i have just added to the question – juan Jun 30 '12 at 22:06
  • If I'm reading your code correct (it's been a long time since I've done any VB.NET), your code looks like it should work as-is. If you need 'connnections' to be something, set it to what you want it to be and Rhino.Mocks should use that as the return value based on your use of the OutRef option. – PatrickSteele Jul 02 '12 at 13:59

0 Answers0