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

The Archive Base Latest Questions

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

I have the following two methods on an interface for my service layer: ICollection<T>

  • 0

I have the following two methods on an interface for my service layer:

ICollection<T> FindAll<T>(Expression<Func<T, bool>> predicate) where T : Post;
ICollection<T> FindAll<T,TKey>(Expression<Func<T, bool>> predicate, OrderingOptions<T,TKey> orderingOptions) where T : Post;

They are extremely similar.

The first one (basically) does this:

return repository
   .Find()
   .OfType<T>()
   .Where(predicate)
   .Take(maxRows)
   .ToList();

The second one (basically) does this:

return repository
   .Find()
   .OfType<T>()
   .Where(predicate)
   .WithOrdering(orderingOptions)
   .Take(maxRows)
   .ToList();

WithOrdering is a pipe extension method i created:

public static IOrderedQueryable<T> WithOrdering<T,TKey>(this IQueryable<T> source, OrderingOptions<T,TKey> postOrderingOptions)
        {
            return postOrderingOptions.SortAscending
                       ? source.OrderBy(postOrderingOptions.OrderingKey)
                       : source.OrderByDescending(postOrderingOptions.OrderingKey);

        }

OrderingOptions<T,TKey> is a generic class i implemented to provide fluent ordering.

So, that being said – i have numerous unit tests for the first method (ensure collection is returned, ensure null is returned for an empty collection, ensure filtered correctly, ensure max rows is returned, etc).

But my question is – how do i test the second method? Do i need two? Given that the only thing that is different is that im using the .OrderBy (or .OrderByDescending) methods.

If im testing that, am i simply testing the LINQ framework?

If not, how can i even test this?

Couple of (possibly important) points:

  1. This are methods on a service layer, which retrieve IQueryable’s on a repository, that is implemented with Entity Framework 4.0
  2. For my unit-tests, the service layer is injected (via StructureMap) a mock repository, but i also toggle this to the real repository manually when i want to do integration testing

Guidance/best practices would be highly appreciated.

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

    You need to unit-test the second method just to make sure it works. If you refactor something that changes how it works and fix the first one, how will you know if you forgot to fix the second one? If you refactor WithOrdering, how will you know that things still work? I would have a unit test to test ascending and one to test descending.

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

Sidebar

Related Questions

No related questions found

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.