minor refactoring and tests
This commit is contained in:
@@ -7,7 +7,7 @@ public class Decode
|
||||
[InlineData(554121)]
|
||||
[InlineData(100454567)]
|
||||
[InlineData(3210589)]
|
||||
public void WhenEncodedToString_ShouldBeDecodedToTheSameByteArray(int seed)
|
||||
public void WhenBytesEncodedToString_ShouldBeDecodedToTheSameByteArray(int seed)
|
||||
{
|
||||
var rng = new Random(seed);
|
||||
|
||||
@@ -23,6 +23,43 @@ public class Decode
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(72121)]
|
||||
[InlineData(554121)]
|
||||
[InlineData(100454567)]
|
||||
[InlineData(3210589)]
|
||||
public void WhenLongEncodedToString_ShouldBeDecodedToTheSameLongArray(int seed)
|
||||
{
|
||||
var rng = new Random(seed);
|
||||
|
||||
for (int i = 1; i <= 512; i++)
|
||||
{
|
||||
var testLong = rng.NextInt64();
|
||||
|
||||
var resultString = Base64Url.Encode(testLong);
|
||||
var resultLong = Base64Url.DecodeLong(resultString);
|
||||
|
||||
resultLong.Should().Be(testLong);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("RgGxr0_n1ZI", -7866126844696657594L)]
|
||||
[InlineData("sxAPfpKB5kY", 5108913293478531251L)]
|
||||
[InlineData("lO4_uitvLCg", 2894810894091415188L)]
|
||||
[InlineData("awxjIqZWz10", 6759716837247880299L)]
|
||||
[InlineData("VjNe72vug4U", -8825948697371200682L)]
|
||||
[InlineData("AAAAAAAAAAA", 0L)]
|
||||
[InlineData("__________8", -1L)]
|
||||
[InlineData("AQAAAAAAAAA", 1L)]
|
||||
[InlineData("CgAAAAAAAAA", 10L)]
|
||||
[InlineData("6AMAAAAAAAA", 1000L)]
|
||||
public void WhenCalled_ShouldReturnValidLong(string testString, long expected)
|
||||
{
|
||||
var result = Base64Url.DecodeLong(testString);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("5QrdUxDUVkCAEGw8pvLsEw", "53dd0ae5-d410-4056-8010-6c3ca6f2ec13")]
|
||||
[InlineData("6nE2uKQ4_0ar9kpmybgkdw", "b83671ea-38a4-46ff-abf6-4a66c9b82477")]
|
||||
@@ -75,10 +112,23 @@ public class Decode
|
||||
action.Should().Throw<FormatException>();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("RgG&r0_n1ZI")]
|
||||
[InlineData("sxA fpKB5kY")]
|
||||
[InlineData("lO4_uitvL)g")]
|
||||
[InlineData("awxjIqZ^z10")]
|
||||
[InlineData("VjNe7!vug4U")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1806:Do not ignore method results", Justification = "Test case")]
|
||||
public void WhenCalledWithInvalidLongString_ShouldThrowFormatException(string testString)
|
||||
{
|
||||
Action action = () => Base64Url.DecodeLong(testString);
|
||||
action.Should().Throw<FormatException>();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void WhenCalledWithNullString_ShouldReturnEmptyArray(string testString)
|
||||
public void WhenCalledWithNullString_ShouldReturnEmptyArray(string? testString)
|
||||
{
|
||||
Base64Url.Decode(testString).Should().BeEmpty();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,23 @@ public class Encode
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("RgGxr0_n1ZI", -7866126844696657594L)]
|
||||
[InlineData("sxAPfpKB5kY", 5108913293478531251L)]
|
||||
[InlineData("lO4_uitvLCg", 2894810894091415188L)]
|
||||
[InlineData("awxjIqZWz10", 6759716837247880299L)]
|
||||
[InlineData("VjNe72vug4U", -8825948697371200682L)]
|
||||
[InlineData("AAAAAAAAAAA", 0L)]
|
||||
[InlineData("__________8", -1L)]
|
||||
[InlineData("AQAAAAAAAAA", 1L)]
|
||||
[InlineData("CgAAAAAAAAA", 10L)]
|
||||
[InlineData("6AMAAAAAAAA", 1000L)]
|
||||
public void WhenCalledWithLong_ShouldReturnValidString(string expected, long testLong)
|
||||
{
|
||||
var result = Base64Url.Encode(testLong);
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("IA", new byte[]{ 0x20, })]
|
||||
[InlineData("Ag", new byte[]{ 0x02, })]
|
||||
@@ -33,7 +50,7 @@ public class Encode
|
||||
[Theory]
|
||||
[InlineData(new byte[] { })]
|
||||
[InlineData(null)]
|
||||
public void WhenCalledWithEmptyByteArray_ShouldReturnEmptyString(byte[] testArray)
|
||||
public void WhenCalledWithEmptyByteArray_ShouldReturnEmptyString(byte[]? testArray)
|
||||
{
|
||||
var actualBase32 = Base64Url.Encode(testArray);
|
||||
actualBase32.Should().Be(string.Empty);
|
||||
@@ -42,7 +59,7 @@ public class Encode
|
||||
[Theory]
|
||||
[InlineData(new byte[] { })]
|
||||
[InlineData(null)]
|
||||
public void WhenCalledWithEmptyByteArray_ShouldReturnZeroAndNotChangeOutput(byte[] testArray)
|
||||
public void WhenCalledWithEmptyByteArray_ShouldReturnZeroAndNotChangeOutput(byte[]? testArray)
|
||||
{
|
||||
char[] output = ['1', '2', '3', '4'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user