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

  • Home
  • SEARCH
  • 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 41293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:09:29+00:00 2026-05-10T15:09:29+00:00

I’m new to RhinoMocks, and trying to get a grasp on the syntax in

  • 0

I’m new to RhinoMocks, and trying to get a grasp on the syntax in addition to what is happening under the hood.

I have a user object, we’ll call it User, which has a property called IsAdministrator. The value for IsAdministrator is evaluated via another class that checks the User’s security permissions, and returns either true or false based on those permissions. I’m trying to mock this User class, and fake the return value for IsAdministrator in order to isolate some Unit Tests.

This is what I’m doing so far:

public void CreateSomethingIfUserHasAdminPermissions() {     User user = _mocks.StrictMock<User>();     SetupResult.For(user.IsAdministrator).Return(true);      // do something with my User object }  

Now, I’m expecting that Rhino is going to ‘fake’ the call to the property getter, and just return true to me. Is this incorrect? Currently I’m getting an exception because of dependencies in the IsAdministrator property.

Can someone explain how I can achieve my goal here?

  • 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-10T15:09:30+00:00Added an answer on May 10, 2026 at 3:09 pm

    One quick note before I jump into this. Typically you want to avoid the use of a ‘Strict’ mock because it makes for a brittle test. A strict mock will throw an exception if anything occurs that you do not explicitly tell Rhino will happen. Also I think you may be misunderstanding exactly what Rhino is doing when you make a call to create a mock. Think of it as a custom Object that has either been derived from, or implements the System.Type you defined. If you did it yourself it would look like this:

    public class FakeUserType: User {     //overriding code here } 

    Since IsAdministrator is probably just a public property on the User type you can’t override it in the inheriting type.

    As far as your question is concerned there are multiple ways you could handle this. You could implement IsAdministrator as a virtual property on your user class as aaronjensen mentioned as follows:

    public class User {     public virtual Boolean IsAdministrator { get; set; } } 

    This is an ok approach, but only if you plan on inheriting from your User class. Also if you wan’t to fake other members on this class they would also have to be virtual, which is probably not the desired behavior.

    Another way to accomplish this is through the use of interfaces. If it is truly the User class you are wanting to Mock then I would extract an interface from it. Your above example would look something like this:

    public interface IUser {     Boolean IsAdministrator { get; } }  public class User : IUser {     private UserSecurity _userSecurity = new UserSecurity();      public Boolean IsAdministrator     {         get { return _userSecurity.HasAccess('AdminPermissions'); }     } }  public void CreateSomethingIfUserHasAdminPermissions() {     IUser user = _mocks.StrictMock<IUser>();     SetupResult.For(user.IsAdministrator).Return(true);      // do something with my User object } 

    You can get fancier if you want by using dependency injection and IOC but the basic principle is the same across the board. Typically you want your classes to depend on interfaces rather than concrete implementations anyway.

    I hope this helps. I have been using RhinoMocks for a long time on a major project now so don’t hesitate to ask me questions about TDD and mocking.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I

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.