This is a migrated thread and some comments may be shown as answers.

Mock.Arrange with dictionary parameter

5 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carl Rippon
Top achievements
Rank 1
Carl Rippon asked on 19 Aug 2010, 01:08 PM
I can't seem to get Mock.Arrange working with a dictionary parameter. I've included some sample code below. I was expecting ret to be equal to "test" but it is coming back as nothing. Have I got the syntax wrong in the Mock.Arrange() call?


<TestClass()> _
Public Class MyTests
 
    <TestMethod()> _
    Public Sub GetValue_ValueReturnedFromDatabase()
        
        Dim ds As IDataService = Mock.Create(Of IDataService)()
        Mock.Arrange(Function() ds.GetValue(Arg.AnyString, Arg.IsAny(Of Dictionary(Of String, Object)))).Returns("test")
        Dim l As New LD(ds)
 
        Dim ret As String = l.GetValue("xxx")
 
        Assert.AreEqual("test", ret)
    End Sub
 
     
End Class
 
 
Public Interface IDataService
    Function GetValue(ByVal SQL As String, ByVal Params As Dictionary(Of String, Object)) As String
End Interface
 
Public Class DS
    Implements IDataService
    Public Function GetValue(ByVal SQL As String, ByVal Params As Dictionary(Of String, Object)) As String Implements IDataService.GetValue
        Return "anything"
    End Function
End Class
 
Public Class LD
    Private _DataService As IDataService
 
    Public Sub New(ByVal DataService As IDataService)
        _DataService = DataService
    End Sub
 
    Public Function GetValue(ByVal Name As String)
        Dim params As New Dictionary(Of String, Object)
        Dim ret As String = _DataService.GetValue("Some SQL", params)
        Return ret
    End Function
End Class

5 Answers, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 20 Aug 2010, 12:48 PM
Hi Carl,

Your test is absolutely correct. However, I found out that when the test is run with the latest patch that is 2010.1. 810, it works nicely but fails when used with 2010.1.713.17 (Q2 build). There were few similar issues that are fixed with the patch. If you are not using it yet,  i would like to ask you to upgrade to it.

Hope, this resolves your issue.

Thanks,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Carl Rippon
Top achievements
Rank 1
answered on 20 Aug 2010, 02:26 PM
Unfortunately I am already using version 2010.1.810 - do you have any ideas why this is not working for me?
0
Ricky
Telerik team
answered on 20 Aug 2010, 02:52 PM
Hi Carl,

Thanks again for your reply. I have attached my project that contains the exact test method that you have pasted in the previous post.

This is the steps I did before running the project:

  1. I downloaded the latest copy of Justmock using my public telerik account
  2. Referenced it into my project (From properties I also ensured that the version number is 2010.1.810.4).
  3. I ran the method and it passed.

Let me know, if the test passes for you in the attached project as well.



Kind regards,
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Carl Rippon
Top achievements
Rank 1
answered on 20 Aug 2010, 03:21 PM
Thanks for this.
It does work in the latest version - I hadn't removed and re-added the reference to JustMock in my project.
0
Chris
Telerik team
answered on 20 Aug 2010, 03:51 PM
Hi Carl,
I'm glad you managed to solve this issue. Should you have some other questions or problems, don't hesitate to contact us.

Regards,
Chris
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Carl Rippon
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Carl Rippon
Top achievements
Rank 1
Chris
Telerik team
Share this question
or