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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:12:21+00:00 2026-05-30T15:12:21+00:00

If I have a dependency IObjectA which contains PropertyA of type IObjectB having a

  • 0

If I have a dependency IObjectA which contains PropertyA of type IObjectB having a public method Foo() in IObjectB.

In order to Verify() Foo() was called can either of these be done, which is correct?

Mock<IObjectA> objectA = new Mock<IObjectA>();
Mock<IObjectB> objectB = new Mock<IObjectB>();

//A
objectA.Verify(x => x.PropertyA.Foo());

//B
objectA.Verify(x => x.PropertyA);
objectB.Verify(x => x.Foo());

“B” seems more correct but does not verify and contradicts my debugging “step through”, “A” however gets the correct results. Can objectA be interrogated for its properties and those properties used for invocation even though it is a mocked type?

  • 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-30T15:12:22+00:00Added an answer on May 30, 2026 at 3:12 pm

    Why do you think B seems more correct?

    Example A is saying inside object A check that PropertyA had foo called on it.

    objectA and objectB are not tied in anyway together in this example. So example B seems misleading in its current form, since it is trying to indicate there is some sort of relation.

    Now if you use setup to assign objectB to objectA then both examples should work (because you are telling Moq how objectA relates to objectB). Doing this setup creates the relationship you are looking to verify.

    Something along the lines of:

    objectA.Setup(x => x.PropertyA).Returns(objectB)
    

    This basically says “when PropertyA is called give me back objectB.“

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

Sidebar

Related Questions

I have a maven dependency in my pom.xml as such: <dependency> <groupId>com.foo</groupId> <artifactId>Bar</artifactId> <version>1.2.3</version>
I have the following dependency property inside a class: class FooHolder { public static
I have a dependency that gets called when the object I'm testing is created.
I have a dependency property on a control which is a custom class. Now
I have several dependency injection services which are dependent on stuff like HTTP context.
i have this Dependency resolver public class NinjectDependencyResolvercs : IDependencyResolver { private readonly IResolutionRoot
In my usercontrol.xaml.cs. I have this dependency proprerty as bleow. public static readonly DependencyProperty
Scenario: I am developing a gem gem-foo , using Bundler. I have a dependency
I have a dependency property defined in my window as below: public static readonly
I have a dependency property (Foreground) on a custom control which is inheriting from

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.