added more tests
All checks were successful
.NET Test / test (push) Successful in 1m6s
.NET Publish / publish (push) Successful in 38s

This commit is contained in:
2024-08-15 22:00:49 +04:00
parent 43135a5ffb
commit 2b68ba982d
9 changed files with 206 additions and 7 deletions

View File

@@ -50,4 +50,36 @@ public class Decode
var result = Base64Url.Decode(testString);
result.Should().BeEquivalentTo(expected);
}
[Theory]
[InlineData(" ")]
[InlineData("hg2&515i3215")]
[InlineData("hg712)21")]
[InlineData("hg712f 21")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1806:Do not ignore method results", Justification = "Test case")]
public void WhenCalledWithInvalidString_ShouldThrowFormatException(string testString)
{
Action action = () => Base64Url.Decode(testString);
action.Should().Throw<FormatException>();
}
[Theory]
[InlineData("5QrdUxDUV CAEGw8pvLsEw")]
[InlineData("6nE2uKQ4$0ar9kpmybgkdw")]
[InlineData("PyD6zwDqXkG*S1HPsp41wQ")]
[InlineData("!dOlPOh3wEe9PlyQgTMt2g")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1806:Do not ignore method results", Justification = "Test case")]
public void WhenCalledWithInvalidGuidString_ShouldThrowFormatException(string testString)
{
Action action = () => Base64Url.DecodeGuid(testString);
action.Should().Throw<FormatException>();
}
[Theory]
[InlineData(null)]
[InlineData("")]
public void WhenCalledWithNullString_ShouldReturnEmptyArray(string testString)
{
Base64Url.Decode(testString).Should().BeEmpty();
}
}

View File

@@ -29,4 +29,26 @@ public class Encode
var result = Base64Url.Encode(testBytes);
result.Should().Be(expected);
}
[Theory]
[InlineData(new byte[] { })]
[InlineData(null)]
public void WhenCalledWithEmptyByteArray_ShouldReturnEmptyString(byte[] testArray)
{
var actualBase32 = Base64Url.Encode(testArray);
actualBase32.Should().Be(string.Empty);
}
[Theory]
[InlineData(new byte[] { })]
[InlineData(null)]
public void WhenCalledWithEmptyByteArray_ShouldReturnZeroAndNotChangeOutput(byte[] testArray)
{
char[] output = ['1', '2', '3', '4'];
var charsWritten = Base64Url.Encode(testArray, output);
charsWritten.Should().Be(0);
output.Should().Equal(['1', '2', '3', '4']);
}
}