Skip to content

Commit

Permalink
Formatting and fixed analyzer bug
Browse files Browse the repository at this point in the history
fixed "AD0001 Analyzer 'Microsoft.NetCore.Analyzers.Security.DoNotHardCodeEncryptionKey' threw an exception of type 'System.NotSupportedException'" issue thanks to https://david.gardiner.net.au/2016/08/error-ad0001-compiler-analyzer-threw.html
  • Loading branch information
rheone committed Oct 13, 2019
1 parent 9c4694d commit f3afeaf
Show file tree
Hide file tree
Showing 17 changed files with 520 additions and 517 deletions.
150 changes: 75 additions & 75 deletions src/Gulliver.Tests/ByteArrayUtilsTests.cs

Large diffs are not rendered by default.

116 changes: 58 additions & 58 deletions src/Gulliver.Tests/ByteArrayUtils_BigEndian_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public partial class ByteArrayUtilsTests

public static IEnumerable<object[]> TrySumBigEndian_Test_Values()
{
var deltas = new[] {long.MinValue, -255, -129, -127, -1, 0, 1, 127, 129, 255, long.MaxValue};
var uints = new uint[] {uint.MinValue, 1, 127, 129, 255, uint.MaxValue};
var deltas = new[] { long.MinValue, -255, -129, -127, -1, 0, 1, 127, 129, 255, long.MaxValue };
var uints = new uint[] { uint.MinValue, 1, 127, 129, 255, uint.MaxValue };

foreach (var delta in deltas)
{
Expand All @@ -39,15 +39,15 @@ public static IEnumerable<object[]> TrySumBigEndian_Test_Values()
if (delta < 0
&& input - delta < 0)
{
yield return new object[] {false, Array.Empty<byte>(), inputBytes, delta};
yield return new object[] { false, Array.Empty<byte>(), inputBytes, delta };
yield break;
}

var expectedBytes = delta < 0
? ByteArrayUtils.SubtractUnsignedBigEndian(inputBytes, deltaBytes)
: ByteArrayUtils.AddUnsignedBigEndian(inputBytes, deltaBytes);

yield return new object[] {true, expectedBytes, inputBytes, delta};
yield return new object[] { true, expectedBytes, inputBytes, delta };
}
}
}
Expand Down Expand Up @@ -114,10 +114,10 @@ IEnumerable<object[]> TestCases()
var leftBytesTrimmed = leftBytes.TrimBigEndianLeadingZeroBytes();
var rightBytesTrimmed = rightBytes.TrimBigEndianLeadingZeroBytes();

yield return new object[] {expected, leftBytes, rightBytes};
yield return new object[] {expected, leftBytesTrimmed, rightBytes};
yield return new object[] {expected, leftBytes, rightBytesTrimmed};
yield return new object[] {expected, leftBytesTrimmed, rightBytesTrimmed};
yield return new object[] { expected, leftBytes, rightBytes };
yield return new object[] { expected, leftBytesTrimmed, rightBytes };
yield return new object[] { expected, leftBytes, rightBytesTrimmed };
yield return new object[] { expected, leftBytesTrimmed, rightBytesTrimmed };
}
}
}
Expand All @@ -143,8 +143,8 @@ public void AddUnsignedBigEndian_Test(byte[] expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void AddUnsignedBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand Down Expand Up @@ -194,10 +194,10 @@ IEnumerable<object[]> TestCases()
var leftBytesTrimmed = leftBytes.TrimBigEndianLeadingZeroBytes();
var rightBytesTrimmed = rightBytes.TrimBigEndianLeadingZeroBytes();

yield return new object[] {expected, leftBytes, rightBytes};
yield return new object[] {expected, leftBytesTrimmed, rightBytes};
yield return new object[] {expected, leftBytes, rightBytesTrimmed};
yield return new object[] {expected, leftBytesTrimmed, rightBytesTrimmed};
yield return new object[] { expected, leftBytes, rightBytes };
yield return new object[] { expected, leftBytesTrimmed, rightBytes };
yield return new object[] { expected, leftBytes, rightBytesTrimmed };
yield return new object[] { expected, leftBytesTrimmed, rightBytesTrimmed };
}
}
}
Expand All @@ -223,8 +223,8 @@ public void SubtractUnsignedBigEndian_Test(byte[] expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void SubtractUnsignedBigEndian_NullInput_Throws_ArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand All @@ -238,8 +238,8 @@ public void SubtractUnsignedBigEndian_NullInput_Throws_ArgumentNullException_Tes
public void SubtractUnsignedBigEndian_SignedOperation_Throws_InvalidOperationException_Test()
{
// Arrange
var left = new byte[] {0x00};
var right = new byte[] {0x00, 0x0F};
var left = new byte[] { 0x00 };
var right = new byte[] { 0x00, 0x0F };

// Act
// Assert
Expand Down Expand Up @@ -281,10 +281,10 @@ IEnumerable<object[]> TestCases()

var expected = (left ?? 0).CompareTo(right ?? 0);

yield return new object[] {expected, leftBytes, rightBytes};
yield return new object[] {expected, leftBytesTrimmed, rightBytes};
yield return new object[] {expected, leftBytes, rightBytesTrimmed};
yield return new object[] {expected, leftBytesTrimmed, rightBytesTrimmed};
yield return new object[] { expected, leftBytes, rightBytes };
yield return new object[] { expected, leftBytesTrimmed, rightBytes };
yield return new object[] { expected, leftBytes, rightBytesTrimmed };
yield return new object[] { expected, leftBytesTrimmed, rightBytesTrimmed };
}
}
}
Expand All @@ -310,8 +310,8 @@ public void CompareUnsignedBigEndian_Test(int expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void CompareUnsignedBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand All @@ -327,12 +327,12 @@ public void CompareUnsignedBigEndian_NullInput_ThrowsArgumentNullException_Test(

[Theory]
[InlineData(0, new byte[] { })]
[InlineData(1, new byte[] {0xff})]
[InlineData(1, new byte[] {0x00, 0xff})]
[InlineData(2, new byte[] {0x00, 0xff, 0xff})]
[InlineData(2, new byte[] {0xff, 0xff})]
[InlineData(3, new byte[] {0xff, 0xff, 0x00})]
[InlineData(3, new byte[] {0x00, 0xff, 0xff, 0x00})]
[InlineData(1, new byte[] { 0xff })]
[InlineData(1, new byte[] { 0x00, 0xff })]
[InlineData(2, new byte[] { 0x00, 0xff, 0xff })]
[InlineData(2, new byte[] { 0xff, 0xff })]
[InlineData(3, new byte[] { 0xff, 0xff, 0x00 })]
[InlineData(3, new byte[] { 0x00, 0xff, 0xff, 0x00 })]
public void BigEndianEffectiveLength_Test(int expected,
byte[] input)
{
Expand All @@ -352,7 +352,7 @@ public void BigEndianEffectiveLength_NullInput_ThrowsArgumentNullException_Test(
// Act
// Assert
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => ((byte[]) null).BigEndianEffectiveLength());
Assert.Throws<ArgumentNullException>(() => ((byte[])null).BigEndianEffectiveLength());
}

#endregion
Expand Down Expand Up @@ -452,8 +452,8 @@ public void BitwiseAndBigEndian_Test(byte[] expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void BitwiseAndBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand Down Expand Up @@ -558,8 +558,8 @@ public void BitwiseOrBigEndian_Test(byte[] expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void BitwiseOrBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand Down Expand Up @@ -664,8 +664,8 @@ public void BitwiseXorBigEndian_Test(byte[] expected,
}

[Theory]
[InlineData(null, new byte[] {0x00})]
[InlineData(new byte[] {0x00}, null)]
[InlineData(null, new byte[] { 0x00 })]
[InlineData(new byte[] { 0x00 }, null)]
public void BitwiseXorBigEndian_NullInput_ThrowsArgumentNullException_Test(byte[] left,
byte[] right)
{
Expand All @@ -689,37 +689,37 @@ public static IEnumerable<object[]> TrimBigEndianLeadingZeros_Test_Values()
var expected = Array.Empty<byte>();

var input = Enumerable.Range(0, i)
.Select(_ => (byte) 0x00)
.Select(_ => (byte)0x00)
.Concat(expected.ToList())
.ToArray();

yield return new object[] {expected, input};
yield return new object[] { expected, input };
}

// trim left
for (var i = 0; i < 5; i++)
{
var expected = new byte[] {0x0A, 0xF0};
var expected = new byte[] { 0x0A, 0xF0 };

var input = Enumerable.Range(0, i)
.Select(_ => (byte) 0x00)
.Select(_ => (byte)0x00)
.Concat(expected.ToList())
.ToArray();

yield return new object[] {expected, input};
yield return new object[] { expected, input };
}

// don't trim right
for (var i = 0; i < 5; i++)
{
var expected = new byte[] {0x0A, 0xF0, 0x00};
var expected = new byte[] { 0x0A, 0xF0, 0x00 };

var input = Enumerable.Range(0, i)
.Select(_ => (byte) 0x00)
.Select(_ => (byte)0x00)
.Concat(expected.ToList())
.ToArray();

yield return new object[] {expected, input};
yield return new object[] { expected, input };
}
}

Expand All @@ -743,7 +743,7 @@ public void TrimBigEndianLeadingZeros_Test(byte[] expected,
public void TrimBigEndianLeadingZeros_NullInput_ThrowsArgumentNullException_Test()
{
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => ((byte[]) null).TrimBigEndianLeadingZeroBytes());
Assert.Throws<ArgumentNullException>(() => ((byte[])null).TrimBigEndianLeadingZeroBytes());
}

#endregion
Expand All @@ -753,25 +753,25 @@ public void TrimBigEndianLeadingZeros_NullInput_ThrowsArgumentNullException_Test
public static IEnumerable<object[]> PadBigEndianMostSignificantBytes_Test_Vales()
{
// no padding, not padded
yield return new object[] { Array.Empty<byte>(), Array.Empty<byte>(), 0, 0x00};
yield return new object[] {new byte[] {0xfc}, new byte[] {0xfc}, 0, 0x00};
yield return new object[] { Array.Empty<byte>(), Array.Empty<byte>(), 0, 0x00 };
yield return new object[] { new byte[] { 0xfc }, new byte[] { 0xfc }, 0, 0x00 };

// input length equal to final length, not padded
yield return new object[] {new byte[] {0x00, 0x00}, new byte[] {0x00, 0x00}, 2, 0x00};
yield return new object[] {new byte[] {0x00, 0x00}, new byte[] {0x00, 0x00}, 2, 0xfc};
yield return new object[] { new byte[] { 0x00, 0x00 }, new byte[] { 0x00, 0x00 }, 2, 0x00 };
yield return new object[] { new byte[] { 0x00, 0x00 }, new byte[] { 0x00, 0x00 }, 2, 0xfc };

// input length greater than final length, not padded
yield return new object[] {new byte[] {0x00, 0x00}, new byte[] {0x00, 0x00}, 1, 0x00};
yield return new object[] {new byte[] {0xfc, 0xac}, new byte[] {0xfc, 0xac}, 1, 0xfc};
yield return new object[] { new byte[] { 0x00, 0x00 }, new byte[] { 0x00, 0x00 }, 1, 0x00 };
yield return new object[] { new byte[] { 0xfc, 0xac }, new byte[] { 0xfc, 0xac }, 1, 0xfc };

// empty input, padded
yield return new object[] {new byte[] {0x00, 0x00}, Array.Empty<byte>(), 2, 0x00};
yield return new object[] {new byte[] {0xfc, 0xfc}, Array.Empty<byte>(), 2, 0xfc};
yield return new object[] { new byte[] { 0x00, 0x00 }, Array.Empty<byte>(), 2, 0x00 };
yield return new object[] { new byte[] { 0xfc, 0xfc }, Array.Empty<byte>(), 2, 0xfc };

// input length less than final length, padded
yield return new object[] {new byte[] {0x00, 0x00, 0x00, 0x00}, new byte[] {0x00, 0x00}, 4, 0x00};
yield return new object[] {new byte[] {0xfc, 0xfc, 0x00, 0x00}, new byte[] {0x00, 0x00}, 4, 0xfc};
yield return new object[] {new byte[] {0xfc, 0xfc, 0xac, 0xac}, new byte[] {0xac, 0xac}, 4, 0xfc};
yield return new object[] { new byte[] { 0x00, 0x00, 0x00, 0x00 }, new byte[] { 0x00, 0x00 }, 4, 0x00 };
yield return new object[] { new byte[] { 0xfc, 0xfc, 0x00, 0x00 }, new byte[] { 0x00, 0x00 }, 4, 0xfc };
yield return new object[] { new byte[] { 0xfc, 0xfc, 0xac, 0xac }, new byte[] { 0xac, 0xac }, 4, 0xfc };
}

[Theory]
Expand All @@ -798,7 +798,7 @@ public void PadBigEndianMostSignificantBytes_NullSource_Throws_ArgumentNullExcep
// Act
// Assert
// ReSharper disable once AssignNullToNotNullAttribute
Assert.Throws<ArgumentNullException>(() => ((byte[]) null).PadBigEndianMostSignificantBytes(42));
Assert.Throws<ArgumentNullException>(() => ((byte[])null).PadBigEndianMostSignificantBytes(42));
}

[Fact]
Expand Down
Loading

0 comments on commit f3afeaf

Please sign in to comment.