-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPathExtractionTests.cs
More file actions
102 lines (83 loc) · 3.67 KB
/
Copy pathPathExtractionTests.cs
File metadata and controls
102 lines (83 loc) · 3.67 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace EFCore.ComplexIndexes.Tests;
[TestClass]
public class PathExtractionTests
{
private class Person
{
public string FirstName { get; set; } = "";
public string LastName { get; set; } = "";
public EmailAddress EmailAddress { get; set; } = new();
public Address Address { get; set; } = new();
}
private class EmailAddress
{
public string Value { get; set; } = "";
}
private class Address
{
public string Street { get; set; } = "";
public ZipCode ZipCode { get; set; } = new();
}
private class ZipCode
{
public string Value { get; set; } = "";
}
[TestMethod(DisplayName = "Extracts single level property")]
public void Extracts_single_level_property()
{
var paths = ComplexIndexExtensions
.ExtractPropertyPaths<Person, object>(x => new { x.FirstName, x.LastName });
List<string> expectedPaths = ["FirstName", "LastName"];
Assert.IsTrue(expectedPaths.SequenceEqual(paths));
}
[TestMethod(DisplayName = "Extracts nested complex property")]
public void Extracts_nested_complex_property()
{
var paths = ComplexIndexExtensions
.ExtractPropertyPaths<Person, object>(x => new { x.LastName, x.EmailAddress.Value });
List<string> expectedPaths = ["LastName", "EmailAddress.Value"];
Assert.IsTrue(expectedPaths.SequenceEqual(paths));
}
[TestMethod(DisplayName = "Extracts deeply nested complex property")]
public void Extracts_deeply_nested_complex_property()
{
var paths = ComplexIndexExtensions
.ExtractPropertyPaths<Person, object>(x => new
{
ZipCode = x.Address.ZipCode.Value,
EmailAddress = x.EmailAddress.Value
});
List<string> expectedPaths = ["Address.ZipCode.Value", "EmailAddress.Value"];
Assert.IsTrue(expectedPaths.SequenceEqual(paths));
}
[TestMethod(DisplayName = "Extracts per-column direction from DbOrder markers")]
public void Extracts_direction_from_dborder_markers()
{
var parts = ComplexIndexExtensions
.ExtractIndexParts<Person, object>(x => new { x.FirstName, Email = DbOrder.Desc(x.EmailAddress.Value) });
Assert.AreEqual("FirstName", parts[0].PropertyPath);
Assert.IsFalse(parts[0].Descending);
Assert.AreEqual("EmailAddress.Value", parts[1].PropertyPath);
Assert.IsTrue(parts[1].Descending);
}
[TestMethod(DisplayName = "DbOrder markers do not affect extracted paths")]
public void DbOrder_markers_do_not_affect_paths()
{
var paths = ComplexIndexExtensions
.ExtractPropertyPaths<Person, object>(x => new { x.FirstName, Email = DbOrder.Desc(x.EmailAddress.Value) });
List<string> expectedPaths = ["FirstName", "EmailAddress.Value"];
Assert.IsTrue(expectedPaths.SequenceEqual(paths));
}
[TestMethod(DisplayName = "Throws for non anonymous type")]
public void Throws_for_non_anonymous_type()
{
Assert.Throws<ArgumentException>(() => ComplexIndexExtensions.ExtractPropertyPaths<Person, string>(x => x.FirstName));
}
[TestMethod(DisplayName = "Throws for single property")]
public void Throws_for_single_property()
{
// This would be caught by HasComplexCompositeIndex, but good to verify
var paths = ComplexIndexExtensions.ExtractPropertyPaths<Person, object>(x => new { x.FirstName });
Assert.ContainsSingle(paths);
}
}