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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:34:28+00:00 2026-05-16T22:34:28+00:00

In my unit-tests I’m mocking a protected method using Moq, and would like to

  • 0

In my unit-tests I’m mocking a protected method using Moq, and would like to assert that it is called a certain number of times. This question describes something similar for an earlier version of Moq:

//expect that ChildMethod1() will be called once. (it's protected)
testBaseMock.Protected().Expect("ChildMethod1")
  .AtMostOnce()
  .Verifiable();

...
testBase.Verify();

but this no longer works; the syntax has changed since then and I cannot find the new equivalent using Moq 4.x:

testBaseMock.Protected().Setup("ChildMethod1")
  // no AtMostOnce() or related method anymore
  .Verifiable();

...
testBase.Verify();
  • 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-16T22:34:30+00:00Added an answer on May 16, 2026 at 10:34 pm

    In the Moq.Protected namespace, there is an IProtectedMock interface that has a Verify method taking Times as a parameter.

    Edit
    This is available since at least Moq 4.0.10827. Syntax example:

    testBaseMock.Protected().Setup("ChildMethod1");
    
    ...
    testBaseMock.Protected().Verify("ChildMethod1", Times.Once());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing unit tests for a family of functions that all share a number
For unit tests, demonstrations and Hibernate tasks I would like to use a small
I'm writing unit tests using nose , and I'd like to check whether a
Quite often I have unit tests using MSTest for code that is in a
For unit tests I would like to mimic different commandline arguments. How do I
I was writing some Unit tests last week for a piece of code that
I've made some unit tests (in test class). The tutorial I've read said that
We are currently using unit tests to test our project. We have the majority
Maintaining unit tests is difficult. I am sure that we all have experienced a
My unit tests are doing something very strange when I call a method of

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.