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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:17:32+00:00 2026-05-26T15:17:32+00:00

How can you verify interaction test using Moles. For example the following test is

  • 0

How can you verify interaction test using Moles. For example the following test is written using rhino mock. Can anyone please tell me how can I achive the same using moles? Is there anything like verify for moles?

[Test]
public void MyTest()
{
    MockRepository mocks = new MockRepository();
    ILogger mockLogger = mocks.StrictMock<ILogger>();

    using(mocks.Record())
    {
        mockLogger .Log("this is my error");
    }

    MyClass mc = new MyClass (mockLogger);

    mc.MyFunc("abcd");
    mocks.Verify(mockLogger);
}



class MyClass
{

    private ILogger logger;

    public MyClass(ILogger logger)
    { this.logger = logger; }

    public void MyFunc(string str)
    {

        logger.log("this is my error");
    }

}

I would really appreciate your help.

  • 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-26T15:17:32+00:00Added an answer on May 26, 2026 at 3:17 pm

    Personally, I use Moq for internal dependency and Moles for externalities (and unpleasant static stuff forced on me by others), so I might not be giving you the best way, but it’s a way:

        [TestMethod, Owner("ebd"), TestCategory("Proven"), TestCategory("Unit")]
        public void MyTest()
        {
            var myCalled = false;
            var myLogger = new SILogger();
            myLogger.LogString = (s) => myCalled = true;
            var myClass = new MyClass(myLogger);
            myClass.MyFunc("abcd");
    
            Assert.IsTrue(myCalled);
        }
    

    Key idea here is “SILogger” which is your stub for ILogger. You then set up instance behavior for it’s “LogString” (which corresponds to your log(string) method. You set it to callback your local variable and set it to true. You then invoke the method that should invoke log, and you assert that your local is now true.

    Again, I’d usually do this with Moq and used myStub.Verify() for this purpose, so it’s possible that there’s a slicker way to do this with moles that I’m not aware of. Personally, I think Moles is much better suited for “mocking the unmockable”, and I prefer a combination of Moq (for my own interfaces and classes) and Moq (for framework and externalities like File I/O, GUI, Db connections, etc).

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

Sidebar

Related Questions

How can I make a verify error for this command? if blablablabla: os.makedirs('C:\\test\\') If
How can I verify a given xpath string is valid in C#/.NET? I'm not
How can I verify an X509 (or DER-formatted) certificate against the Java certificate store
Can anybody help me in finding out how to verify that _tmkdir succeeded. For
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
I would like to know how I can verify a user's credential against an
Are there any tools that can verify whether a jQuery plugin will be compatible
How to get number range in java? for instance how can verify is the
I'm trying to do cast a List to an IEnumerable, so I can verify
I've created an integration test to verify that a repository handles Concurrency correcly. If

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.