File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ public class AppSettings
1313
1414 public string BindSecretKey { get ; set ; }
1515 public string BindJwtSecret { get ; set ; }
16+ private string IgnoredProperty { get ; set ; }
1617}
1718
1819public class SettingsExample1
@@ -48,3 +49,16 @@ public class WriteOnlyProperties
4849 public int WeatherId { set => weatherId = value ; }
4950 public string ApiKey { set => apiKey = value ; }
5051}
52+
53+ public class NonPublicProperties
54+ {
55+ public string apiKey ;
56+ public int weatherId ;
57+ public string url ;
58+ public string TokenId { get ; private set ; }
59+ private string ApiKey { get => apiKey ; set => apiKey = value ; }
60+ protected int WeatherId { get => weatherId ; set => weatherId = value ; }
61+ internal string SecretKey { get ; set ; }
62+ protected internal int TimeId { get ; set ; }
63+ private protected string Url { get => url ; set => url = value ; }
64+ }
Original file line number Diff line number Diff line change @@ -122,4 +122,26 @@ public void Bind_WhenPropertyIsWriteOnly_ShouldIgnoreTheWriteOnlyProperty()
122122 Assert . AreNotEqual ( notExpected : 10 , actual : settings . weatherId ) ;
123123 Assert . AreNotEqual ( notExpected : "123456" , actual : settings . apiKey ) ;
124124 }
125+
126+ [ TestMethod ]
127+ public void Bind_WhenAllowedBindNonPublicProperties_ShouldSetNonPublicProperties ( )
128+ {
129+ var customProvider = new CustomEnvironmentVariablesProvider ( ) ;
130+ var binder = new EnvBinder ( customProvider ) . AllowBindNonPublicProperties ( ) ;
131+ customProvider [ "TokenId" ] = "e45d" ;
132+ customProvider [ "ApiKey" ] = "example123" ;
133+ customProvider [ "WeatherId" ] = "3" ;
134+ customProvider [ "SecretKey" ] = "23example" ;
135+ customProvider [ "TimeId" ] = "34" ;
136+ customProvider [ "Url" ] = "example.com" ;
137+
138+ var settings = binder . Bind < NonPublicProperties > ( ) ;
139+
140+ Assert . AreEqual ( expected : "e45d" , actual : settings . TokenId ) ;
141+ Assert . AreEqual ( expected : "example123" , actual : settings . apiKey ) ;
142+ Assert . AreEqual ( expected : 3 , actual : settings . weatherId ) ;
143+ Assert . AreEqual ( expected : "23example" , actual : settings . SecretKey ) ;
144+ Assert . AreEqual ( expected : 34 , actual : settings . TimeId ) ;
145+ Assert . AreEqual ( expected : "example.com" , actual : settings . url ) ;
146+ }
125147}
You can’t perform that action at this time.
0 commit comments