@@ -178,11 +178,13 @@ public void PgService_ViaProperty()
178178
179179 private void PgService_With ( Func < string ? , string ? , int ? , bool , NpgsqlConnectionStringBuilder > factory )
180180 {
181+ // Nominal case
181182 var builder = factory ( "MyService" , "MyHost" , null , false ) ;
182183 builder . PostProcessAndValidate ( ) ;
183184 Assert . That ( builder , Is . Not . Null ) ;
184185 Assert . That ( builder . Count , Is . EqualTo ( 2 ) ) ;
185186
187+ // Missing service file is ignored
186188 var tempFile = Path . GetTempFileName ( ) ;
187189 using var pgServiceFileVariable = SetEnvironmentVariable ( "PGSERVICEFILE" , tempFile ) ;
188190 builder = factory ( "MyService" , "MyHost" , null , false ) ;
@@ -192,12 +194,14 @@ private void PgService_With(Func<string?, string?, int?, bool, NpgsqlConnectionS
192194
193195 try
194196 {
197+ // Comments are ignored
195198 File . WriteAllText ( tempFile , "# test" ) ;
196199 builder = factory ( "MyService" , "MyHost" , null , false ) ;
197200 builder . PostProcessAndValidate ( ) ;
198201 Assert . That ( builder , Is . Not . Null ) ;
199202 Assert . That ( builder . Count , Is . EqualTo ( 2 ) ) ;
200203
204+ // Other services are ignored
201205 File . WriteAllText ( tempFile , """
202206 [OtherService]
203207 Host=test
@@ -208,6 +212,22 @@ private void PgService_With(Func<string?, string?, int?, bool, NpgsqlConnectionS
208212 Assert . That ( builder , Is . Not . Null ) ;
209213 Assert . That ( builder . Count , Is . EqualTo ( 2 ) ) ;
210214
215+ // Unknown settings are ignored
216+ File . WriteAllText ( tempFile , """
217+ [MyService]
218+ Unknown=test
219+ Port=1234
220+ """ ) ;
221+ builder = factory ( "MyService" , "MyHost" , null , false ) ;
222+ builder . PostProcessAndValidate ( ) ;
223+ builder . PostProcessAndValidate ( ) ;
224+ Assert . That ( builder , Is . Not . Null ) ;
225+ Assert . That ( builder . Count , Is . EqualTo ( 3 ) ) ;
226+ Assert . That ( builder . Host , Is . EqualTo ( "MyHost" ) ) ;
227+ Assert . That ( builder . Port , Is . EqualTo ( 1234 ) ) ;
228+ Assert . That ( builder . Service , Is . EqualTo ( "MyService" ) ) ;
229+
230+ // Overridden settings are ignored
211231 File . WriteAllText ( tempFile , """
212232 [MyService]
213233 Host=test
@@ -242,47 +262,4 @@ private void PgService_With(Func<string?, string?, int?, bool, NpgsqlConnectionS
242262 File . Delete ( tempFile ) ;
243263 }
244264 }
245-
246- [ Test ]
247- [ NonParallelizable ] // Sets environment variable
248- public void FromPgServiceFile ( )
249- {
250- Assert . Throws < ArgumentException > ( ( ) => NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ) ;
251-
252- Assert . Null ( NpgsqlConnectionStringBuilder . FromPgServiceFile ( "MyService" ) ) ;
253-
254- using var pgServiceVariable = SetEnvironmentVariable ( "PGSERVICE" , "MyService" ) ;
255- Assert . Null ( NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ) ;
256-
257- var tempFile = Path . GetTempFileName ( ) ;
258- using var pgServiceFileVariable = SetEnvironmentVariable ( "PGSERVICEFILE" , tempFile ) ;
259- Assert . Null ( NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ) ;
260-
261- try
262- {
263- File . WriteAllText ( tempFile , "# test" ) ;
264- Assert . Null ( NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ) ;
265-
266- File . WriteAllText ( tempFile , """
267- [OtherService]
268- Host=test
269- Port=1234
270- """ ) ;
271- Assert . Null ( NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ) ;
272-
273- File . WriteAllText ( tempFile , """
274- [MyService]
275- Host=test
276- Port=1234
277- """ ) ;
278- var builder = NpgsqlConnectionStringBuilder . FromPgServiceFile ( ) ;
279- Assert . NotNull ( builder ) ;
280- Assert . AreEqual ( "test" , builder ! . Host ) ;
281- Assert . AreEqual ( 1234 , builder . Port ) ;
282- }
283- finally
284- {
285- File . Delete ( tempFile ) ;
286- }
287- }
288265}
0 commit comments