public void SortBy_SelectorAscendingDirection_Ascending() { OrderSubject s2_10 = new OrderSubject(2, 10), s1_7 = new OrderSubject(1, 7), s1_8 = new OrderSubject(1, 8); var query = new[] { s2_10, s1_7, s1_8 }.AsQueryable(); Assert.That(query.SortBy(s => s.I2, Direction.Ascending), Is.EqualTo(new[] { s1_7, s1_8, s2_10 })); }
public void MaxBy_SeveralEqualElements_FirstReturned() { OrderSubject twoOne = new OrderSubject(2, 1), anotherTwoOne = new OrderSubject(2, 1); var collection = new[] { new OrderSubject(2, 0), twoOne, anotherTwoOne }; Assert.That(collection.MaxBy(s => s.I2), Is.SameAs(twoOne)); }
public void MaxBy_DefaultComparer_MinimumValueAccordingToSelector() { var twoOne = new OrderSubject(2, 1); var collection = new[] { new OrderSubject(1, -1), twoOne }; Assert.That(collection.MaxBy(s => s.I2), Is.EqualTo(twoOne)); }
public Command(int pageIndex, int pageSize, string filter, OrderSubject orderSubject, OrderDirection orderDirection) { PageIndex = pageIndex; PageSize = pageSize; Filter = filter; OrderSubject = orderSubject; OrderDirection = orderDirection; }
public void SortBy_SelectorNullDirection_Unordered() { OrderSubject s2_10 = new OrderSubject(2, 10), s1_7 = new OrderSubject(1, 7), s1_8 = new OrderSubject(1, 8); var query = new[] { s2_10, s1_7, s1_8 }.AsQueryable(); Direction? nullDirection = null; Assert.That(query.SortBy(s => s.I2, nullDirection), Is.EqualTo(query)); }
public void SortBy_SomeUnexpectedObject_ObjectFilteredOut() { OrderSubject one = new OrderSubject(1, 1), two = new OrderSubject(2, 2); var subject = new[] { one, two }; var actual = subject.SortBy(s => s.I1, new[] { 3, 2 }); Assert.That(actual, Is.EqualTo(new[] { two })); }
public void SortBy_SomeMissingKeys_ExistingObjectsInSpecifiedOrder() { OrderSubject one = new OrderSubject(1, 1), two = new OrderSubject(2, 2); var subject = new[] { one, two }; var actual = subject.SortBy(s => s.I1, new[] { 2, 3, 1 }); Assert.That(actual, Is.EqualTo(new[] { two, one })); }
public void SortBy_ListOfExistingKeys_ObjectsInSameOrder() { OrderSubject one = new OrderSubject(1, 1), two = new OrderSubject(2, 2); var subject = new[] { one, two }; var actual = subject.SortBy(s => s.I1, new[] { 2, 1 }); Assert.That(actual, Is.EqualTo(new[] { two, one })); }
public void MaxBy_AlternativeComparer_MinimumValueAccordingToSelectorAndComparer() { var twoMinusTwo = new OrderSubject(2, -2); var collection = new[] { new OrderSubject(2, -1), twoMinusTwo }; IComparer <int> absComparer = Cmp <int> .By((one, other) => Math.Abs(one).CompareTo(Math.Abs(other))); Assert.That(collection.MaxBy(s => s.I2, absComparer), Is.EqualTo(twoMinusTwo)); }
public void MinBy_AlternativeComparer_MinimumValueAccordingToSelectorAndComparer() { var twoOne = new OrderSubject(2, 1); var collection = new[] { new OrderSubject(2, -2), twoOne }; IComparer <int> absComparer = Cmp <int> .By((one, other) => Math.Abs(one).CompareTo(Math.Abs(other))); Assert.That(collection.MinBy(s => s.I2, absComparer), Is.SameAs(twoOne)); }
public void SortBy_CustomEqualizer_EqualizerHonored() { OrderSubject one = new OrderSubject(1, 1), two = new OrderSubject(2, 2); var subject = new[] { one, two }; IEqualityComparer <int> signDoesNotMatter = Eq <int> .By( (x, y) => Math.Abs(x).Equals(Math.Abs(y)), i => Math.Abs(i).GetHashCode()); var actual = subject.SortBy(s => s.I1, new[] { -2, 1 }, signDoesNotMatter); Assert.That(actual, Is.EqualTo(new[] { two, one })); }
private static Func <Thing, string> OrderProperty(OrderSubject orderSubject) { switch (orderSubject) { case OrderSubject.Attribute0: return(x => x.Attribute0); case OrderSubject.Attribute1: return(x => x.Attribute1); default: throw new ArgumentOutOfRangeException(nameof(orderSubject), orderSubject, null); } }
public Command OrderedBy(OrderSubject orderSubject) { var copy = Copied(); // todo: not sure this is the best place for this logic if (OrderSubject == orderSubject) { copy.OrderDirection = OrderDirection == OrderDirection.Ascending ? OrderDirection.Descending : OrderDirection.Ascending; } else { copy.OrderSubject = orderSubject; } return(copy); }
public OrderDisplay(OrderSubject o) { this.Order = o; Order.registerObserver(this); }