using NUnit.Framework; using System.Collections.Generic; using System.Linq; [TestFixture] public class ListOrderTests { [Test] public void TestDescendingSort() { Listnumbers = new List () { 3, 5, 1, 4, 2 }; List sortedNumbers = numbers.OrderByDescending(x => x).ToList(); Assert.That(sortedNumbers, Is.EqualTo(new List () { 5, 4, 3, 2, 1 })); } }
using NUnit.Framework; using System.Collections.Generic; using System.Linq; [TestFixture] public class StudentOrderTests { [Test] public void TestDescendingSort() { ListIn the above example, we define a simple class called Student with three properties: FirstName, LastName, and GPA. We create a list of Student objects, invoke the OrderByDescending method on the list using the GPA property as the sorting criterion, and store the result in a new list called sortedStudents. We then use the Assert class from NUnit to verify that the resulting sorted list matches the expected order based on the Last Name property. The List OrderByDescending method is part of the System.Linq namespace, which is included in the .NET Framework class library.students = new List () { new Student("John", "Doe", 3.5), new Student("Jane", "Smith", 4.0), new Student("Bob", "Wilson", 3.9), new Student("Mary", "Taylor", 3.2) }; List sortedStudents = students.OrderByDescending(s => s.GPA).ToList(); Assert.That(sortedStudents.Select(s => s.LastName), Is.EqualTo(new List () { "Smith", "Wilson", "Doe", "Taylor" })); } private class Student { public string FirstName { get; } public string LastName { get; } public double GPA { get; } public Student(string firstName, string lastName, double gpa) { FirstName = firstName; LastName = lastName; GPA = gpa; } } }