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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:25:54+00:00 2026-05-22T11:25:54+00:00

I need to not only swap implementation but also to add necessary check to

  • 0

I need to not only swap implementation but also to add necessary check to make sure that certain methods were called in the right order. I can imagine something like Mole + Mock would give me this option. Does anybody know if Moles has this feature?

This code should be helpful:

// Verify if Dispose was called
MDisposableObject.Constructor = delegate(DisposableObject instance)
{
    MDisposableObject mole = new MDisposableObject(instance);
    ...
    // This doesn't work 
    //objectContext.Expects(i => i.Dispose()).ToBeCalledOneTime();
};
  • 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-22T11:25:55+00:00Added an answer on May 22, 2026 at 11:25 am

    Moles aim to give stubs (and not mocks) for everything, even for static or sealed methods. It’s written in the Moles manual that they are not aiming the mocking aspect like others mocking frameworks : they offer isolation, not mocks. If you want to check calls on your Moles, you have to do your own way.
    For example:

        bool called = false;
        MDisposableObject.Constructor = (@this) =>
        {
            var mole = new MDisposableObject(@this)
            {
                Dispose = () =>
                    {
                        Assert.IsFalse(called);
                        called=true;
                        //if you want to call the original implementation:
                        MolesContext.ExecuteWithoutMoles(() => (@this).Dispose());
                        //or do something else, even nothing
                    }
    
            };
        };
    

    Only Typemock Isolator (powerfull but expensive) and JustMock of Telerik (new concurrent, also not free) enable mocking features for everything.
    If you have some interfaces, delegates and virtual method, use free mocking framework like Moq or RhinoMocks.

    A warning about my example: until now I didn’t found how to call the orignal constructor, I mean something like

    var mole = new SDisposable();
    (@this) = mole;
    new MDisposable(mole) {...};
    

    Actually, from what I read on msdn, it’s not possible… I hope following releases will enable that.

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

Sidebar

Related Questions

In my C#/MVC4/Razor Application I need to make sure that user enter not only
I have some images that need to change, based not only on hover, but
MSDN docs say that only value types need boxing, but this does not apply
I need a simple parser generator. The language does not matter. It only has
I am a beginner SQL user (not formally trained; OJT only) and need some
I'm writing my own simple drop-down...and it's not going so well. I need only
I have a table with columns ID, DateStamp and the ID need not be
I need to not validate against a doctype, so I'd like to set a
With JPA I do not need to code the SQL for every new attribute
I need to find a GPS location within my app which does not need

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.