Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 133095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:22:10+00:00 2026-05-11T06:22:10+00:00

How can I mock one method with RhinoMocks in VB.Net? The reference I found

  • 0

How can I mock one method with RhinoMocks in VB.Net? The reference I found is in C#:

 Expect.Call(delegate{list.Add(0);}).IgnoreArguments()       .Do((Action<int>)delegate(int item) {       if (item < 0) throw new ArgumentOutOfRangeException();   });  

SharpDevelop converts this to:

Expect.Call(Function() Do             list.Add(0)             End Function).IgnoreArguments().Do(DirectCast(Function(item As Integer) Do                         If item < 0 Then                             Throw New ArgumentOutOfRangeException()                         End If                        End Function, Action(Of Integer))) 

But that doesn’t work either (it doesn’t compile).

This is what I want to do: create a new object and call a method which sets some properties of that method. In real-life this method, will populate the properties with values found in the database. In test, I would like to mock this method with a custom method/delegate so that I can set the properties myself (without going to the database).

In pseudo-code, this is what I’m trying to do:

 Dim _lookup As LookUp = MockRepository.GenerateMock(Of LookUp)()  _luvalue.Expect(Function(l As LookUp) l.GetLookUpByName('test')).Do(Function(l As LookUp) l.Property = 'value') 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:22:11+00:00Added an answer on May 11, 2026 at 6:22 am

    Unfortunately you’re attempting to do both a Sub lambda and a Statement Lambda. Neither are supported in VS2008 (but will be in the upcoming version of VS). Here is the expanded version that will work for VB

    I’m guessing at the type of m_list

    Class MockHelper   Dim m_list as new List(Of Object)    Public Sub New()      Expect(AddressOf CallHelper).IgnoreArguments().Do(AddressOf Do Hepler)   End Sub    Private Sub CallHelper()      m_list.Add(0)   End Sub    Private Sub DoHelper(ByVal item as Integer)     if item < 0 Then       Throw New ArgumentOutOfRangeException     End If   End Sub End Class 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I mock the initialize method on a ruby class? I'm doing some
How can I Mock Indexed Property with Rhino Mocks ?
Can you do mock page requests with NUnit with webforms? what about web service
I am using Moq to mock my Repository layer so I can unit test.
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can a LINQ enabled app run on a machine that only has the .NET
Can somebody point me to a resource that explains how to go about having
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone tell me how I can display a status message like 12 seconds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.