diff --git a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs index bd5e4606755..35861567f7a 100644 --- a/src/BootstrapBlazor/Components/Affix/Affix.razor.cs +++ b/src/BootstrapBlazor/Components/Affix/Affix.razor.cs @@ -41,7 +41,7 @@ public partial class Affix private string? StyleString => CssBuilder.Default("position: sticky;") .AddStyle("z-index", $"{ZIndex}", ZIndex.HasValue) - .AddStyle($"{Position.ToDescriptionString()}", $"{Offset}px") + .AddStyle(Position.ToDescriptionString(), $"{Offset}px") .AddStyleFromAttributes(AdditionalAttributes) .Build(); } diff --git a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs index cf3e86aba3a..a4e32e5ad83 100644 --- a/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs +++ b/src/BootstrapBlazor/Components/Drawer/Drawer.razor.cs @@ -19,7 +19,7 @@ public partial class Drawer .Build(); private string? StyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-position", $"{Position}", !string.IsNullOrEmpty(Position)) + .AddStyle("--bb-drawer-position", Position) .AddStyleFromAttributes(AdditionalAttributes) .Build(); @@ -27,8 +27,8 @@ public partial class Drawer /// 获得 抽屉 Style 字符串 /// private string? DrawerStyleString => CssBuilder.Default() - .AddStyle("--bb-drawer-width", $"{Width}", !string.IsNullOrEmpty(Width) && Placement != Placement.Top && Placement != Placement.Bottom) - .AddStyle("--bb-drawer-height", $"{Height}", !string.IsNullOrEmpty(Height) && (Placement == Placement.Top || Placement == Placement.Bottom)) + .AddStyle("--bb-drawer-width", Width, Placement != Placement.Top && Placement != Placement.Bottom) + .AddStyle("--bb-drawer-height", Height, Placement == Placement.Top || Placement == Placement.Bottom) .Build(); /// diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index 9b4ad06dfad..34c25d1b0ee 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -39,15 +39,17 @@ public async Task GetClientInfo() { RequestUrl = navigation.Uri }; - _jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js"); - _interop ??= DotNetObjectReference.Create(this); - await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData)); - // 等待 SetData 方法执行完毕 try { - await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(1)); + _jsModule ??= await runtime.LoadModule("./_content/BootstrapBlazor/modules/client.js"); + _interop ??= DotNetObjectReference.Create(this); + await _jsModule.InvokeVoidAsync("ping", "ip.axd", _interop, nameof(SetData)); + + // 等待 SetData 方法执行完毕 + await _taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(3)); } + catch (TimeoutException) { } catch (Exception ex) { logger.LogError(ex, "method GetClientInfo failed"); diff --git a/test/UnitTest/Services/WebClientServiceTest.cs b/test/UnitTest/Services/WebClientServiceTest.cs index 6d7bf64861a..35ff8cdcb36 100644 --- a/test/UnitTest/Services/WebClientServiceTest.cs +++ b/test/UnitTest/Services/WebClientServiceTest.cs @@ -59,11 +59,17 @@ public async Task WebClientOptions_Ok() } [Fact] - public async Task Timeout_Ok() + public async Task GetClientInfo_Error() { var service = Context.Services.GetRequiredService(); var client = await service.GetClientInfo(); + + // TimeoutException Assert.Null(client.Ip); + + // Exception + Context.JSInterop.SetupVoid("ping", _ => true).SetException(new Exception("test-exception")); + client = await service.GetClientInfo(); } [Fact]