Using native Convert from hex function for .NET 8
This commit is contained in:
@@ -8,6 +8,19 @@ namespace AMWD.Common.Tests.Extensions
|
||||
[TestClass]
|
||||
public class StringExtensionsTest
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ShouldThrowArgumentNullExceptionWhenNull()
|
||||
{
|
||||
// arrange
|
||||
string hex = null;
|
||||
|
||||
// act
|
||||
var bytes = hex.HexToBytes();
|
||||
|
||||
// assert - ArgumentNullException
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnEmptyList()
|
||||
{
|
||||
@@ -22,28 +35,19 @@ namespace AMWD.Common.Tests.Extensions
|
||||
Assert.IsFalse(bytes.Any());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ShouldReturnEmptyListWhenInvalid()
|
||||
[DataTestMethod]
|
||||
[DataRow("aff", null)]
|
||||
[DataRow("de:ad:be:e", ":")]
|
||||
[DataRow("hell", "")]
|
||||
[ExpectedException(typeof(FormatException))]
|
||||
public void ShouldThrowFormatExceptionWhenInvalid(string hex, string delimiter)
|
||||
{
|
||||
// arrange
|
||||
string hex1 = "aff";
|
||||
string hex2 = "de:ad:be:e";
|
||||
string hex3 = "hell";
|
||||
|
||||
// act
|
||||
var bytes1 = hex1.HexToBytes();
|
||||
var bytes2 = hex2.HexToBytes(":");
|
||||
var bytes3 = hex3.HexToBytes();
|
||||
var bytes = hex.HexToBytes(delimiter);
|
||||
|
||||
// assert
|
||||
Assert.IsNotNull(bytes1);
|
||||
Assert.IsFalse(bytes1.Any());
|
||||
|
||||
Assert.IsNotNull(bytes2);
|
||||
Assert.IsFalse(bytes2.Any());
|
||||
|
||||
Assert.IsNotNull(bytes3);
|
||||
Assert.IsFalse(bytes3.Any());
|
||||
// assert - FormatException
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
Reference in New Issue
Block a user