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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:20:39+00:00 2026-05-16T17:20:39+00:00

How do I check if Create was not called without using the Rhino Mocks

  • 0

How do I check if Create was not called without using the Rhino Mocks AssertWasNotCalled method.

Here is the test:

    [Test]
    public void When_try_to_create_directory_that_already_exits_return_false()
    {
        var directoryInfoMock = MockRepository.GenerateMock<IDirectoryInfoWrap>();
        directoryInfoMock.Stub(x => x.Exists).Return(true);
        directoryInfoMock.Expect(x => x.Create());
        Assert.AreEqual(false, new DirectoryInfoSample().TryToCreateDirectory(directoryInfoMock));

        directoryInfoMock.VerifyAllExpectations();
    }

Also, can someone clarify what Stub does.

  • 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-16T17:20:40+00:00Added an answer on May 16, 2026 at 5:20 pm
    directoryInfoMock.Stub(x => x.Exists).Return(true);
    

    ensures that any call to the property directoryInfoMock.Exists will return true. But if the property is never call or called many times, it will not cause the test to fail. The purpose of the stub is to provide some meal to your code under test so that it can run normally.

    directoryInfoMock.Expect(x => x.Create());
    

    expects that the method directoryInfoMock.Create be called at least once. If not, an exception will be thrown by Rhino.Mocks during the execution of directoryInfoMock.VerifyAllExpectations().

    So basically, your unit test should work as expected. What is the output of the test?


    UPDATE:
    You might want to specify an explicit number of times the method should be called as well. This can be done by using Repeat.x with x is Once(), Twice(), Never(), or Times(N).

    directoryInfoMock.Expect(x => x.Create()).Repeat.Never();
    

    This expects that Create is never called. And of course your test will fail if it is actually called.

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

Sidebar

Related Questions

I'm using C# to create simple application that will check the database repeatedly after
Need to create a custom DNS name server using C which will check against
I'm using MoQ to test some controllers I have. I'm not able to set
Can you create a delegate of an instance method without specifying the instance at
Suppose I have created one jQuery function to check if elements exist or not
I am trying to create a check constraint on an access (jet?) table. So,
I'm trying to create a check on a few columns in my database that
Quick sanity check - I wanted to create a new remote branch for myself.
I want to create new creative and check its audit status in facebook ads
I create a table by query below CREATE TABLE testing( test_field VARCHAR(20) CHECK(test_field like

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.