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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:11:51+00:00 2026-06-08T02:11:51+00:00

(As indicated by the tags, I am using moq). I have an interface like

  • 0

(As indicated by the tags, I am using moq).

I have an interface like this:

interface ISource
{
  string Name { get; set; }
  int Id { get; set; }
}

interface IExample
{
  string Name { get; }
  ISource Source { get; set; }
}

In my application, concrete instances of IExample accept a DTO (IDataTransferObject) as the Source. Some properties on the concrete implementation of IExample are simply delegated to the Source. Like this…

class Example : IExample
{
  IDataTransferObject Source { get; set; }

  string Name { get { return _data.Name; } }
}

I would like to create a standalone mock of IExample (standalone meaning that I cannot use a captured variable because several instances of the IExample mock will be created in the course of a test) and setup the Mock such that IExample.Name returns the value of IExample.Source.Name. So, I would like to create a mock something like this:

var example = new Mock<IExample>();
example.SetupProperty(ex => ex.Source);
example.SetupGet(ex => ex.Name).Returns(what can I put here to return ex.Source.Name);

Essentially, I want to configure the mock to return, as the value of one property, the value of a property of a subobject of the mock.

Thanks.

  • 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-08T02:11:52+00:00Added an answer on June 8, 2026 at 2:11 am

    You could probably use:

    example.SetupGet(ex => ex.Name).Returns(() => example.Object.Source.Name);
    

    The value to be returned will then be determined when the property is accessed, and will be taken from Name property of the mock’s Source property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Tags table CREATE TABLE IF NOT EXISTS `Tags` ( `id_tag` int(10)
I want to replace xml tags that look like this: <indicator itype=ST ind=U/> with
As indicated in title, right now I have captured the event when the session
I have a lot of cycles ( indicated by numeric values, for example, 1-2-3-4
I have an XML document with a default namespace indicated at the root. Something
I have a text file containing strings to encrypt. These strings are indicated by
I have a Grails 2.0.0 project that was created using grails create-app . In
I've heavily edited this question because responses indicated I wasn't being clear problem: UI
I have a Razor page with a drop down list inside a form: @using
I'm using the recaptcha gem (github.com/ambethia/recaptcha) but have been unable to change from the

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.