public void Apply_SortByName_SortedHighestToLowest() { // arrange var sort = new DynamicSort <FakeSortClass>(t => t.Name); sort.AddKey("age", "age desc", t => t.Age); var coll = GetSampleList(); // act var result = sort.Apply("age", coll); var enumerated = result.ToList(); // assert FakeSortClass current = null; foreach (var e in enumerated) { if (current == null) { current = e; continue; } Assert.True(e.Age > current.Age); current = e; } }
public void AddKey_AddValueType_DoesNotThrow() { // arrange var sort = new DynamicSort <FakeSortClass>(t => t.Name); // act sort.AddKey("name", "name desc", t => t.Age); // assert Assert.True(true); }
public void Apply_EmptyKey_SortsByDefault() { // arrange var sort = new DynamicSort <FakeSortClass>(t => t.Name); sort.AddKey("age", "age desc", t => t.Age); var coll = GetSampleList().ToList(); // act var result = sort.Apply(string.Empty, coll); // assert Assert.Equal("Jeremy", result.First().Name); }
public void Apply_WithThenBy_ExpectedOrder() { // arrange var sort = new DynamicSort <FakeSortClass>(t => t.Name); sort.AddKey("age", "age desc", t => t.Name, t => t.Age); var coll = GetSampleList(); // act var result = sort.Apply("age", coll); // assert (verify that the grouping is ordered, basically) var oldestJulieAge = result.Where(p => p.Name.Equals("Julie")).Max(p => p.Age); var julies = result.Where(p => p.Name.Equals("Julie")); Assert.Equal(oldestJulieAge, julies.Last().Age); }