File tree Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Expand file tree Collapse file tree 5 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk.Razor" >
22
33 <PropertyGroup >
4- <Version >9.1.7 </Version >
4+ <Version >9.1.8 </Version >
55 </PropertyGroup >
66
77 <ItemGroup >
Original file line number Diff line number Diff line change @@ -235,6 +235,13 @@ public partial class Select<TValue> : ISelect
235235 [ NotNull ]
236236 private IStringLocalizer < Select < TValue > > ? Localizer { get ; set ; }
237237
238+ /// <summary>
239+ /// 获得/设置 <see cref="ILookupService"/> 服务实例
240+ /// </summary>
241+ [ Inject ]
242+ [ NotNull ]
243+ private ILookupService ? InjectLookupService { get ; set ; }
244+
238245 /// <summary>
239246 /// 获得 input 组件 Id 方法
240247 /// </summary>
@@ -371,13 +378,15 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
371378 private async Task < IEnumerable < SelectedItem > > GetItemsAsync ( )
372379 {
373380 IEnumerable < SelectedItem > ? items = null ;
374- if ( LookupService != null )
381+ if ( ! string . IsNullOrEmpty ( LookupServiceKey ) )
375382 {
376- items = await LookupService . GetItemsByKeyAsync ( LookupServiceKey , LookupServiceData ) ;
383+ items = await GetLookupService ( ) . GetItemsAsync ( LookupServiceKey , LookupServiceData ) ;
377384 }
378385 return items ?? [ ] ;
379386 }
380387
388+ private ILookupService GetLookupService ( ) => LookupService ?? InjectLookupService ;
389+
381390 /// <summary>
382391 /// 获得/设置 数据总条目
383392 /// </summary>
Original file line number Diff line number Diff line change @@ -438,6 +438,7 @@ public async Task LookupServiceKey_Ok()
438438 builder . CloseComponent ( ) ;
439439 } ) ;
440440 } ) ;
441+ cut . WaitForAssertion ( ( ) => cut . Contains ( "LookupService-Test-1" ) ) ;
441442 var select = cut . FindComponent < Select < string > > ( ) ;
442443 var lookupService = Context . Services . GetRequiredService < ILookupService > ( ) ;
443444 var lookup = await lookupService . GetItemsAsync ( "FooLookup" , "" ) ;
@@ -471,7 +472,7 @@ public async Task LookupService_Ok()
471472 builder . CloseComponent ( ) ;
472473 } ) ;
473474 } ) ;
474- cut . WaitForElements ( ".select" ) ;
475+ cut . WaitForAssertion ( ( ) => cut . Contains ( "LookupService-Test-1-async" ) ) ;
475476 var select = cut . FindComponent < Select < string > > ( ) ;
476477 var lookup = await lookupService . GetItemsAsync ( "FooLookup" , "" ) ;
477478 Assert . NotNull ( lookup ) ;
Original file line number Diff line number Diff line change @@ -106,6 +106,18 @@ public void Disabled_Ok()
106106 Assert . Contains ( "dropdown-item active disabled" , cut . Markup ) ;
107107 }
108108
109+ [ Fact ]
110+ public void LookupService_Ok ( )
111+ {
112+ // 不给 Items 时走 LookupService
113+ var cut = Context . RenderComponent < Select < string > > ( pb =>
114+ {
115+ pb . Add ( a => a . LookupServiceKey , "FooLookup" ) ;
116+ } ) ;
117+ cut . WaitForAssertion ( ( ) => cut . Contains ( "LookupService-Test-1" ) ) ;
118+ Assert . Equal ( 2 , cut . Instance . Items . Count ( ) ) ;
119+ }
120+
109121 [ Fact ]
110122 public void IsClearable_Ok ( )
111123 {
Original file line number Diff line number Diff line change @@ -7673,7 +7673,6 @@ public async Task GetValue_LookupServiceKey()
76737673 pb . Add ( a => a . LookupService , new MockLookupServiceAsync ( ) ) ;
76747674 } ) ;
76757675 await cut . InvokeAsync ( ( ) => table . Instance . QueryAsync ( ) ) ;
7676- cut . WaitForElement ( "[data-bs-original-title=\" LookupService-Test-True-async\" ]" ) ;
76777676 }
76787677
76797678 [ Fact ]
You can’t perform that action at this time.
0 commit comments