From 5d33197397ebeb910829083213778a300bcab4b8 Mon Sep 17 00:00:00 2001 From: "Angelito Sardez, Jr" Date: Thu, 4 Oct 2018 00:18:51 +1000 Subject: [PATCH 1/4] ThenBy extension method and unit test implementation. --- ShittyLINQ/ThenBy.cs | 21 +++++++++++ ShittyLinqTests/ThenByTests.cs | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 ShittyLINQ/ThenBy.cs create mode 100644 ShittyLinqTests/ThenByTests.cs diff --git a/ShittyLINQ/ThenBy.cs b/ShittyLINQ/ThenBy.cs new file mode 100644 index 0000000..f2909e3 --- /dev/null +++ b/ShittyLINQ/ThenBy.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ShittyLINQ +{ + public static partial class Extensions + { + public static IOrderedEnumerable ThenBy(this IOrderedEnumerable source, Func keySelector) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, null, false); + } + + public static IOrderedEnumerable ThenBy(this IOrderedEnumerable source, Func keySelector, IComparer comparer) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, comparer, false); + } + } +} diff --git a/ShittyLinqTests/ThenByTests.cs b/ShittyLinqTests/ThenByTests.cs new file mode 100644 index 0000000..010b0a5 --- /dev/null +++ b/ShittyLinqTests/ThenByTests.cs @@ -0,0 +1,66 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ShittyLINQ; +using System; + +namespace ShittyTests +{ + [TestClass] + public class ThenByTests + { + + [TestMethod] + public void ThenBy_WithoutComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, int prop2)[] + { + ("test", 3), + ("test", 2), + ("test", 1), + }, i => i.prop1); + + // Act + var result = items.ThenBy(i => i.prop2); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual(1, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(2, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(3, enumerator.Current.prop2); + } + } + + + [TestMethod] + public void ThenBy_WithComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, string prop2)[] + { + ("test", "c"), + ("test", "B"), + ("test", "a"), + }, i => i.prop1); + + // Act + var result = items.ThenBy(i => i.prop2, StringComparer.OrdinalIgnoreCase); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual("a", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("B", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("c", enumerator.Current.prop2); + } + } + } +} From 41ae7f51e2a0ad4fc3439f5932cd74ec811218a9 Mon Sep 17 00:00:00 2001 From: "Angelito Sardez, Jr" Date: Thu, 4 Oct 2018 00:28:19 +1000 Subject: [PATCH 2/4] ThenByDescending extension method and unit test implementation. --- ShittyLINQ/ThenByDescending.cs | 21 ++++++++ ShittyLinqTests/ThenByDescendingTests.cs | 64 ++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 ShittyLINQ/ThenByDescending.cs create mode 100644 ShittyLinqTests/ThenByDescendingTests.cs diff --git a/ShittyLINQ/ThenByDescending.cs b/ShittyLINQ/ThenByDescending.cs new file mode 100644 index 0000000..7083ce6 --- /dev/null +++ b/ShittyLINQ/ThenByDescending.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ShittyLINQ +{ + public static partial class Extensions + { + public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, null, true); + } + + public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector, IComparer comparer) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, comparer, true); + } + } +} diff --git a/ShittyLinqTests/ThenByDescendingTests.cs b/ShittyLinqTests/ThenByDescendingTests.cs new file mode 100644 index 0000000..ef478b5 --- /dev/null +++ b/ShittyLinqTests/ThenByDescendingTests.cs @@ -0,0 +1,64 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ShittyLINQ; +using System; + +namespace ShittyTests +{ + [TestClass] + public class ThenByDescendingTests + { + [TestMethod] + public void ThenByDescending_WithoutComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, int prop2)[] + { + ("test", 1), + ("test", 2), + ("test", 3), + }, i => i.prop1); + + // Act + var result = items.ThenByDescending(i => i.prop2); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual(3, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(2, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(1, enumerator.Current.prop2); + } + } + + [TestMethod] + public void ThenByDescending_WithComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, string prop2)[] + { + ("test", "a"), + ("test", "B"), + ("test", "c"), + }, i => i.prop1); + + // Act + var result = items.ThenByDescending(i => i.prop2, StringComparer.OrdinalIgnoreCase); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual("c", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("B", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("a", enumerator.Current.prop2); + } + } + } +} From 0804f78fe84704e25185c28d83eaeea9f8fcd59c Mon Sep 17 00:00:00 2001 From: "Angelito Sardez, Jr" Date: Thu, 4 Oct 2018 00:31:35 +1000 Subject: [PATCH 3/4] Revert "ThenByDescending extension method and unit test implementation." This reverts commit 41ae7f51e2a0ad4fc3439f5932cd74ec811218a9. --- ShittyLINQ/ThenByDescending.cs | 21 -------- ShittyLinqTests/ThenByDescendingTests.cs | 64 ------------------------ 2 files changed, 85 deletions(-) delete mode 100644 ShittyLINQ/ThenByDescending.cs delete mode 100644 ShittyLinqTests/ThenByDescendingTests.cs diff --git a/ShittyLINQ/ThenByDescending.cs b/ShittyLINQ/ThenByDescending.cs deleted file mode 100644 index 7083ce6..0000000 --- a/ShittyLINQ/ThenByDescending.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace ShittyLINQ -{ - public static partial class Extensions - { - public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector) - { - if (source == null) throw new ArgumentNullException("source"); - return source.CreateOrderedEnumerable(keySelector, null, true); - } - - public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector, IComparer comparer) - { - if (source == null) throw new ArgumentNullException("source"); - return source.CreateOrderedEnumerable(keySelector, comparer, true); - } - } -} diff --git a/ShittyLinqTests/ThenByDescendingTests.cs b/ShittyLinqTests/ThenByDescendingTests.cs deleted file mode 100644 index ef478b5..0000000 --- a/ShittyLinqTests/ThenByDescendingTests.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using ShittyLINQ; -using System; - -namespace ShittyTests -{ - [TestClass] - public class ThenByDescendingTests - { - [TestMethod] - public void ThenByDescending_WithoutComparer() - { - // Arrange - var items = System.Linq.Enumerable.OrderBy(new (string prop1, int prop2)[] - { - ("test", 1), - ("test", 2), - ("test", 3), - }, i => i.prop1); - - // Act - var result = items.ThenByDescending(i => i.prop2); - - // Assert - Assert.IsNotNull(result); - using (var enumerator = result.GetEnumerator()) - { - enumerator.MoveNext(); - Assert.AreEqual(3, enumerator.Current.prop2); - enumerator.MoveNext(); - Assert.AreEqual(2, enumerator.Current.prop2); - enumerator.MoveNext(); - Assert.AreEqual(1, enumerator.Current.prop2); - } - } - - [TestMethod] - public void ThenByDescending_WithComparer() - { - // Arrange - var items = System.Linq.Enumerable.OrderBy(new (string prop1, string prop2)[] - { - ("test", "a"), - ("test", "B"), - ("test", "c"), - }, i => i.prop1); - - // Act - var result = items.ThenByDescending(i => i.prop2, StringComparer.OrdinalIgnoreCase); - - // Assert - Assert.IsNotNull(result); - using (var enumerator = result.GetEnumerator()) - { - enumerator.MoveNext(); - Assert.AreEqual("c", enumerator.Current.prop2); - enumerator.MoveNext(); - Assert.AreEqual("B", enumerator.Current.prop2); - enumerator.MoveNext(); - Assert.AreEqual("a", enumerator.Current.prop2); - } - } - } -} From 6510b86c230c06c44ec82f0e0b58b5dbfed3456b Mon Sep 17 00:00:00 2001 From: "Angelito Sardez, Jr" Date: Thu, 4 Oct 2018 00:35:14 +1000 Subject: [PATCH 4/4] ThenByDescending extension method and unit test implementation. --- ShittyLINQ/ThenByDescending.cs | 21 ++++++++ ShittyLinqTests/ThenByDescendingTests.cs | 64 ++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 ShittyLINQ/ThenByDescending.cs create mode 100644 ShittyLinqTests/ThenByDescendingTests.cs diff --git a/ShittyLINQ/ThenByDescending.cs b/ShittyLINQ/ThenByDescending.cs new file mode 100644 index 0000000..7083ce6 --- /dev/null +++ b/ShittyLINQ/ThenByDescending.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace ShittyLINQ +{ + public static partial class Extensions + { + public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, null, true); + } + + public static IOrderedEnumerable ThenByDescending(this IOrderedEnumerable source, Func keySelector, IComparer comparer) + { + if (source == null) throw new ArgumentNullException("source"); + return source.CreateOrderedEnumerable(keySelector, comparer, true); + } + } +} diff --git a/ShittyLinqTests/ThenByDescendingTests.cs b/ShittyLinqTests/ThenByDescendingTests.cs new file mode 100644 index 0000000..88b55ac --- /dev/null +++ b/ShittyLinqTests/ThenByDescendingTests.cs @@ -0,0 +1,64 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using ShittyLINQ; +using System; + +namespace ShittyTests +{ + [TestClass] + public class ThenByDescendingTests + { + [TestMethod] + public void ThenByDescending_WithoutComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, int prop2)[] + { + ("test", 1), + ("test", 2), + ("test", 3), + }, i => i.prop1); + + // Act + var result = items.ThenByDescending(i => i.prop2); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual(3, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(2, enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual(1, enumerator.Current.prop2); + } + } + + [TestMethod] + public void ThenByDescending_WithComparer() + { + // Arrange + var items = System.Linq.Enumerable.OrderBy(new (string prop1, string prop2)[] + { + ("test", "a"), + ("test", "B"), + ("test", "c"), + }, i => i.prop1); + + // Act + var result = items.ThenByDescending(i => i.prop2, StringComparer.OrdinalIgnoreCase); + + // Assert + Assert.IsNotNull(result); + using (var enumerator = result.GetEnumerator()) + { + enumerator.MoveNext(); + Assert.AreEqual("c", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("B", enumerator.Current.prop2); + enumerator.MoveNext(); + Assert.AreEqual("a", enumerator.Current.prop2); + } + } + } +}