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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:28:20+00:00 2026-05-21T10:28:20+00:00

What is the correct way to unit test a method that returns a sequence

  • 0

What is the correct way to unit test a method that returns a sequence of complex objects?

I’m implementing a branch finder. I have a repository that returns a Branch object which has various information such as

  • Branch name
  • Address
  • Location
  • Products stocked

I have a repository that I’ve faked to always return a known sequence of Branch objects and I need to test the logic in my BranchFinder service.

The Find method takes a location (lat/long) and a product specification in the form of a Flags enum .

public IEnumerable<Branch> Find(Location location, Products products);

Knowing the data that the search is going to operate on, I can safely specify a location and product specification and know what to expect, but how do I assert that the sequence is correct.

e.g.

var loc = new Location(53.79424, -1.546112);
var results = service.Find(loc, Products.Milk | Products.Bananas);

I know for this given query that a certain subset of data should be returned in a certain order, and also that the distance from the current location to the branch should increase as you iterate through the result set.

What is the correct/best way to test these rules and situations?

  • 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-21T10:28:21+00:00Added an answer on May 21, 2026 at 10:28 am

    First thing I would do would be to make sure you access the Service via an interface ILocatorService. Also make sure that any downstream dependency it has to get the Branch info also used via Interface (so that you can inject Mock later on in your test).

    Also, be clear that you are testing ILocatorService itself (to make sure that any change you made in the service doest break it).

    For Any Dependencies that ILocatorService uses, you can use RhynoMocks to return set of results (it might be going to DB or some other vendor app to give us list of branches)

    That way your inputs to ILocatorService stays the same and the only thing you are testing is if any logic that you have changed is breaking existign test/functionality.

    • 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.