Skip to content

Commit e23d095

Browse files
committed
test: 更新单元测试
1 parent 76f2b86 commit e23d095

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

test/UnitTestTcpSocket/BinConverterTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ namespace UnitTestTcpSocket;
88

99
public class BinConverterTest
1010
{
11+
[Fact]
12+
public void ToHexString_Null()
13+
{
14+
var actual = BinConverter.ToString(null);
15+
Assert.Equal(string.Empty, actual);
16+
17+
actual = BinConverter.ToString([]);
18+
Assert.Equal(string.Empty, actual);
19+
}
20+
1121
[Fact]
1222
public void ToBinString_Ok()
1323
{
@@ -19,6 +29,14 @@ public void ToBinString_Ok()
1929
Assert.Equal("00011010 00000010", actual);
2030
}
2131

32+
[Fact]
33+
public void ToHexString_Exception()
34+
{
35+
var data = "00011010-00000010";
36+
var ex = Assert.ThrowsAny<ArgumentException>(() => BinConverter.ToBytes(data));
37+
Assert.NotNull(ex);
38+
}
39+
2240
[Fact]
2341
public void ToBytes_Ok()
2442
{

test/UnitTestTcpSocket/HexConverterTest.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
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

@@ -8,6 +8,24 @@ namespace UnitTestTcpSocket;
88

99
public class HexConverterTest
1010
{
11+
[Fact]
12+
public void ToHexString_Null()
13+
{
14+
var actual = HexConverter.ToString(null);
15+
Assert.Equal(string.Empty, actual);
16+
17+
actual = HexConverter.ToString([]);
18+
Assert.Equal(string.Empty, actual);
19+
}
20+
21+
[Fact]
22+
public void ToHexString_Exception()
23+
{
24+
var data = "1A021304FE1";
25+
var ex = Assert.ThrowsAny<ArgumentException>(() => HexConverter.ToBytes(data));
26+
Assert.NotNull(ex);
27+
}
28+
1129
[Fact]
1230
public void ToHexString_Ok()
1331
{

0 commit comments

Comments
 (0)