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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:41:03+00:00 2026-05-11T03:41:03+00:00

How do I verify that method was NOT called in Moq ? Does it

  • 0

How do I verify that method was NOT called in Moq?

Does it have something like AssertWasNotCalled?

UPDATE: Starting from Version 3.0, a new syntax can be used:

mock.Verify(foo => foo.Execute('ping'), Times.Never()); 
  • 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. 2026-05-11T03:41:04+00:00Added an answer on May 11, 2026 at 3:41 am

    UPDATE: Since version 3, check the update to the question above or Dann’s answer below.

    Either, make your mock strict so it will fail if you call a method for which you don’t have an expect

    new Mock<IMoq>(MockBehavior.Strict) 

    Or, if you want your mock to be loose, use the .Throws( Exception )

    var m = new Mock<IMoq>(MockBehavior.Loose); m.Expect(a => a.moo()).Throws(new Exception('Shouldn't be called.')); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it legal to MOQ a class that does not inherit an interface like
Using Moq, I'd like to be able to verify that certain conditions are met
Using RhinoMocks, I have a catch-22 situation: I want to verify that a method
How does QA verify that existing product functionality is still working while verifying new
I want to use ValidationRules to verify that a few ListBox controls have at
Are there any libraries that instrument code to verify that methods called on Swing
The method below that updates the database is called UpdateHold(). This instance of the
I have a method that calls another method of a mocked object with a
I have a class that inherits from an abstract base class. I am trying
How do you 'verify' that a message sent using MSMQ to a private local

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.