-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBinConverterTest.cs
More file actions
55 lines (45 loc) · 1.55 KB
/
BinConverterTest.cs
File metadata and controls
55 lines (45 loc) · 1.55 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
// 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/
namespace UnitTestTcpSocket;
public class BinConverterTest
{
[Fact]
public void ToHexString_Null()
{
var actual = BinConverter.ToString(null);
Assert.Equal(string.Empty, actual);
actual = BinConverter.ToString([]);
Assert.Equal(string.Empty, actual);
}
[Fact]
public void ToBinString_Ok()
{
var data = new byte[] { 0x1A, 0x02 };
var actual = BinConverter.ToString(data);
Assert.Equal("00011010-00000010", actual);
actual = BinConverter.ToString(data, " ");
Assert.Equal("00011010 00000010", actual);
}
[Fact]
public void ToHexString_Exception()
{
var data = "00011010-00000010";
var ex = Assert.ThrowsAny<ArgumentException>(() => BinConverter.ToBytes(data));
Assert.NotNull(ex);
}
[Fact]
public void ToBytes_Ok()
{
var excepted = new byte[] { 0x1A, 0x02 };
var data = "00011010-00000010";
var actual = BinConverter.ToBytes(data, "-");
Assert.Equal(excepted, actual);
data = "00011010 00000010";
actual = BinConverter.ToBytes(data, " ");
Assert.Equal(excepted, actual);
data = "0001101000000010";
actual = BinConverter.ToBytes(data);
Assert.Equal(excepted, actual);
}
}