Skip to content

Commit 417d179

Browse files
committed
test: 提高 TryConvertTo 方法代码覆盖率
1 parent 07af0a8 commit 417d179

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

test/UnitTestTcpSocket/TcpSocketFactoryTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

5+
using BootstrapBlazor.Socket.Logging;
56
using Microsoft.Extensions.Logging;
67
using System.Buffers;
78
using System.Net;
@@ -631,6 +632,14 @@ public async Task DelimiterDataPackageHandler_Ok()
631632
Assert.NotNull(ex);
632633
}
633634

635+
[Fact]
636+
public void TryConvertTo_Error()
637+
{
638+
var converter = new MockErrorDataConverter();
639+
var result = converter.TryConvertTo(new byte[] { 0x1, 0x2 }, out var entity);
640+
Assert.False(result);
641+
}
642+
634643
[Fact]
635644
public async Task TryConvertTo_Ok()
636645
{
@@ -1417,6 +1426,14 @@ protected override bool Parse(ReadOnlyMemory<byte> data, MockEntity entity)
14171426
}
14181427
}
14191428

1429+
class MockErrorDataConverter : DataConverter<MockEntity>
1430+
{
1431+
protected override bool Parse(ReadOnlyMemory<byte> data, MockEntity entity)
1432+
{
1433+
throw new Exception("Mock parse error");
1434+
}
1435+
}
1436+
14201437
class FooConverter(string name) : IDataPropertyConverter
14211438
{
14221439
public object? Convert(ReadOnlyMemory<byte> data)

0 commit comments

Comments
 (0)