11using System ;
2+ using System . Collections . Generic ;
23using NUnit . Framework ;
34using System . Linq . Expressions ;
45using Nest . Resolvers ;
@@ -12,6 +13,9 @@ public class PropertyNameResolverTests : BaseJsonTests
1213 internal class SomeClass
1314 {
1415 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 ; }
1519 }
1620 [ ElasticType ( IdProperty = "Guid" ) ]
1721 internal class SomeOtherClass
@@ -44,6 +48,7 @@ public override string ToString()
4448 return "static id ftw" ;
4549 }
4650 }
51+
4752 [ Test ]
4853 public void TestUsesElasticProperty ( )
4954 {
@@ -52,6 +57,7 @@ public void TestUsesElasticProperty()
5257 var expected = "myCustomClass.MID" ;
5358 Assert . AreEqual ( expected , propertyName ) ;
5459 }
60+
5561 [ Test ]
5662 public void TestUsesOtherElasticProperty ( )
5763 {
@@ -60,6 +66,7 @@ public void TestUsesOtherElasticProperty()
6066 var expected = "custom.MID" ;
6167 Assert . AreEqual ( expected , propertyName ) ;
6268 }
69+
6370 [ Test ]
6471 public void TestUsesOtherElasticTypePropertyIsIgnored ( )
6572 {
@@ -68,6 +75,7 @@ public void TestUsesOtherElasticTypePropertyIsIgnored()
6875 var expected = "myCustomOtherClass.MID" ;
6976 Assert . AreEqual ( expected , propertyName ) ;
7077 }
78+
7179 [ Test ]
7280 public void TestCreatedDate ( )
7381 {
@@ -76,6 +84,34 @@ public void TestCreatedDate()
7684 var expected = "CreateDate" ;
7785 Assert . AreEqual ( expected , propertyName ) ;
7886 }
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+
79115 [ Test ]
80116 public void SearchUsesTheProperResolver ( )
81117 {
0 commit comments