tests/DotNetCommon.Test/BytesToHexConverterTests.cs
(完整代码) 1KBnamespace DotNetCommon.Test
{
using System;
using NUnit.Framework;
using Shouldly;
using BytesToHexConverter = DotNetCommon.BytesToHexConverter;
[TestFixture]
internal sealed class BytesToHexConverterTests
{
[Test]
public void When_converting_bytes()
{
var bytes = new byte[] { 37, 80, 68, 70 };
var hex = BytesToHexConverter.ToHex(bytes);
hex.ShouldBe("25504446");
}
[Test]
public void When_converting_hex()
{
const string Hex = "25504446";
var bytes = BytesToHexConverter.FromHex(Hex);
bytes.ShouldBe(new byte[] { 37, 80, 68, 70 });
}
[Test]
public void When_converting_empty_bytes()
{
BytesToHexConverter.ToHex(new byte[0])
.ShouldBe(string.Empty);
}
[Test]
public void When_converting_empty_hex()
{
BytesToHexConverter.FromHex(string.Empty)
.ShouldBe(new byte[0]);
}
[Test]
public void When_converting_null_bytes()
{
Should.Throw<ArgumentNullException>(() => BytesToHexConverter.ToHex(null));
}
[Test]
public void When_converting_null_hex()
{
Should.Throw<ArgumentNullException>(() => BytesToHexConverter.FromHex(null));
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
