66using Shouldly ;
77using Xunit ;
88
9- namespace JavaVersionSwitcher . Tests
9+ namespace JavaVersionSwitcher . Tests ;
10+
11+ public class ConfigurationServiceTests
1012{
11- public class ConfigurationServiceTests
13+ [ Fact ]
14+ public async Task SetConfiguration_throws_on_wrong_provider ( )
1215 {
13- [ Fact ]
14- public async Task SetConfiguration_throws_on_wrong_provider ( )
15- {
16- // arrange
17- using var fixture = new ConfigurationServiceFixture ( ) ;
18- const string providerName = "non-existent-provider" ;
16+ // arrange
17+ using var fixture = new ConfigurationServiceFixture ( ) ;
18+ const string providerName = "non-existent-provider" ;
1919
20- // act
21- // ReSharper disable once AccessToDisposedClosure
22- async Task Act ( ) => await fixture . Service . SetConfiguration ( providerName , null , null ) ;
20+ // act
21+ // ReSharper disable once AccessToDisposedClosure
22+ async Task Act ( ) => await fixture . Service . SetConfiguration ( providerName , null , null ) ;
2323
24- // assert
25- ( await Should . ThrowAsync < KeyNotFoundException > ( ( Func < Task > ) Act ) )
26- . Message
27- . ShouldSatisfyAllConditions (
28- m => m . ShouldStartWith ( "No ConfigurationProvider" ) ,
29- m => m . ShouldContain ( providerName ) ) ;
30- }
24+ // assert
25+ ( await Should . ThrowAsync < KeyNotFoundException > ( ( Func < Task > ) Act ) )
26+ . Message
27+ . ShouldSatisfyAllConditions (
28+ m => m . ShouldStartWith ( "No ConfigurationProvider" ) ,
29+ m => m . ShouldContain ( providerName ) ) ;
30+ }
3131
32- [ Fact ]
33- public async Task SetConfiguration_throws_on_wrong_setting ( )
34- {
35- // arrange
36- const string providerName = "provider" ;
37- using var fixture = new ConfigurationServiceFixture ( ) ;
38- fixture . WithConfigurationProvider ( providerName ) ;
39- const string setting = "non-existent-setting" ;
32+ [ Fact ]
33+ public async Task SetConfiguration_throws_on_wrong_setting ( )
34+ {
35+ // arrange
36+ const string providerName = "provider" ;
37+ using var fixture = new ConfigurationServiceFixture ( ) ;
38+ fixture . WithConfigurationProvider ( providerName ) ;
39+ const string setting = "non-existent-setting" ;
4040
41- // act'
42- // ReSharper disable once AccessToDisposedClosure
43- async Task Act ( ) => await fixture . Service . SetConfiguration ( providerName , setting , null ) ;
41+ // act'
42+ // ReSharper disable once AccessToDisposedClosure
43+ async Task Act ( ) => await fixture . Service . SetConfiguration ( providerName , setting , null ) ;
4444
45- // assert
46- ( await Should . ThrowAsync < KeyNotFoundException > ( ( Func < Task > ) Act ) )
47- . Message
48- . ShouldSatisfyAllConditions (
49- m => m . ShouldStartWith ( "No Configuration with the name" ) ,
50- m => m . ShouldContain ( setting ) ) ;
51- }
45+ // assert
46+ ( await Should . ThrowAsync < KeyNotFoundException > ( ( Func < Task > ) Act ) )
47+ . Message
48+ . ShouldSatisfyAllConditions (
49+ m => m . ShouldStartWith ( "No Configuration with the name" ) ,
50+ m => m . ShouldContain ( setting ) ) ;
51+ }
5252
53- [ Fact ]
54- public async Task SetConfiguration_writes_value_to_xml ( )
55- {
56- // arrange
57- const string providerName = "pName" ;
58- const string settingsName = "settingsName" ;
59- const string value = "a value" ;
60- using var fixture = new ConfigurationServiceFixture ( ) ;
61- fixture . WithConfigurationProvider ( providerName , settingsName ) ;
53+ [ Fact ]
54+ public async Task SetConfiguration_writes_value_to_xml ( )
55+ {
56+ // arrange
57+ const string providerName = "pName" ;
58+ const string settingsName = "settingsName" ;
59+ const string value = "a value" ;
60+ using var fixture = new ConfigurationServiceFixture ( ) ;
61+ fixture . WithConfigurationProvider ( providerName , settingsName ) ;
6262
63- // act'
64- await fixture . Service . SetConfiguration ( providerName , settingsName , value ) ;
63+ // act'
64+ await fixture . Service . SetConfiguration ( providerName , settingsName , value ) ;
6565
66- // assert
67- var xml = fixture . ReadXml ( providerName , settingsName ) ;
68- xml . Value . ShouldBe ( value ) ;
69- }
66+ // assert
67+ var xml = fixture . ReadXml ( providerName , settingsName ) ;
68+ xml . Value . ShouldBe ( value ) ;
69+ }
7070
71- [ Fact ]
72- public async Task GetConfiguration_returns_empty_for_not_set_setting ( )
73- {
74- // arrange
75- const string providerName = "pName" ;
76- const string settingsName = "settingsName" ;
77- using var fixture = new ConfigurationServiceFixture ( ) ;
78- fixture . WithConfigurationProvider ( providerName , settingsName ) ;
71+ [ Fact ]
72+ public async Task GetConfiguration_returns_empty_for_not_set_setting ( )
73+ {
74+ // arrange
75+ const string providerName = "pName" ;
76+ const string settingsName = "settingsName" ;
77+ using var fixture = new ConfigurationServiceFixture ( ) ;
78+ fixture . WithConfigurationProvider ( providerName , settingsName ) ;
7979
80- // act'
81- var actual = await fixture . Service . GetConfiguration ( providerName , settingsName ) ;
80+ // act'
81+ var actual = await fixture . Service . GetConfiguration ( providerName , settingsName ) ;
8282
83- // assert
84- actual . ShouldBe ( string . Empty ) ;
85- }
83+ // assert
84+ actual . ShouldBe ( string . Empty ) ;
85+ }
8686
87- [ Fact ]
88- public async Task GetConfiguration_returns_the_value_from_xml ( )
89- {
90- // arrange
91- const string providerName = "pName" ;
92- const string settingsName = "settingsName" ;
93- const string expected = "some value" ;
94- using var fixture = new ConfigurationServiceFixture ( ) ;
95- fixture . WithConfigurationProvider ( providerName , settingsName ) ;
96- fixture . EnsureSetting ( providerName , settingsName , expected ) ;
87+ [ Fact ]
88+ public async Task GetConfiguration_returns_the_value_from_xml ( )
89+ {
90+ // arrange
91+ const string providerName = "pName" ;
92+ const string settingsName = "settingsName" ;
93+ const string expected = "some value" ;
94+ using var fixture = new ConfigurationServiceFixture ( ) ;
95+ fixture . WithConfigurationProvider ( providerName , settingsName ) ;
96+ fixture . EnsureSetting ( providerName , settingsName , expected ) ;
9797
98- // act'
99- var actual = await fixture . Service . GetConfiguration ( providerName , settingsName ) ;
98+ // act'
99+ var actual = await fixture . Service . GetConfiguration ( providerName , settingsName ) ;
100100
101- // assert
102- actual . ShouldBe ( expected ) ;
103- }
101+ // assert
102+ actual . ShouldBe ( expected ) ;
103+ }
104104
105- [ Fact ]
106- public async Task SetConfiguration_removes_empty_settings ( )
107- {
108- // arrange
109- const string providerName = "pName" ;
110- const string settingsName = "settingsName" ;
111- using var fixture = new ConfigurationServiceFixture ( ) ;
112- fixture . WithConfigurationProvider ( providerName , settingsName ) ;
113- fixture . EnsureSetting ( providerName , settingsName , "some value" ) ;
105+ [ Fact ]
106+ public async Task SetConfiguration_removes_empty_settings ( )
107+ {
108+ // arrange
109+ const string providerName = "pName" ;
110+ const string settingsName = "settingsName" ;
111+ using var fixture = new ConfigurationServiceFixture ( ) ;
112+ fixture . WithConfigurationProvider ( providerName , settingsName ) ;
113+ fixture . EnsureSetting ( providerName , settingsName , "some value" ) ;
114114
115- // act'
116- await fixture . Service . SetConfiguration ( providerName , settingsName , null ) ;
115+ // act'
116+ await fixture . Service . SetConfiguration ( providerName , settingsName , null ) ;
117117
118- // assert
119- var xml = fixture . ReadXml ( ) ;
120- xml . Parent . ShouldBeNull ( "this should be the root node." ) ;
121- xml . Elements ( ) . Count ( ) . ShouldBe ( 0 ) ;
122- }
118+ // assert
119+ var xml = fixture . ReadXml ( ) ;
120+ xml . Parent . ShouldBeNull ( "this should be the root node." ) ;
121+ xml . Elements ( ) . Count ( ) . ShouldBe ( 0 ) ;
123122 }
124123}
0 commit comments