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 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 have been testing and playing around with jquery date picker below. http://jqueryui.com/demos/datepicker/ on
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
I'm new to Actionscript and I'm playing around and testing with collisions. I have
I've been playing around a bit with Minitest, and have found behavior that I
I was playing around with some Chrome Extensions, testing stuff, changing samples, etc, when
Just playing around with Wordpress / Contact Form 7 . Is it possible to
I playing around with the Twitter API for my BlackBerry application. Is there any
Was playing around a little bit with the TimeSpan class and I started wondering
While playing around with the emulator, I noticed that when trying to view a
I've been playing around with .NET SpeechSynthesizer lately. and I've got a method that

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.