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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:23:26+00:00 2026-06-11T14:23:26+00:00

Coming from using Moq, I’m used to being able to Setup mocks as Verifiable.

  • 0

Coming from using Moq, I’m used to being able to Setup mocks as Verifiable. As you know, this is handy when you want to ensure your code under test actually called a method on a dependency.

e.g. in Moq:

// Set up the Moq mock to be verified
mockDependency.Setup(x => x.SomethingImportantToKnow()).Verifiable("Darn, this did not get called.");
target = new ClassUnderTest(mockDependency);
// Act on the object under test, using the mock dependency
target.DoThingsThatShouldUseTheDependency();
// Verify the mock was called.
mockDependency.Verify();

I’ve been using VS2012’s “Fakes Framework” (for lack of knowing a better name for it), which is quite slick and I’m starting to prefer it to Moq, as it seems a bit more expressive and makes Shims easy. However, I can’t figure out how to reproduce behavior similar to Moq’s Verifiable/Verify implementation. I found the InstanceObserver property on the Stubs, which sounds like it might be what I want, but there’s no documentation as of 9/4/12, and I’m not clear how to use it, if it’s even the right thing.

Can anyone point me in the right direction on doing something like Moq Verifiable/Verify with VS2012’s Fakes?

— 9/5/12 Edit —
I realized a solution to the problem, but I’d still like to know if there’s a built-in way to do it with VS2012 Fakes. I’ll leave this open a little while for someone to claim if they can. Here’s the basic idea I have (apologies if it doesn’t compile).

[TestClass]
public class ClassUnderTestTests
{
    private class Arrangements
    {
        public ClassUnderTest Target;
        public bool SomethingImportantToKnowWasCalled = false;  // Create a flag!
        public Arrangements()
        {
            var mockDependency = new Fakes.StubIDependency  // Fakes sweetness.
            {
                SomethingImportantToKnow = () => { SomethingImportantToKnowWasCalled = true; }  // Set the flag!
            }
            Target = new ClassUnderTest(mockDependency);
        }
    }

    [TestMethod]
    public void DoThingThatShouldUseTheDependency_Condition_Result()
    {
        // arrange
        var arrangements = new Arrangements();
        // act
        arrangements.Target.DoThingThatShouldUseTheDependency();
        // assert
        Assert.IsTrue(arrangements.SomethingImportantToKnowWasCalled);  // Voila!
    }
}

— 9/5/12 End edit —

  • 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-11T14:23:27+00:00Added an answer on June 11, 2026 at 2:23 pm

    Since I’ve heard no better solutions, I’m calling the edits from 9/5/12 the best approach for now.

    EDIT
    Found the magic article that describes best practices. http://www.peterprovost.org/blog/2012/11/29/visual-studio-2012-fakes-part-3/

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

Sidebar

Related Questions

Coming from a background using Visual Studio and Notepad++ I'm used to the indent
Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine() : (Note that
Coming from this previous question: Using Obscure and UnObscure...Am I doing this right? 1:
Coming from the asp.net webforms model I'm used to using validators which display an
I'm using this example to store in the database the info coming from PayPal,
I'm trying to display a list coming from my database using Linqtosql but I
I am using Codeignitor for programming and coming from c#. its look like a
I'm using RSA private-public key encryption to encrypt data coming from server. The main
new to Laravel (coming from Java spring), while using Route::get('/', function() { return Hello
Hi i am using PHP to store the timezone.The timezone coming from dropdown and

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.