1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using NUnit . Framework ;
3
4
using System . Linq . Expressions ;
4
5
using Nest . Resolvers ;
@@ -12,6 +13,9 @@ public class PropertyNameResolverTests : BaseJsonTests
12
13
internal class SomeClass
13
14
{
14
15
public MyCustomClass MyCustomClass { get ; set ; }
16
+ public Dictionary < string , SomeOtherClass > StringDict { get ; set ; }
17
+ public Dictionary < int , MyCustomClass > IntDict { get ; set ; }
18
+ public IList < MyCustomClass > ListOfCustomClasses { get ; set ; }
15
19
}
16
20
[ ElasticType ( IdProperty = "Guid" ) ]
17
21
internal class SomeOtherClass
@@ -44,6 +48,7 @@ public override string ToString()
44
48
return "static id ftw" ;
45
49
}
46
50
}
51
+
47
52
[ Test ]
48
53
public void TestUsesElasticProperty ( )
49
54
{
@@ -52,6 +57,7 @@ public void TestUsesElasticProperty()
52
57
var expected = "myCustomClass.MID" ;
53
58
Assert . AreEqual ( expected , propertyName ) ;
54
59
}
60
+
55
61
[ Test ]
56
62
public void TestUsesOtherElasticProperty ( )
57
63
{
@@ -60,6 +66,7 @@ public void TestUsesOtherElasticProperty()
60
66
var expected = "custom.MID" ;
61
67
Assert . AreEqual ( expected , propertyName ) ;
62
68
}
69
+
63
70
[ Test ]
64
71
public void TestUsesOtherElasticTypePropertyIsIgnored ( )
65
72
{
@@ -68,6 +75,7 @@ public void TestUsesOtherElasticTypePropertyIsIgnored()
68
75
var expected = "myCustomOtherClass.MID" ;
69
76
Assert . AreEqual ( expected , propertyName ) ;
70
77
}
78
+
71
79
[ Test ]
72
80
public void TestCreatedDate ( )
73
81
{
@@ -76,6 +84,34 @@ public void TestCreatedDate()
76
84
var expected = "CreateDate" ;
77
85
Assert . AreEqual ( expected , propertyName ) ;
78
86
}
87
+
88
+ [ Test ]
89
+ public void TestDictionaryStringExpression ( )
90
+ {
91
+ Expression < Func < SomeClass , object > > exp = ( m ) => m . StringDict [ "someValue" ] . CreateDate ;
92
+ var propertyName = new PropertyNameResolver ( ) . Resolve ( exp ) ;
93
+ var expected = "stringDict.someValue.CreateDate" ;
94
+ Assert . AreEqual ( expected , propertyName ) ;
95
+ }
96
+
97
+ [ Test ]
98
+ public void TestDictionaryIntExpression ( )
99
+ {
100
+ Expression < Func < SomeClass , object > > exp = ( m ) => m . IntDict [ 101 ] . MyProperty ;
101
+ var propertyName = new PropertyNameResolver ( ) . Resolve ( exp ) ;
102
+ var expected = "intDict.101.MID" ;
103
+ Assert . AreEqual ( expected , propertyName ) ;
104
+ }
105
+
106
+ [ Test ]
107
+ public void TestCollectionIndexExpressionDoesNotEndUpInPath ( )
108
+ {
109
+ Expression < Func < SomeClass , object > > exp = ( m ) => m . ListOfCustomClasses [ 101 ] . MyProperty ;
110
+ var propertyName = new PropertyNameResolver ( ) . Resolve ( exp ) ;
111
+ var expected = "listOfCustomClasses.MID" ;
112
+ Assert . AreEqual ( expected , propertyName ) ;
113
+ }
114
+
79
115
[ Test ]
80
116
public void SearchUsesTheProperResolver ( )
81
117
{
0 commit comments