-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c10e696
commit ed17744
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
test/Atc.Tests/Extensions/BaseTypes/ByteExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// ReSharper disable AssignNullToNotNullAttribute | ||
// ReSharper disable StringLiteralTypo | ||
namespace Atc.Tests.Extensions.BaseTypes; | ||
|
||
public class ByteExtensionsTests | ||
{ | ||
[Fact] | ||
public void ToHex_NullByteArray() | ||
{ | ||
byte[] nullArray = null; | ||
|
||
Assert.Throws<ArgumentNullException>(() => nullArray.ToHex()); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_EmptyByteArray() | ||
{ | ||
var byteArray = Array.Empty<byte>(); | ||
|
||
var actual = byteArray.ToHex(); | ||
|
||
Assert.Equal(string.Empty, actual); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_WithoutSeparator() | ||
{ | ||
byte[] byteArray = { 0x12, 0x34, 0x56 }; | ||
|
||
var actual = byteArray.ToHex(); | ||
|
||
Assert.Equal("123456", actual); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_WithSeparator1() | ||
{ | ||
byte[] byteArray = { 0x12, 0x34, 0x56 }; | ||
|
||
var actual = byteArray.ToHex("-"); | ||
|
||
Assert.Equal("12-34-56", actual); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_WithSeparator2() | ||
{ | ||
byte[] byteArray = { 0x12, 0x34, 0x56 }; | ||
|
||
var actual = byteArray.ToHex(":"); | ||
|
||
Assert.Equal("12:34:56", actual); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_WithSeparatorAndHexSign1() | ||
{ | ||
byte[] byteArray = { 0x12, 0x34, 0x56 }; | ||
|
||
var actual = byteArray.ToHex(", ", showHexSign: true); | ||
|
||
Assert.Equal("0x12, 0x34, 0x56", actual); | ||
} | ||
|
||
[Fact] | ||
public void ToHex_WithSeparatorAndHexSign2() | ||
{ | ||
byte[] byteArray = { 0x12, 0x34, 0x56 }; | ||
|
||
var actual = byteArray.ToHex(" - ", showHexSign: true); | ||
|
||
Assert.Equal("0x12 - 0x34 - 0x56", actual); | ||
} | ||
} |