Skip to content

Commit b63b191

Browse files
committed
Annotate Arrange/Act/Assert in unit tests
1 parent 16e83e3 commit b63b191

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AlwaysEncrypted/AeadAes256CbcHmac256EncryptionKeyTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ public class AeadAes256CbcHmac256EncryptionKeyTest
2222
[Fact]
2323
public void Constructor_ThrowsOnInvalidSize()
2424
{
25+
// Arrange
2526
byte[] invalidSizeRootKey = [0x01, 0x02, 0x03, 0x04];
27+
// Act
2628
Action createEncryptionKey = () => new AeadAes256CbcHmac256EncryptionKey(invalidSizeRootKey);
2729

30+
// Assert
2831
Assert.NotEqual(AeadAes256CbcHmac256EncryptionKey.KeySizeInBytes, invalidSizeRootKey.Length);
2932
Assert.Throws<ArgumentException>(createEncryptionKey);
3033
}
@@ -37,14 +40,17 @@ public void Constructor_ThrowsOnInvalidSize()
3740
[Fact]
3841
public void Constructor_SucceedsOnValidSize()
3942
{
43+
// Arrange
4044
byte[] validRootKey = [
4145
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
4246
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
4347
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
4448
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
4549
];
50+
// Act
4651
AeadAes256CbcHmac256EncryptionKey encryptionKey = new(validRootKey);
4752

53+
// Assert
4854
Assert.Equal(AeadAes256CbcHmac256EncryptionKey.KeySizeInBytes, encryptionKey.EncryptionKey.Length);
4955
Assert.Equal(AeadAes256CbcHmac256EncryptionKey.KeySizeInBytes, encryptionKey.MacKey.Length);
5056
Assert.Equal(AeadAes256CbcHmac256EncryptionKey.KeySizeInBytes, encryptionKey.IvKey.Length);

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AlwaysEncrypted/AeadAes256CbcHmac256FactoryTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ public class AeadAes256CbcHmac256FactoryTest
2121
[Fact]
2222
public void InvalidEncryptionType_Throws()
2323
{
24+
// Arrange
2425
byte[] dummySymmetricKeyMaterial = [0x00];
2526
SymmetricKey symmetricKey = new(dummySymmetricKeyMaterial);
27+
// Act
2628
Action createEncryptionAlgorithm = () =>
2729
AeadAes256CbcHmac256Factory.Instance.Create(symmetricKey, (EncryptionType)0xFF, SqlAeadAes256CbcHmac256Algorithm.AlgorithmName);
2830

31+
// Assert
2932
Assert.Throws<ArgumentException>(createEncryptionAlgorithm);
3033
}
3134

@@ -36,6 +39,7 @@ public void InvalidEncryptionType_Throws()
3639
[Fact]
3740
public void MultipleCreateCalls_ReturnCachedAlgorithm()
3841
{
42+
// Arrange
3943
byte[] validFirstRootKeyMaterial = [
4044
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
4145
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
@@ -51,10 +55,12 @@ public void MultipleCreateCalls_ReturnCachedAlgorithm()
5155
SymmetricKey firstRootKey = new(validFirstRootKeyMaterial);
5256
SymmetricKey secondRootKey = new(validSecondRootKeyMaterial);
5357

58+
// Act
5459
SqlClientEncryptionAlgorithm initialFirstAlgorithm = AeadAes256CbcHmac256Factory.Instance.Create(firstRootKey, EncryptionType.Deterministic, SqlAeadAes256CbcHmac256Algorithm.AlgorithmName);
5560
SqlClientEncryptionAlgorithm cachedFirstAlgorithm = AeadAes256CbcHmac256Factory.Instance.Create(firstRootKey, EncryptionType.Deterministic, SqlAeadAes256CbcHmac256Algorithm.AlgorithmName);
5661
SqlClientEncryptionAlgorithm initialSecondAlgorithm = AeadAes256CbcHmac256Factory.Instance.Create(secondRootKey, EncryptionType.Deterministic, SqlAeadAes256CbcHmac256Algorithm.AlgorithmName);
5762

63+
// Assert
5864
Assert.Equal(initialFirstAlgorithm, cachedFirstAlgorithm);
5965
Assert.NotEqual(initialFirstAlgorithm, initialSecondAlgorithm);
6066

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AlwaysEncrypted/EncryptionAlgorithmFactoryListTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ public void GetAlgorithmWithInvalidAlgorithm_Throws()
2222
{
2323
const string InvalidAlgorithmName = nameof(EncryptionAlgorithmFactoryListTest);
2424

25+
// Arrange
2526
byte[] dummySymmetricKeyMaterial = [0x00];
2627
SymmetricKey dummySymmetricKey = new(dummySymmetricKeyMaterial);
28+
// Act
2729
Action getAlgorithm = () => EncryptionAlgorithmFactoryList.GetAlgorithm(dummySymmetricKey, 0x01, InvalidAlgorithmName, out _);
2830

31+
// Assert
2932
ArgumentException thrownException = Assert.Throws<ArgumentException>(getAlgorithm);
3033

3134
Assert.Contains(InvalidAlgorithmName, thrownException.Message);

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AlwaysEncrypted/SymmetricKeyTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public class SymmetricKeyTest
2121
[Fact]
2222
public void Constructor_WrapsByteArray()
2323
{
24+
// Arrange
2425
byte[] dummySymmetricKeyMaterial = [0x00];
26+
// Act
2527
SymmetricKey symmetricKey = new(dummySymmetricKeyMaterial);
2628

29+
// Assert
2730
Assert.Same(dummySymmetricKeyMaterial, symmetricKey.RootKey);
2831
}
2932

@@ -34,9 +37,11 @@ public void Constructor_WrapsByteArray()
3437
[Fact]
3538
public void Constructor_ThrowsOnNullOrEmptyArray()
3639
{
40+
// Act
3741
Action createNullArray = () => new SymmetricKey(rootKey: null);
3842
Action createEmptyArray = () => new SymmetricKey(rootKey: []);
3943

44+
// Assert
4045
Assert.Throws<ArgumentNullException>(createNullArray);
4146
Assert.Throws<ArgumentNullException>(createEmptyArray);
4247
}

0 commit comments

Comments
 (0)