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

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think the first method is safer. AFAIK there is… May 11, 2026 at 1:03 pm
  • added an answer currentNumber is one of the elements of numbers, not the… May 11, 2026 at 1:03 pm
  • added an answer Try this: <?php echo get_avatar( $comment, $size = '78', $default… May 11, 2026 at 1:03 pm

Related Questions

How can I Mock Indexed Property with Rhino Mocks ?
How can I get programmatic access to the call stack?
How can I request a random row (or as close to truly random as
How can I set up my crontab to execute X script at 11:59PM every
How can I calculate the value of PI using C#? I was thinking it
I currently have a method within my class that has to call other methods,
I am writing a small app to teach myself ASP.NET MVC, and one of
I've been a fan of EasyMock for many years now, and thanks to SO
I am new to jmock and trying to mock an HttpSession. I am getting:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.