-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathHexConverterTest.cs
More file actions
57 lines (46 loc) · 1.61 KB
/
HexConverterTest.cs
File metadata and controls
57 lines (46 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
using BootstrapBlazor.Components.DataConverter;
namespace UnitTestTcpSocket;
public class HexConverterTest
{
[Fact]
public void ToHexString_Null()
{
var actual = HexConverter.ToString(null);
Assert.Equal(string.Empty, actual);
actual = HexConverter.ToString([]);
Assert.Equal(string.Empty, actual);
}
[Fact]
public void ToHexString_Exception()
{
var data = "1A021304FE1";
var ex = Assert.ThrowsAny<ArgumentException>(() => HexConverter.ToBytes(data));
Assert.NotNull(ex);
}
[Fact]
public void ToHexString_Ok()
{
var data = new byte[] { 0x1A, 0x02, 0x13, 0x04, 0xFE };
var actual = HexConverter.ToString(data);
Assert.Equal("1A-02-13-04-FE", actual);
actual = HexConverter.ToString(data, " ");
Assert.Equal("1A 02 13 04 FE", actual);
}
[Fact]
public void ToBytes_Ok()
{
var excepted = new byte[] { 0x1A, 0x02, 0x13, 0x04, 0xFE };
var data = "1A021304FE";
var actual = HexConverter.ToBytes(data);
Assert.Equal(excepted, actual);
data = "1A-02-13-04-FE";
actual = HexConverter.ToBytes(data, "-");
Assert.Equal(excepted, actual);
data = "1A 02 13 04 FE";
actual = HexConverter.ToBytes(data, " ");
Assert.Equal(excepted, actual);
}
}