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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:17:11+00:00 2026-05-21T02:17:11+00:00

Good afternoon I have a class and it has an associated extension method. public

  • 0

Good afternoon

I have a class and it has an associated extension method.

public class Person{
    public int ID {get;set}
    public string Name {get;set}
}

Extension method:

public static class Helper {
   public static int GetToken(this Person person){
       int id = 0;
       //Something here is done to read token from another service...
       return id;
   }
}

Now I am trying to use Rhino and test this method

public void readPersonToken(int personId) {

   var person = Person.GetPersonInfo(personId);//we consume a service here
   Console.Writeline(person.GetToken());//get token is consuming another service

}

Supposing I am writing my test and have already an interface that calls GetPersonInfo()

var _interface = MockRepository.GenerateMock<IMyInterface>();

and the main Expect is

_interface.Expect(x => x.GetPersonInfo(2))
          .Return(new Person { ID=2, Name = "A Stubbed Monica!" });

how can I create a test for the extension metod GetToken?

  • 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-21T02:17:11+00:00Added an answer on May 21, 2026 at 2:17 am

    Extension methods are just syntatic sugar for static methods. So what you really need is the ability to mock the static method here. Unfortunately this is not possible in Rhino Mocks.

    See the following StackOverflow thread for more details

    • Mocking Static methods using Rhino.Mocks

    To mock a static method you need a mocking framework which actually uses the CLR profiler to intercept method calls. As the thread mentions TypeMock should be able to do this.

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

Sidebar

Related Questions

Good afternoon all, I have a class which looks like this: public class Grapheme
Good afternoon I have a table that has customer id, name, computer, laptop, blah,
Good afternoon all, I was wondering what's the reason that public class test<T> {
Good Afternoon, I have a html aspx page that has many many div elements.
Good afternoon, I have a C++ class Range which implements a operator < for
Good afternoon, We have implemented a C++ cKeyArray class to test whether we can
Good Afternoon All, I have a table inside a div. The div has a
Good afternoon, I have a web query in Excel 2002 going against a web
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main

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.