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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:01:17+00:00 2026-05-16T12:01:17+00:00

I am attempting to be a good TDD citizen as I design an application.

  • 0

I am attempting to be a good TDD citizen as I design an application. I’m using Moq, and I’ve run into a little repository issue.

My repository has a Find method:

public IEnumerable<T> Find(Expression<Func<T, bool>> where)
        {
            return _objectSet.Where(where);
        }

Then I attempt to set up a mock of the repository:

mock.Setup(m => m.Find(c => c.ConferenceID == conferenceID))
                .Returns(ConferenceTestObjectContainer.CreateConferences().Where(c => c.ConferenceID == conferenceID).ToList());

The test will work if I test against the mock directly in the test, but if I inject the mock into my production code (an ASP.NET page in this case,) and test the page method, it doesn’t work.

Justin Etheredge addresses the problem in his post here. The issue is that the comparer between the call and the setup can’t handle Expressions so well.

The problem that I’m having is with his comparer function:

public static Expression<Func<T,bool>> AreEqual<T>(Expression<Func<T,bool>> expr)
{
    return Match<Expression<Func<T, bool>>>
        .Create(t => t.ToString() == expr.ToString());            
}

This raises a compiler error:

The type arguments for method ‘Moq.Match.Create(System.Predicate)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

I understand that the compiler can’t infer the type of “T”, but I’m not clear on how to fix that. The good Mr. Etheredge made this work, but I don’t understand what I’m doing wrong.

TIA.

  • 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-16T12:01:17+00:00Added an answer on May 16, 2026 at 12:01 pm

    OK, so this question is going Tumblweed…

    For the record, I worked around the problem by deriving a new Entity-specific Repository and added a FindById() method, which works great.

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

Sidebar

Related Questions

Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
I'm attempting to use the MVP design pattern with a Swing application in conjunction
I have a service that attempting to serialize a list into JSON (using JSON.NET)
I am attempting to use Scintilla .NET in a project (I want a good
Attempting to build a C# project which has numerous references to assemblies in NuGet
I'm attempting to piece together and run a list of tasks put together by
I'm attempting to implement custom termination behavior in a Cocoa application. Normally when my
I am attempting to profile a VB6 application. Basically I wanted to work out
So I'm attempting to create a Befunge interperter and reading a text file into
Good Evening Stackoverflow Lords & Ladies, I am attempting to develop a Layar layer

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.