Skip to content

Commit c47c61b

Browse files
authored
refactor(INetworkMonitor): update return type nullable NetworkMonitorState (#6417)
* refactor: 更改返回值为可为空对象 * test: 更新单元测试
1 parent a1b8cbf commit c47c61b

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/BootstrapBlazor/Services/DefaultNetworkMonitorService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public DefaultNetowrkMonitorService(IJSRuntime jsRuntime)
3434
/// <summary>
3535
/// <inheritdoc/>
3636
/// </summary>
37-
public async Task<NetworkMonitorState> GetNetworkMonitorState(CancellationToken token = default)
37+
public async Task<NetworkMonitorState?> GetNetworkMonitorState(CancellationToken token = default)
3838
{
3939
_module ??= await LoadModule();
40-
return await _module.InvokeAsync<NetworkMonitorState?>("getNetworkInfo", token) ?? new();
40+
return await _module.InvokeAsync<NetworkMonitorState?>("getNetworkInfo", token);
4141
}
4242

4343
/// <summary>

src/BootstrapBlazor/Services/INetworkMonitorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface INetworkMonitorService
1616
/// <param name="token">A cancellation token that can be used to cancel the operation.</param>
1717
/// <returns>A task representing the asynchronous operation. The task result contains the current <see
1818
/// cref="NetworkMonitorState"/>.</returns>
19-
Task<NetworkMonitorState> GetNetworkMonitorState(CancellationToken token = default);
19+
Task<NetworkMonitorState?> GetNetworkMonitorState(CancellationToken token = default);
2020

2121
/// <summary>
2222
/// Registers a callback to be invoked when the network monitor state changes.

test/UnitTest/Services/DefaultNetworkMonitorServiceTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public async Task GetNetworkMonitorState_Ok()
1818
});
1919
var service = Context.Services.GetRequiredService<INetworkMonitorService>();
2020
var state = await service.GetNetworkMonitorState(CancellationToken.None);
21+
Assert.NotNull(state);
2122
Assert.Equal("4g", state.NetworkType);
2223
Assert.Equal(10, state.Downlink);
2324
Assert.Equal(100, state.RTT);

test/UnitTest/Services/TcpSocketFactoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public async Task DelimiterDataPackageHandler_Ok()
637637
var ex = Assert.Throws<ArgumentNullException>(() => new DelimiterDataPackageHandler(string.Empty));
638638
Assert.NotNull(ex);
639639

640-
ex = Assert.Throws<ArgumentNullException>(() => new DelimiterDataPackageHandler((byte[])null!));
640+
ex = Assert.Throws<ArgumentNullException>(() => new DelimiterDataPackageHandler(null!));
641641
Assert.NotNull(ex);
642642
}
643643

0 commit comments

Comments
 (0)