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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:05:53+00:00 2026-06-07T01:05:53+00:00

Using JustMock, can I arrange a mock to return something based on the input

  • 0

Using JustMock, can I arrange a mock to return something based on the input parameter?

For example, say a method takes in an int, I want to return that value + 1
I want the output to always be mocked as input+1 but I don’t know the input at design time.

My real usage for this is with an object parameter and I need to mock to always return a new object having some of the same properties… but I do not know how to reference the parameters in the .Returns() section.

EDIT: More details:

Three types:
IMoneyConverter
Money
Currency

A Money object has two properties: decimal valueAmount and Currency valueCurrency

IMoneyConverter exposes:

.Convert(Money valueFrom, Currency currencyTo, DateTime asOfDate)

This method returns the converted Money object, in the new Currency (currencyTo) as of the specified date.

My intent is to mock the IMoneyConverter so that its .Convert method returns a new Money object having the amount of the Money (valueFrom) parameter and the Currency of the currencyTo parameter.

  • 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-07T01:05:55+00:00Added an answer on June 7, 2026 at 1:05 am

    I’m not 100% sure I understood the exact requirements, but this test works and I believe will demonstrate how to accomplish what you want:

    [Test]
    public void SampleTest() {
       IMoneyConverter mock = Mock.Create<IMoneyConverter>();
       mock.Arrange( x => x.Convert( Arg.IsAny<Money>(), Arg.IsAny<Currency>(), Arg.IsAny<DateTime>() ) )
          .Returns( (Func<Money,Currency,DateTime,Money>)
             ( (m, c, d ) => new Money { ValueAmount = m.ValueAmount, Currency = c }) );
    
       Money inMoney = new Money() { ValueAmount = 42 };
       Currency inCurrency = new Currency();
       Money outMoney = mock.Convert( inMoney, inCurrency, DateTime.Now );
       Assert.AreEqual( 42, outMoney.ValueAmount  );
       Assert.AreSame( inCurrency, outMoney.Currency );
    }
    
    public interface IMoneyConverter {
       Money Convert( Money valueFrom, Currency currencyTo, DateTime asOfDate );
    }
    
    public class Money {
       public decimal ValueAmount { get; set; }
       public Currency Currency { get; set; }
    }
    
    public class Currency {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JustMock to mock interfaces for unit testing, but perhaps I'm not
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
I would like to Mock the System.IO.FileInfo.Extension Method and have it return .xls but
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
Using jQuery, one can easily find out whether a particular element is visible using
Using Android TelephonyManager an application can obtain the state of data activity over the
using a binary search tree I need to add to a vector all int
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle

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.