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

  • SEARCH
  • Home
  • 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 6364967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:14:02+00:00 2026-05-25T00:14:02+00:00

I am using Rhino Mocks. I have a data repository, a small part of

  • 0

I am using Rhino Mocks. I have a data repository, a small part of it is defined like this,

interface IDataRepository
{
    void GetCurrentUserId(Action<int?> callback);
}

This is on the client side of a silverlight RIA services application, thus why we have an Action callback. This will callback once the operation has been completed on the server, and there is a result.

To unit test something that calls that method I end up doing this,

private delegate void GetCurrentUserIdDelegate(Action<int?> callback);

private void GetCurrentUserId(Action<int?> callback)
{
    callback.Invoke(10);
}

[TestMethod]
public void TestBlah()
{
    var mockRepository = MockRepository.GenerateMock<IDataRepository>();

    mockRepository.Expect(r => r.GetCurrentUserId(null)).IgnoreArguments().Do(new GetCurrentUserIdDelegate(GetCurrentUserId));
}

It works fine, but it seems very verbose. Isn’t there a more concise way of doing it?

I am going to have to define a delegate for each of the methods in the IDataRepository interface that have callbacks in them. To me this seems a bit messy, hard to maintain, etc.

Perhaps there is an inline way of doing it without needing to define the delegates?

  • 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. Editorial Team
    Editorial Team
    2026-05-25T00:14:03+00:00Added an answer on May 25, 2026 at 12:14 am

    The delegate you pass should just have the same signature as the mocked method, so in your case you can use Action<Action<int?>>:

    mockRepository
        .Expect(r => r.GetCurrentUserId(null))
        .IgnoreArguments()
        .Do(new Action<Action<int?>>(act => { act(10); }));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started using Rhino mocks and I am having difficulty doing that.
I have just crafted the following test using Rhino mocks. Does my test look
Does anyone have an implementation lying around of an auto-mock container using Rhino Mocks
a have some artefacts when using Rhino Mocks var mocks = new MockRepository(); INotifyMessageSender
I have been using Moq and initially Rhino Mocks over the last year together
I have a Data Service interface with a method: void GetDataByLocationId(Guid locationId, Action<InvokeOperation<IEnumerable<DataValue>>> callback);
I am using Rhino Mocks 3.6. I have seen many types of coding. Sometimes
I am using Rhino Mocks as a mocking framework for unit testing. I have
I'm having a problem with Rhino Mocks. My Test method looks like this: MockRepository
I have read a lot about mocking, particularly using Rhino Mocks and have learned

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.