1+ using System ;
2+ using System . Diagnostics . CodeAnalysis ;
3+ using System . Linq . Expressions ;
4+ using NUnit . Framework ;
5+ using RediSearchSharp . Utils ;
6+
7+ namespace RediSearchSharp . Tests
8+ {
9+ [ TestFixture ]
10+ [ SuppressMessage ( "ReSharper" , "ClassNeverInstantiated.Local" ) ]
11+ [ SuppressMessage ( "ReSharper" , "UnusedAutoPropertyAccessor.Local" ) ]
12+ public class PropertySelectorExtensionsTests
13+ {
14+ public class GetMemberName
15+ {
16+ private class ChildType
17+ {
18+ public string ChildTypeProperty { get ; set ; }
19+ }
20+
21+ private class TestType
22+ {
23+ public string TestTypeProperty { get ; set ; }
24+ public ChildType ChildType { get ; set ; }
25+ }
26+
27+ [ Test ]
28+ public void Should_throw_when_the_property_selector_is_not_a_member_expression ( )
29+ {
30+ Expression < Func < TestType , string > > testExpression = t => t . ToString ( ) ;
31+ Assert . Throws < ArgumentException > ( ( ) =>
32+ {
33+ testExpression . GetMemberName ( ) ;
34+ } ) ;
35+ }
36+
37+ [ Test ]
38+ public void Should_throw_when_the_expression_is_not_referring_to_a_property_of_the_type ( )
39+ {
40+ Expression < Func < TestType , string > > testExpression = t => t . ChildType . ChildTypeProperty ;
41+ Assert . Throws < ArgumentException > ( ( ) =>
42+ {
43+ testExpression . GetMemberName ( ) ;
44+ } ) ;
45+ }
46+
47+ [ Test ]
48+ public void Should_return_the_property_name ( )
49+ {
50+ Expression < Func < TestType , string > > testExpression = t => t . TestTypeProperty ;
51+
52+ string memberName = testExpression . GetMemberName ( ) ;
53+
54+ Assert . That ( memberName , Is . EqualTo ( "TestTypeProperty" ) ) ;
55+ }
56+ }
57+ }
58+ }
0 commit comments