@@ -40,5 +40,59 @@ public void Given_Property_When_GetJsonPropertyName_Invoked_Then_It_Should_Retur
4040
4141 result . Should ( ) . Be ( jsonPropertyName ) ;
4242 }
43+
44+ [ TestMethod ]
45+ public void Given_Property_When_GetJsonPropertyName_IsEmpty_Then_It_Should_Return_ElementName ( )
46+ {
47+ var name = "FakePropertyNoPropertyValue" ;
48+ var property = typeof ( FakeModel ) . GetProperty ( name , BindingFlags . Public | BindingFlags . Instance ) ;
49+ var namingStrategy = new DefaultNamingStrategy ( ) ;
50+
51+ var result = PropertyInfoExtensions . GetJsonPropertyName ( property , namingStrategy ) ;
52+
53+ result . Should ( ) . NotBeNullOrEmpty ( ) ;
54+ result . Should ( ) . Be ( name ) ;
55+ }
56+
57+ [ TestMethod ]
58+ public void Given_Property_When_DefaultJsonProperyAnnotation_Invoked_Then_It_Should_Return_ElementName ( )
59+ {
60+ var name = "FakePropertyNoAnnotation" ;
61+ var property = typeof ( FakeModel ) . GetProperty ( name , BindingFlags . Public | BindingFlags . Instance ) ;
62+ var namingStrategy = new DefaultNamingStrategy ( ) ;
63+
64+ var result = PropertyInfoExtensions . GetJsonPropertyName ( property , namingStrategy ) ;
65+
66+ result . Should ( ) . NotBeNullOrEmpty ( ) ;
67+ result . Should ( ) . Be ( name ) ;
68+ }
69+
70+ [ TestMethod ]
71+ public void Given_Property_When_GetJsonPropertyName_IsEmpty_WithCamelCaseNaming_Then_It_Should_Return_ElementName ( )
72+ {
73+ var name = "FakePropertyNoPropertyValue" ;
74+ var camelCaseName = "fakePropertyNoPropertyValue" ;
75+ var property = typeof ( FakeModel ) . GetProperty ( name , BindingFlags . Public | BindingFlags . Instance ) ;
76+ var namingStrategy = new CamelCaseNamingStrategy ( ) ;
77+
78+ var result = PropertyInfoExtensions . GetJsonPropertyName ( property , namingStrategy ) ;
79+
80+ result . Should ( ) . NotBeNullOrEmpty ( ) ;
81+ result . Should ( ) . Be ( camelCaseName ) ;
82+ }
83+
84+ [ TestMethod ]
85+ public void Given_Property_When_DefaultJsonProperyAnnotation_Invoked_WithCamelCaseNaming_Then_It_Should_Return_ElementName ( )
86+ {
87+ var name = "FakePropertyNoAnnotation" ;
88+ var camelCaseName = "fakePropertyNoAnnotation" ;
89+ var property = typeof ( FakeModel ) . GetProperty ( name , BindingFlags . Public | BindingFlags . Instance ) ;
90+ var namingStrategy = new CamelCaseNamingStrategy ( ) ;
91+
92+ var result = PropertyInfoExtensions . GetJsonPropertyName ( property , namingStrategy ) ;
93+
94+ result . Should ( ) . NotBeNullOrEmpty ( ) ;
95+ result . Should ( ) . Be ( camelCaseName ) ;
96+ }
4397 }
4498}
0 commit comments