From 698ad814f436023f512453d9da6cea58a2f8c7c0 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 25 Apr 2022 16:28:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20OnChange?= =?UTF-8?q?=20=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/SweetAlert/SwalService.cs | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs index f0dff6cda..e797f0348 100644 --- a/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs +++ b/src/BootstrapBlazor/Components/SweetAlert/SwalService.cs @@ -9,9 +9,8 @@ namespace BootstrapBlazor.Components; /// /// SweetAlert 弹窗服务 /// -public class SwalService : BootstrapServiceBase, IDisposable +public class SwalService : BootstrapServiceBase { - private readonly IDisposable _optionsReloadToken; private BootstrapBlazorOptions _option; /// @@ -21,7 +20,6 @@ public class SwalService : BootstrapServiceBase, IDisposable public SwalService(IOptionsMonitor option) { _option = option.CurrentValue; - _optionsReloadToken = option.OnChange(op => _option = op); } /// @@ -38,25 +36,4 @@ public class SwalService : BootstrapServiceBase, IDisposable await Invoke(option, swal); } - - /// - /// - /// - /// - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - _optionsReloadToken.Dispose(); - } - } - - /// - /// Dispose 方法 - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } } -- Gitee From 96a5bd26f3ae3aec28704b2734865771ace04032 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 25 Apr 2022 16:32:08 +0800 Subject: [PATCH 2/5] =?UTF-8?q?doc:=20=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/BootstrapBlazorServiceCollectionExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs index fa4d45046..ebafc4e5b 100644 --- a/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs +++ b/src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs @@ -131,6 +131,5 @@ public static class BootstrapBlazorServiceCollectionExtensions services.TryAddSingleton, ConfigurationChangeTokenSource>(); services.TryAddSingleton, ConfigureOptions>(); return services; - } } -- Gitee From 96d96abd17afbb44ce3418705faeb65cc41ec8b5 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 25 Apr 2022 18:10:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20WebClient=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/WebClientService.cs | 10 ++--- .../UnitTest/Services/WebClientServiceTest.cs | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 test/UnitTest/Services/WebClientServiceTest.cs diff --git a/src/BootstrapBlazor/Services/WebClientService.cs b/src/BootstrapBlazor/Services/WebClientService.cs index e4a116799..9eb9e8d4e 100644 --- a/src/BootstrapBlazor/Services/WebClientService.cs +++ b/src/BootstrapBlazor/Services/WebClientService.cs @@ -8,7 +8,7 @@ using Microsoft.JSInterop; namespace BootstrapBlazor.Components; /// -/// +/// WebClient 服务类 /// public class WebClientService : IDisposable { @@ -33,7 +33,7 @@ public class WebClientService : IDisposable public WebClientService(IJSRuntime runtime, NavigationManager navigation) => (_runtime, _navigation) = (runtime, navigation); /// - /// + /// 获得 ClientInfo 实例方法 /// /// public async Task GetClientInfo() @@ -54,7 +54,7 @@ public class WebClientService : IDisposable } /// - /// + /// SetData 方法由 JS 调用 /// /// /// @@ -73,7 +73,7 @@ public class WebClientService : IDisposable Client.Ip = ip; Client.OS = os; Client.Browser = browser; - Client.Device = ParseDeviceType(device); + Client.Device = WebClientService.ParseDeviceType(device); Client.Language = language; Client.Engine = engine; Client.UserAgent = agent; @@ -81,7 +81,7 @@ public class WebClientService : IDisposable ReturnTask?.TrySetResult(true); } - private WebClientDeviceType ParseDeviceType(string device) + private static WebClientDeviceType ParseDeviceType(string device) { var ret = WebClientDeviceType.PC; if (Enum.TryParse(device, true, out var d)) diff --git a/test/UnitTest/Services/WebClientServiceTest.cs b/test/UnitTest/Services/WebClientServiceTest.cs new file mode 100644 index 000000000..f40d12f66 --- /dev/null +++ b/test/UnitTest/Services/WebClientServiceTest.cs @@ -0,0 +1,42 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.Extensions.DependencyInjection; + +namespace UnitTest.Services; + +public class WebClientServiceTest : BootstrapBlazorTestBase +{ + [Fact] + public async Task WebClientService_Ok() + { + var service = Context.Services.GetRequiredService(); + service.SetData("test_id", "192.168.0.1", "ios", "chrome", "mobile", "zh", "engine", "test_agent"); + ClientInfo? client = null; + _ = Task.Run(async () => client = await service.GetClientInfo()); + while (client == null) + { + await Task.Delay(100); + service.SetData("test_id", "192.168.0.1", "ios", "chrome", "mobile", "zh", "engine", "test_agent"); + } + client.City = "test_city"; + client.RequestUrl = "test_url"; + Assert.Equal("test_id", client.Id); + Assert.Equal("192.168.0.1", client.Ip); + Assert.Equal("ios", client.OS); + Assert.Equal("chrome", client.Browser); + Assert.Equal(WebClientDeviceType.Mobile, client.Device); + Assert.Equal("zh", client.Language); + Assert.Equal("engine", client.Engine); + Assert.Equal("test_agent", client.UserAgent); + Assert.Equal("test_city", client.City); + Assert.Equal("test_url", client.RequestUrl); + } + + [Fact] + public void WebClientService_Dispose() + { + using var service = Context.Services.GetRequiredService(); + } +} -- Gitee From e21b435353d3441461a07df996f78828c43a1341 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 25 Apr 2022 18:10:10 +0800 Subject: [PATCH 4/5] =?UTF-8?q?doc:=20=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Services/BootstrapServiceBaseTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTest/Services/BootstrapServiceBaseTest.cs b/test/UnitTest/Services/BootstrapServiceBaseTest.cs index 47707e330..ac9d43afa 100644 --- a/test/UnitTest/Services/BootstrapServiceBaseTest.cs +++ b/test/UnitTest/Services/BootstrapServiceBaseTest.cs @@ -25,7 +25,7 @@ public class BootstrapServiceBaseTest private class MockBootstrapService : BootstrapServiceBase { - private Alert Alert { get; set; } = new Alert(); + private Alert Alert { get; } = new Alert(); public async Task Test1(TOption option, Func callback) { -- Gitee From 5aefb4cef1f5a27b6f6a33e45b45dc3caba9511f Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Mon, 25 Apr 2022 18:15:49 +0800 Subject: [PATCH 5/5] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20LookupService?= =?UTF-8?q?=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Core/TableTestBase.cs | 1 - test/UnitTest/Services/LookupServiceTest.cs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/UnitTest/Services/LookupServiceTest.cs diff --git a/test/UnitTest/Core/TableTestBase.cs b/test/UnitTest/Core/TableTestBase.cs index a8dd1cede..53546595e 100644 --- a/test/UnitTest/Core/TableTestBase.cs +++ b/test/UnitTest/Core/TableTestBase.cs @@ -48,7 +48,6 @@ public class TableTestHost : IDisposable { services.AddBootstrapBlazor(op => op.ToastDelay = 2000); services.ConfigureJsonLocalizationOptions(op => op.AdditionalJsonAssemblies = new[] { typeof(Alert).Assembly }); - services.AddSingleton(); } protected virtual void ConfigureConfigration(IServiceCollection services) diff --git a/test/UnitTest/Services/LookupServiceTest.cs b/test/UnitTest/Services/LookupServiceTest.cs new file mode 100644 index 000000000..630f9022e --- /dev/null +++ b/test/UnitTest/Services/LookupServiceTest.cs @@ -0,0 +1,17 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.Extensions.DependencyInjection; + +namespace UnitTest.Services; + +public class LookupServiceTest : MessageTestBase +{ + [Fact] + public void LookupService_Null() + { + var service = Context.Services.GetRequiredService(); + Assert.Null(service.GetItemsByKey("")); + } +} -- Gitee