Mock.Arrange with dictionary parameter

6 posts, 0 answers
  1. Carl Rippon
    Carl Rippon avatar
    14 posts
    Member since:
    Mar 2010

    Posted 19 Aug 2010 Link to this post

    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
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 20 Aug 2010 Link to this post

    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
  3. DevCraft R3 2016 release webinar banner
  4. Carl Rippon
    Carl Rippon avatar
    14 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    Unfortunately I am already using version 2010.1.810 - do you have any ideas why this is not working for me?
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 20 Aug 2010 Link to this post

    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
  6. Carl Rippon
    Carl Rippon avatar
    14 posts
    Member since:
    Mar 2010

    Posted 20 Aug 2010 Link to this post

    Thanks for this.
    It does work in the latest version - I hadn't removed and re-added the reference to JustMock in my project.
  7. Chris
    Admin
    Chris avatar
    221 posts

    Posted 20 Aug 2010 Link to this post

    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
Back to Top
DevCraft R3 2016 release webinar banner