-
Notifications
You must be signed in to change notification settings - Fork 29
/
ThenByTests.cs
66 lines (58 loc) · 1.88 KB
/
ThenByTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
}
}
}