Skip to content

Commit ef43651

Browse files
committed
test: 增加单元测试
1 parent f4bd614 commit ef43651

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
// Website: https://www.blazor.zone or https://argozhang.github.io/
4+
5+
using BootstrapBlazor.Components.DataConverter;
6+
7+
namespace UnitTestTcpSocket;
8+
9+
public class ExtensionsTest
10+
{
11+
[Fact]
12+
public void ToHexString_Ok()
13+
{
14+
var data = new byte[] { 0x1A, 0x02, 0x13, 0x04, 0xFE };
15+
var actual = HexConverter.ToString(data);
16+
Assert.Equal("1A-02-13-04-FE", actual);
17+
18+
actual = HexConverter.ToString(data, " ");
19+
Assert.Equal("1A 02 13 04 FE", actual);
20+
}
21+
22+
[Fact]
23+
public void ToByte_Ok()
24+
{
25+
var excepted = new byte[] { 0x1A, 0x02, 0x13, 0x04, 0xFE };
26+
27+
var data = "1A021304FE";
28+
var actual = HexConverter.ToByte(data);
29+
Assert.Equal(excepted, actual);
30+
31+
data = "1A-02-13-04-FE";
32+
actual = HexConverter.ToByte(data, "-");
33+
Assert.Equal(excepted, actual);
34+
35+
data = "1A 02 13 04 FE";
36+
actual = HexConverter.ToByte(data, " ");
37+
Assert.Equal(excepted, actual);
38+
}
39+
}

0 commit comments

Comments
 (0)