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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:36:19+00:00 2026-05-13T08:36:19+00:00

So I have the following class: public class MyClass { internal void A() {

  • 0

So I have the following class:

public class MyClass {
  internal void A() {
    foreach(Thing thing in ThingArray)
      B(thing);
  }

  virtual internal void B(Thing thing)
  {
    //  do some stuff
  }
}

And then I have the following test:

...
var testObject = new Mock<MyClass>(parameters);
testObject.Setup(t => t.B(It.IsAny<Thing>()));

test.Object.A();

test.Verify(t => t.B(It.IsAny<Thing>()), Times.Exactly(2));

And the verify is failing. I’ve checked, and the code is calling the real B() method as opposed to a mocked B() method.

I’ve got a lot of code running where Moq works perfectly, and I’ve been coding long enough to realize that I must be doing something wrong here, but for the life of me I can’t see it. I’ve been proceeding under the assumption that since I’m calling test.Object.A(), the calls to B() are not going through the Mock, but that really doesn’t make any sense to me since a call from any other object would work the same…

So why on earth isn’t the mocked setup being executed?

Edit: Yes, I have the internals visible to the test project. I meant to put that into the original post, since I knew someone would mention it.

As to the real code, it is unfortunately VERY proprietary, so I can’t post it. I’ll see if I can adjust the code tomorrow to make it actually compile.

  • 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-13T08:36:20+00:00Added an answer on May 13, 2026 at 8:36 am

    I’m not sure if Gamlor’s answer works. It seems that if you want to perform a setup on a method where you want to verify that Class1.MethodA calls Class1.MethodB, MethodB (which is the one you would do the setup on) has to be public (regardless of InternalsVisibleTo). I wrote a simple test under a similar situation and found that once I made my MethodB public, Moq started working. I would bet if you made your method B public, it would work.

    I assume this is a Castle or Moq bug but I don’t know for sure. Hopefully somebody will chime in.

    I know making MethodB public is not a good choice. But that is what I know about the situation…

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

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer customCountries = COUNTRIES.clone customCountries['Europe'] = 'EU' May 13, 2026 at 8:37 pm
  • Editorial Team
    Editorial Team added an answer I don't typically use animate, so I'll leave it to… May 13, 2026 at 8:37 pm
  • Editorial Team
    Editorial Team added an answer Yes, your reasoning is basically correct. You would create a… May 13, 2026 at 8:37 pm

Related Questions

Why does constructor ORDER matter in VB.Net? I am building a .Net type library
Lots of developers think that testing private methods is a bad idea. However, all
So I have a class that looks something like the following: public class MyClass
If I have the following code: public class MyClass { public string myName {
Say I have the following hierarchy: public class MyClass { protected virtual void Method()

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.