diff options
Diffstat (limited to 'src/Http/WebUtilities/test/WebEncodersTests.cs')
-rw-r--r-- | src/Http/WebUtilities/test/WebEncodersTests.cs | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/src/Http/WebUtilities/test/WebEncodersTests.cs b/src/Http/WebUtilities/test/WebEncodersTests.cs index e619c3d597..e261c54aa9 100644 --- a/src/Http/WebUtilities/test/WebEncodersTests.cs +++ b/src/Http/WebUtilities/test/WebEncodersTests.cs @@ -4,61 +4,60 @@ using System; using Xunit; -namespace Microsoft.AspNetCore.WebUtilities +namespace Microsoft.AspNetCore.WebUtilities; + +public class WebEncodersTests { - public class WebEncodersTests - { - [Theory] - [InlineData("", 1, 0)] - [InlineData("", 0, 1)] - [InlineData("0123456789", 9, 2)] - [InlineData("0123456789", Int32.MaxValue, 2)] - [InlineData("0123456789", 9, -1)] - public void Base64UrlDecode_BadOffsets(string input, int offset, int count) + [Theory] + [InlineData("", 1, 0)] + [InlineData("", 0, 1)] + [InlineData("0123456789", 9, 2)] + [InlineData("0123456789", Int32.MaxValue, 2)] + [InlineData("0123456789", 9, -1)] + public void Base64UrlDecode_BadOffsets(string input, int offset, int count) + { + // Act & assert + Assert.ThrowsAny<ArgumentException>(() => { - // Act & assert - Assert.ThrowsAny<ArgumentException>(() => - { - var retVal = WebEncoders.Base64UrlDecode(input, offset, count); - }); - } + var retVal = WebEncoders.Base64UrlDecode(input, offset, count); + }); + } - [Theory] - [InlineData(0, 1, 0)] - [InlineData(0, 0, 1)] - [InlineData(10, 9, 2)] - [InlineData(10, Int32.MaxValue, 2)] - [InlineData(10, 9, -1)] - public void Base64UrlEncode_BadOffsets(int inputLength, int offset, int count) - { - // Arrange - byte[] input = new byte[inputLength]; + [Theory] + [InlineData(0, 1, 0)] + [InlineData(0, 0, 1)] + [InlineData(10, 9, 2)] + [InlineData(10, Int32.MaxValue, 2)] + [InlineData(10, 9, -1)] + public void Base64UrlEncode_BadOffsets(int inputLength, int offset, int count) + { + // Arrange + byte[] input = new byte[inputLength]; - // Act & assert - Assert.ThrowsAny<ArgumentException>(() => - { - var retVal = WebEncoders.Base64UrlEncode(input, offset, count); - }); - } + // Act & assert + Assert.ThrowsAny<ArgumentException>(() => + { + var retVal = WebEncoders.Base64UrlEncode(input, offset, count); + }); + } - [Fact] - public void DataOfVariousLengthRoundTripCorrectly() + [Fact] + public void DataOfVariousLengthRoundTripCorrectly() + { + for (int length = 0; length != 256; ++length) { - for (int length = 0; length != 256; ++length) + var data = new byte[length]; + for (int index = 0; index != length; ++index) { - var data = new byte[length]; - for (int index = 0; index != length; ++index) - { - data[index] = (byte)(5 + length + (index * 23)); - } - string text = WebEncoders.Base64UrlEncode(data); - byte[] result = WebEncoders.Base64UrlDecode(text); + data[index] = (byte)(5 + length + (index * 23)); + } + string text = WebEncoders.Base64UrlEncode(data); + byte[] result = WebEncoders.Base64UrlDecode(text); - for (int index = 0; index != length; ++index) - { - Assert.Equal(data[index], result[index]); - } + for (int index = 0; index != length; ++index) + { + Assert.Equal(data[index], result[index]); } } } |