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

The Archive Base Latest Questions

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

How do I assert in MSTest that the order of the returned collection is

  • 0

How do I assert in MSTest that the order of the returned collection is correct?

[TestMethod]
    public void when_sorting_movies_it_should_be_able_to_sort_all_movies_by_title_descending()
    {
        populateTestMovies(movie_collection);
        MovieLibrary movieLibrary = new MovieLibrary(movie_collection);
        IEnumerable<Movie> results = movieLibrary.sort_all_movies_by_title_descending();
        Assert.IsTrue(results.Contains(theres_something_about_mary));
        Assert.IsTrue(results.Contains(the_ring));
        Assert.IsTrue(results.Contains(shrek));
        Assert.IsTrue(results.Contains(pirates_of_the_carribean));
        Assert.IsTrue(results.Contains(indiana_jones_and_the_temple_of_doom));
        Assert.IsTrue(results.Contains(cars));
        Assert.IsTrue(results.Contains(a_bugs_life));
        Assert.AreEqual(7, results.Count());
    }
  • 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-20T10:27:15+00:00Added an answer on May 20, 2026 at 10:27 am

    Create a hard-coded IEnumerable<string> with the movie titles in the expected order, pull the titles from the result collection and use SequenceEqual to check that they come in the same order (assuming your referred constants are Movie objects, and that Movie has a Title property):

    IEnumerable<string> expected = new[] 
    { 
        theres_something_about_mary.Title, 
        the_ring.Title,
       /* and so on */ 
    };
    Assert.IsTrue(results.Select(m => m.Title).SequenceEqual(expected));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MSTest you can do something like: [TestMethod] [DataSource(Microsoft.VisualStudio.TestTools.DataSource.CSV, testdata.csv, testdata#csv, DataAccessMethod.Sequential)] public void
I'm having trouble with some MSTest unit tests that pass when I run them
I would like to provide some custom Assert methods in my MSTest Unit Testing
assert !destinationDirectory: Destination directory is required to create an archive Does this mean that
//Assert Lazy<INotificationService> notificationService = Substitute.For<Lazy<INotificationService>>(); Service target = new Service(repository, notificationService); //Act target.SendNotify(Message); //Arrange
assert !ActionMailer::Base.deliveries.empty?, Queue is empty If I have two unit tests that send mail,
I have one test that needs to work more then 1 minute (VS2008, MSTest,
assert(0.1 + 0.2 != 0.3); // shall be true is my favorite check that
How do I use Assert (or other Test class) to verify that an exception
My assert macro is like this: #ifdef DEBUG #define ASSERT(x) ((void)(!(x) && assert_handler(#x, __FILE__,

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.