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 8347777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:28:20+00:00 2026-06-09T07:28:20+00:00

I am trying to arrange the input parameter of the lambda that is passed

  • 0

I am trying to arrange the input parameter of the lambda that is passed to ICallback#Regsiter<T>(Action<T>) in the (paired down) unit test sample below (see the comments in the unit test sample). I am trying to avoid having to abstract out the lambda because it’s so specific and small, but I’m not sure if that’s possible.

// IBus interface peek
public interface IBus {
    ICallback Send(IMessage message);
}

// ICallback interface peek
public interface ICallback {
    void Register<T>(Action<T> callback);
}

public enum ReturnCode { Success }

// Controller
public class FooController : AsyncController {
    readonly IBus _bus;
    //...
    // Action being unit tested
    public void BarAsync() {
        _bus
            .Send(ZapMessageFactory.Create())
            .Register<ReturnCode>(x => {
                AsyncManger.Parameters["returnCode"] = x;
            });
    }

    public ActionResult BarCompleted(ReturnCode returnCode) {
        // ...
    }
}

// Controller action unit test
[TestClass]
public class FooControllerTest {
    [TestMethod}
    public void BarTestCanSetAsyncManagerParameterErrorCodeToSuccess() {
        var fooController = ControllerUTFactory.CreateFooController();
        // HOW DO I MOCK THE ACTION DELEGATE PARAMETER TO BE ReturnCode.Success
        // SO I CAN DO THE ASSERT BELOW???
        fooController.BarAsync();
        Assert.AreEqual(ReturnCode.Success, (ReturnCode)fooController.AsyncManager.Parameters["returnCode"]);
    }
}
  • 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-06-09T07:28:21+00:00Added an answer on June 9, 2026 at 7:28 am

    Using the Mock<T>#Callback() is the answer:

    [TestMethod}
    public void BarTestCanSetAsyncManagerParameterErrorCodeToSuccess() {
        var mockCallback = new Mock<ICallback>();
        mockCallback
                .Setup(x => x.Register(It.IsAny<ReasonCode>())
                // THIS LINE IS THE ANSWER
                .Callback(action => action(ReasonCode.Success));
        var mockBus = new Mock<IBus>();
        mockBus
                .Setup(x => x.Send(It.IsAny<ZapMessage>())
                .Returns(mockCallback.Object);
    
        var fooController = new FooController(mockBus.Object);
    
        fooController.BarAsync();
        Assert.AreEqual(ReturnCode.Success, (ReturnCode)fooController.AsyncManager.Parameters["returnCode"]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to arrange two buttons in an horizontal LinearLayout so that they
I'm trying to test some application logic that is dependent on the Values property
I'm trying to write a test for an ASP.Net MVC controller action. I'd like
I've been trying to arrange my cells in my table row below such that
I'm trying to obtain a text input visual element that to look unitary but
I am trying to use a wxSizer to arrange widgets inside a panel. I
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
trying to figure out why this is happening - I have an input text
i'm trying to use a regexp to arrange some text, with re.sub . Let's
Benn trying to test a service layer method which returns a simple IList using

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.