Fix bad serials (#304)

- [X] Fixes bad serial calculations
- [X] Tightens HexStrings

Bumps release version
Updates documentation
This commit is contained in:
Kamron Batman 2020-11-08 12:09:26 -08:00 • committed by GitHub
parent b0c1076cb5
commit ae436cb55f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 76 additions and 51 deletions

View file

@ -0,0 +1,15 @@
using System;
using System.Text;
namespace Server.Tests
{
public static class AssertThat
{
// TODO: Swap actual and expected to match Assert
public static void Equal(ReadOnlySpan<byte> actual, ReadOnlySpan<byte> expected) =>
Xunit.Assert.True(
expected.SequenceEqual(actual),
$"Expected does not match actual.\nExpected:\t{expected.ToDelimitedHexString()}\nActual:\t\t{actual.ToDelimitedHexString()}"
);
}
}

View file

@ -0,0 +1,26 @@
using System;
using Xunit;
namespace Server.Tests.Accounting
{
public class HexStringConverterTest
{
[Theory]
[InlineData("ABCDEF1234", new byte[] { 0xAB, 0xCD, 0xEF, 0x12, 0x34 })]
public void TestGetBytes(string input, byte[] bytes)
{
Span<byte> outputBytes = stackalloc byte[input.Length / 2];
HexStringConverter.GetBytes(input, outputBytes);
Assert.Equal(bytes, outputBytes.ToArray());
Assert.Equal(input, bytes.ToHexString());
}
[Theory]
[InlineData("[AB, CD, EF, 12, 34]", new byte[] { 0xAB, 0xCD, 0xEF, 0x12, 0x34 })]
public void TestsGetStringDelimited(string expected, byte[] bytes)
{
Assert.Equal(expected, bytes.ToDelimitedHexString());
}
}
}

View file

@ -1,24 +0,0 @@
using System;
using System.Text;
namespace Server.Tests
{
public static class AssertThat
{
public static string SpanToString(ReadOnlySpan<byte> bytes)
{
var builder = new StringBuilder();
builder.Append("[");
builder.AppendJoin(", ", bytes.ToArray());
builder.Append("]");
return builder.ToString();
}
public static void Equal(ReadOnlySpan<byte> actual, ReadOnlySpan<byte> expected) =>
Xunit.Assert.True(
expected.SequenceEqual(actual),
$"Expected does not match actual.\nExpected:\t{SpanToString(expected)}\nActual:\t\t{SpanToString(actual)}"
);
}
}