Using DoInstead for a private method

2 posts, 1 answers
  1. Wietze
    Wietze avatar
    1 posts
    Member since:
    Jul 2012

    Posted 12 Dec 2012 Link to this post

    Hi I have this situation.

    Public Class PrivateMethodDoInstead
        Private Function GetSomeQuantity(ByRef quantity As Long) As Boolean
            '....get quantity from the database code would be here
            Return quantity > 0
        End Function
        Public Function HandleRecords() As Boolean
            Dim quantity As Long
            Dim returnValue As Boolean = GetSomeQuantity(quantity)
            If returnValue Then
            End If
            Return returnValue
        End Function
        Private Sub StoreTotals(quantity As Long)
            ' do something
        End Sub
    End Class

    I would like to Mock my private function GetSomeQuantity.
    It is private. When it is public it would work by doing this:

    Mock.Arrange(Function() testInstance.GetSomeQuantity(
         Arg.IsAny(Of Long))
        ).DoInstead(Function(ByRef quantity As Long) As Boolean
                        quantity = 5
                        Return True
                    End Function).Returns(True)

    But how can I do this for a private function?
    I did try it using the nonpublic, but it keeps giving me an error that it cannot resolve the method and that I should check my arguments.

    Any help would be appreciated.


  2. Answer
    Kaloyan avatar
    872 posts

    Posted 13 Dec 2012 Link to this post

    Hi Wietze,

    Thank you again for contacting Telerik support.

    Unfortunately, we don't support mocking of out/ref arguments for non-public method. However, we are working on this and planning to include it in one of our recent builds.

    As we want to deliver the best support to our users, I'd like to ask you one off-topic question that will help us do so. Your feedback will be much appreciated.
    As I can see, you are using VB.Net, so I would like to ask if you are interested in having test examples in VB.Net into the JustMock documentation?

    Thank you for the feedback.
    All the best,
    the Telerik team
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
Back to Top