Skip to content

Commit 192815c

Browse files
committed
test: 提高代码覆盖率
1 parent b46f874 commit 192815c

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
7878
}
7979
else
8080
{
81-
SocketLogging.LogInformation($"{nameof(Parse)} failed. Can't convert value from {valueType} to {p.PropertyType}");
81+
SocketLogging.LogInformation($"{nameof(Parse)} failed. Can't convert value from {GetValueType(valueType)} to {p.PropertyType}");
8282
}
8383
}
8484
}
@@ -87,6 +87,8 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
8787
return ret;
8888
}
8989

90+
private static string GetValueType(Type? type) => type?.FullName ?? "NULL";
91+
9092
private DataPropertyConverterAttribute? GetPropertyConverterAttribute(PropertyInfo propertyInfo)
9193
{
9294
DataPropertyConverterAttribute? attr = null;

test/UnitTestTcpSocket/TcpSocketFactoryTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@ public async Task TryConvertTo_Ok()
675675
Assert.Equal([1, 2, 3, 4, 5], entity.Header);
676676
Assert.Equal([3, 4], entity.Body);
677677

678+
// null
679+
Assert.Equal((byte)0x0, entity.Value16);
680+
681+
// null
682+
Assert.Equal((byte)0x0, entity.Value17);
683+
678684
// byte
679685
Assert.Equal(0x1, entity.Value15);
680686

@@ -1426,6 +1432,12 @@ class MockEntity
14261432

14271433
[DataPropertyConverter(Type = typeof(byte), Offset = 0, Length = 1)]
14281434
public byte Value15 { get; set; }
1435+
1436+
[DataPropertyConverter(Type = typeof(byte), ConverterType = typeof(MockNullConverter), Offset = 0, Length = 1)]
1437+
public byte Value16 { get; set; }
1438+
1439+
[DataPropertyConverter(Type = typeof(byte[]), Offset = 0, Length = 1)]
1440+
public byte Value17 { get; set; }
14291441
}
14301442

14311443
class MockSocketDataConverter : DataConverter<MockEntity>
@@ -1444,6 +1456,14 @@ protected override bool Parse(ReadOnlyMemory<byte> data, MockEntity entity)
14441456
}
14451457
}
14461458

1459+
class MockNullConverter : IDataPropertyConverter
1460+
{
1461+
public object? Convert(ReadOnlyMemory<byte> data)
1462+
{
1463+
return null;
1464+
}
1465+
}
1466+
14471467
class FooConverter(string name) : IDataPropertyConverter
14481468
{
14491469
public object? Convert(ReadOnlyMemory<byte> data)

0 commit comments

Comments
 (0)