1+ using Everything . Wrapper ;
12using Lanceur . Core . Configuration ;
23using Lanceur . Core . Configuration . Configurations ;
34using Lanceur . Core . Configuration . Sections ;
1415using Lanceur . Tests . Tools . SQL ;
1516using Lanceur . Ui . Core . Extensions ;
1617using Microsoft . Extensions . DependencyInjection ;
18+ using NSubstitute ;
1719using Shouldly ;
1820using Xunit ;
1921
@@ -52,7 +54,7 @@ public void RegisterAllStores()
5254 [ Theory ]
5355 [ InlineData ( null , "pp hello world" ) ] // null override, then use the default one
5456 [ InlineData ( "^pp.*" , ": hello world" ) ]
55- public void UseDefaultShortcutWhenNoOverride ( string aliasOverride , string cmdlineString )
57+ public void UseDefaultShortcutWhenNoOverride ( string ? aliasOverride , string cmdlineString )
5658 {
5759 // arrange
5860 var cfgOverride = aliasOverride is null
@@ -77,9 +79,22 @@ public void UseDefaultShortcutWhenNoOverride(string aliasOverride, string cmdlin
7779 . AddSingleton < IStoreService , EverythingStore > ( )
7880 . AddSingleton < IStoreOrchestrationFactory , StoreOrchestrationFactory > ( )
7981 . AddSingleton < ISearchServiceOrchestrator , SearchServiceOrchestrator > ( )
80- . AddStoreServicesMockContext ( )
8182 . AddStoreServicesConfiguration ( cfgOverride )
8283 . AddTestOutputHelper ( OutputHelper )
84+ . AddStoreServicesMockContext ( ( _ , i ) => {
85+ i . Value . Returns ( new StoreSection
86+ {
87+ StoreShortcuts =
88+ [
89+ new StoreShortcut
90+ {
91+ AliasOverride = aliasOverride ,
92+ StoreType = typeof ( EverythingStore ) . FullName
93+ }
94+ ]
95+ } ) ;
96+ return i ;
97+ } )
8398 . BuildServiceProvider ( ) ;
8499
85100 // act
@@ -89,14 +104,16 @@ public void UseDefaultShortcutWhenNoOverride(string aliasOverride, string cmdlin
89104 var orchestrator = serviceProvider . GetService < ISearchServiceOrchestrator > ( ) ! ;
90105
91106 // assert
107+ OutputHelper . WriteLine ( $ "Alive pattern: '{ store . StoreOrchestration . AlivePattern } '") ;
108+ OutputHelper . WriteLine ( $ "Cmdline : { cmdlineString } ") ;
92109 orchestrator . IsAlive ( store , Cmdline . Parse ( cmdlineString ) )
93110 . ShouldBeFalse ( ) ;
94111 }
95112
96113 [ Theory ]
97114 [ InlineData ( null , ": hello world" ) ] // null override, then use the default one
98115 [ InlineData ( "^pp.*" , "pp hello world" ) ]
99- public void UseOverridenShortcutWhenConfigured ( string aliasOverride , string cmdlineString )
116+ public void UseOverridenShortcutWhenConfigured ( string ? aliasOverride , string cmdlineString )
100117 {
101118 // arrange
102119 var cfgOverride = aliasOverride is null
@@ -121,7 +138,17 @@ public void UseOverridenShortcutWhenConfigured(string aliasOverride, string cmdl
121138 . AddSingleton < IStoreService , EverythingStore > ( )
122139 . AddSingleton < IStoreOrchestrationFactory , StoreOrchestrationFactory > ( )
123140 . AddSingleton < ISearchServiceOrchestrator , SearchServiceOrchestrator > ( )
124- . AddStoreServicesMockContext ( )
141+ . AddStoreServicesMockContext ( ( _ , i ) => {
142+ i . Value . Returns ( new StoreSection ( )
143+ {
144+ StoreShortcuts = [ new StoreShortcut
145+ {
146+ StoreType = typeof ( EverythingStore ) . FullName ,
147+ AliasOverride = aliasOverride
148+ } ]
149+ } ) ;
150+ return i ;
151+ } )
125152 . AddStoreServicesConfiguration ( cfgOverride )
126153 . BuildServiceProvider ( ) ;
127154
@@ -157,19 +184,23 @@ public void UseOverridenShortcutWhenUpdated()
157184 var orchestrator = serviceProvider . GetService < ISearchServiceOrchestrator > ( ) ! ;
158185 var configuration = serviceProvider . GetService < IConfigurationFacade > ( ) ! ;
159186
160- // At this point, there's no configuration, we used the default config (hardcoded)
161- orchestrator . IsAlive ( store , Cmdline . Parse ( cmdlineString1 ) ) . ShouldBeTrue ( "Default values should be used" ) ;
162-
163- // Let's update the configuration and check whether it is taken into account
164- UpdateConfiguration ( aliasOverride1 ) ;
165- orchestrator . IsAlive ( store , Cmdline . Parse ( cmdlineString2 ) )
166- . ShouldBeTrue ( "When updating from default values to new value" ) ;
167-
168- // Let's do this again to be sure the update can be done multiple times
169- UpdateConfiguration ( aliasOverride2 ) ;
170- orchestrator . IsAlive ( store , Cmdline . Parse ( cmdlineString3 ) )
171- . ShouldBeTrue ( "When updating from some values to updated values" ) ;
172-
187+ orchestrator . ShouldSatisfyAllConditions (
188+ o =>
189+ // "At this point, there's no configuration, we used the default config (hardcoded)"
190+ o . IsAlive ( store , Cmdline . Parse ( cmdlineString1 ) )
191+ . ShouldBeTrue ( "Default values should be used" ) ,
192+ o => {
193+ // Let's update the configuration and check whether it is taken into account
194+ UpdateConfiguration ( aliasOverride1 ) ;
195+ o . IsAlive ( store , Cmdline . Parse ( cmdlineString2 ) )
196+ . ShouldBeTrue ( "When updating from default values to new value" ) ;
197+ } ,
198+ o => {
199+ // Let's do this again to be sure the update can be done multiple times
200+ UpdateConfiguration ( aliasOverride2 ) ;
201+ o . IsAlive ( store , Cmdline . Parse ( cmdlineString3 ) )
202+ . ShouldBeTrue ( "When updating from some values to updated values" ) ;
203+ } ) ;
173204 return ;
174205
175206 IServiceProvider ConfigureServices ( )
@@ -180,8 +211,7 @@ IServiceProvider ConfigureServices()
180211 . AddSingleton < IStoreService , EverythingStore > ( )
181212 . AddSingleton < IStoreOrchestrationFactory , StoreOrchestrationFactory > ( )
182213 . AddSingleton < ISearchServiceOrchestrator , SearchServiceOrchestrator > ( )
183- . AddStoreServicesMockContext ( )
184- . AddTestOutputHelper ( OutputHelper ) ;
214+ . AddMockSingleton < IEverythingApi > ( ) ; // Real ISection<StoreSection> needed — don't use AddStoreServicesMockContext()
185215
186216 serviceCollection . AddConfiguration ( ) // Real configuration facility (not mocked)
187217 . AddConfigurationSections ( )
@@ -193,7 +223,11 @@ void UpdateConfiguration(string aliasOverride)
193223 {
194224 configuration . Application . Stores . StoreShortcuts =
195225 [
196- new StoreShortcut { StoreType = typeof ( EverythingStore ) . ToString ( ) , AliasOverride = aliasOverride }
226+ new StoreShortcut
227+ {
228+ StoreType = typeof ( EverythingStore ) . ToString ( ) ,
229+ AliasOverride = aliasOverride
230+ }
197231 ] ;
198232 configuration . Save ( ) ;
199233 }
0 commit comments