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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:41:56+00:00 2026-05-26T12:41:56+00:00

Im trying to mock a method that is ineherited from a parent class that

  • 0

Im trying to mock a method that is ineherited from a parent class that is generic. Right know my code looks like this.

public interface IBaseRepository<T>
{
    IEnumerable<T> FindMany(Func<T, bool> condition);
}

public interface IPersonRepository : IBaseRepository<person>
{
    //Here I got some specifics methods for person repository
}

My test code looks like this;

    private IPersonRepository mockPersonRepository { get; set; }

    [TestMethod]
    public void TestMehtod()
    {
        LogonModel model = CreateLogonModel("test@test.com", "test", "Index");
        person p = new person() { Email = model.Email, password = model.Password, PersonId = 1 };

        mockPersonRepository.Stub(x => x.FindMany(y => y.Email == model.Email && y.password == model.Password)).Return(new List<person> {p});
        mockPersonRepository.Replay();

        var actual = instanceToTest.LogOnPosted(model) as PartialViewResult;

        Assert.AreEqual("_Login", actual.ViewName);
    }

When I am using the debugging tool in vs 2010 I can se that me Stub, doesnt works, the return person is always null. I have declared the FindMany method as virtual.

Does anybody know how to stub that method? Im using RhinoMocks.

  • 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-26T12:41:56+00:00Added an answer on May 26, 2026 at 12:41 pm

    The problem is that you are comparing the lambda – but you are really interested in having the person instance passed into the lambda match your person object based on satisfying the predicate condition – You can use Matches() to achieve this by just executing the predicate on p – if that equates to true than you have a match and should return the stubbed list:

    mockPersonRepository.Stub(x => x.FindMany(Arg<Func<person, bool>>.Matches( y => y(p))))
                        .Return(new List<person> { p });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I took a method from this post (accepted answer code) that serializes object so
Trying to mock the following method: bool IsLoginValid(LoginViewModel viewModel, out User user); Tried this
I´m encountering this problem trying to mock some objects that receive complex lambda expressions
I'm trying to mock a method that has the equivalent of the following signature:
I'm currently trying to mock the following method using Jack. The code example is
I have Equals method that I am trying to tests. this method return true
I am trying to verify that my Rails code calls ActiveRecord's all method (all
I'm trying to mock a method call that takes a call-by-name argument: import org.scalatest.WordSpec
I am trying to mock out a private method that is making a JNDI
I've been trying to get to mock a method with vararg parameters using Mockito:

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.