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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:58:33+00:00 2026-05-18T06:58:33+00:00

I was playing around with testing using machine specifications and there is something that

  • 0

I was playing around with testing using machine specifications and there is something that i am just not able to do, was wondering if somebody have been there before,

Is there any way to using Rhino Mocks to create a stub for a method that uses a lambda expression, i found that i can do the following

Having this method in a sample class:

public void UpdateVisit(int userId){
    var user = repository.FindBy<User>(x=>x.Id==userId && user.IsActive ==true);
    user.Visit = user.Visit + 1;
    repository.Save(user);
}

I can stub the method like this:

//...Inside test method
var user = new User();
repository.Stub(x=>x.FindBy<User>(Arg<Expression<Func<User,bool>>>.Is.Anything)).Return(user);

The thing is I would like to stub the method not to Any Lambda Expression, just for the specific lambda expression "x=>x.Id==userId && user.IsActive ==true", so that the test would fail if this expression changes in the method…

I guess i could create a mock repository that does not go to the database and test the behavior in the lambda though this, i was wondering if there is another approach to this…

Appreciate any suggestions on this,
Thanks

  • 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-18T06:58:34+00:00Added an answer on May 18, 2026 at 6:58 am

    You don’t want to test that the particular lambda expression is used in the method. You want to test the behavior that the method is suppose to have. Testing implementation details like a specific lambda expression is in general too brittle. Instead:

    [Fact]
    UpdateVisit_updates_Visit_for_user_that_is_in_the_repository_and_is_active() {
        // set up mock repository with dummy user having
        // userId == 1,
        // IsActive == true,
        // Visit = 42
        // invoke UpdateVisit
        // pull userId == 1 from the repository
        Assert.Equal(43, user.Visit);
    }
    
    [Fact]
    UpdateVisit_does_not_update_visit_for_user_that_is_not_active() {
        // etc.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with BCEL. I'm not using it to generate bytecode, but instead
I have been playing around with the concept of 'module' that some mvc frameworks
Just playing around with the now released Silverlight 2.0. I'm trying to put a
While playing around with regexps in Scala I wrote something like this: scala> val
I'm playing around with the <canvas> element, drawing lines and such. I've noticed that
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into
I am playing around with MVC and have started setting up an existing site
I've been reading about Inversion of Control frameworks and I'm just playing around with
I'm currently playing around with HTML_QuickForm for generating forms in PHP. It seems kind
I'm playing around with a native (non-web) single-player game I'm writing, and it occured

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.