Skip to content

Commit 484c666

Browse files
authored
[Storage] Test Refactoring for OpenReadAsyncOverload_AllowModifications & OpenReadAsyncOverload_NotAllowModifications (Azure#45823)
* Refactored tests + recordings * Minor refactor
1 parent a315ab8 commit 484c666

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

sdk/storage/Azure.Storage.Blobs/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/storage/Azure.Storage.Blobs",
5-
"Tag": "net/storage/Azure.Storage.Blobs_66e593a51d"
5+
"Tag": "net/storage/Azure.Storage.Blobs_a4e8ca8040"
66
}

sdk/storage/Azure.Storage.Common/tests/Shared/OpenReadTestBase.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -662,25 +662,30 @@ public async Task OpenReadAsyncOverload_AllowModifications()
662662
// Arrange
663663
byte[] data0 = GetRandomBuffer(size);
664664
byte[] data1 = GetRandomBuffer(size);
665-
byte[] expectedData = new byte[2 * size];
666-
Array.Copy(data0, 0, expectedData, 0, size);
667-
Array.Copy(data1, 0, expectedData, size, size);
665+
byte[] expectedDataBeforeModify = new byte[size];
666+
byte[] expectedDataAfterModify = new byte[size];
667+
Array.Copy(data0, 0, expectedDataBeforeModify, 0, size);
668+
Array.Copy(data1, 0, expectedDataAfterModify, 0, size);
668669

669670
TResourceClient client = GetResourceClient(disposingContainer.Container);
670671
await StageDataAsync(client, new MemoryStream(data0));
671672

672673
// Act
673674
Stream outputStream = await OpenReadAsyncOverload(client, allowModifications: true);
674-
byte[] outputBytes = new byte[2 * size];
675-
await outputStream.ReadAsync(outputBytes, 0, size);
675+
byte[] outputBytesBeforeModify = new byte[size];
676+
await outputStream.ReadAsync(outputBytesBeforeModify, 0, size);
676677

677678
// Modify the blob.
678679
await ModifyDataAsync(client, new MemoryStream(data1), ModifyDataMode.Append);
679680

680-
await outputStream.ReadAsync(outputBytes, size, size);
681+
byte[] outputBytesAfterModify = new byte[size];
682+
byte[] emptyBytes = new byte[size];
683+
await outputStream.ReadAsync(outputBytesAfterModify, 0, size);
681684

682685
// Assert
683-
TestHelper.AssertSequenceEqual(expectedData, outputBytes);
686+
TestHelper.AssertSequenceEqual(expectedDataBeforeModify, outputBytesBeforeModify);
687+
TestHelper.AssertSequenceEqual(expectedDataAfterModify, outputBytesAfterModify);
688+
Assert.AreNotEqual(emptyBytes, outputBytesAfterModify);
684689
}
685690

686691
[RecordedTest]
@@ -692,25 +697,30 @@ public async Task OpenReadAsyncOverload_NotAllowModifications()
692697
// Arrange
693698
byte[] data0 = GetRandomBuffer(size);
694699
byte[] data1 = GetRandomBuffer(size);
695-
byte[] expectedData = new byte[2 * size];
696-
Array.Copy(data0, 0, expectedData, 0, size);
697-
Array.Copy(data1, 0, expectedData, size, size);
700+
byte[] expectedDataBeforeModify = new byte[size];
701+
byte[] expectedDataAfterModify = new byte[size];
702+
Array.Copy(data0, 0, expectedDataBeforeModify, 0, size);
703+
Array.Copy(data1, 0, expectedDataAfterModify, 0, size);
698704

699705
TResourceClient client = GetResourceClient(disposingContainer.Container);
700706
await StageDataAsync(client, new MemoryStream(data0));
701707

702708
// Act
703709
Stream outputStream = await OpenReadAsyncOverload(client, allowModifications: false);
704-
byte[] outputBytes = new byte[2 * size];
705-
await outputStream.ReadAsync(outputBytes, 0, size);
710+
byte[] outputBytesBeforeModify = new byte[size];
711+
await outputStream.ReadAsync(outputBytesBeforeModify, 0, size);
706712

707713
// Modify the blob.
708714
await ModifyDataAsync(client, new MemoryStream(data1), ModifyDataMode.Append);
709715

710-
await outputStream.ReadAsync(outputBytes, size, size);
716+
byte[] outputBytesAfterModify = new byte[size];
717+
byte[] emptyBytes = new byte[size];
718+
await outputStream.ReadAsync(outputBytesAfterModify, 0, size);
711719

712720
// Assert
713-
Assert.AreNotEqual(expectedData, outputBytes);
721+
TestHelper.AssertSequenceEqual(expectedDataBeforeModify, outputBytesBeforeModify);
722+
Assert.AreNotEqual(expectedDataAfterModify, outputBytesAfterModify);
723+
TestHelper.AssertSequenceEqual(emptyBytes, outputBytesAfterModify);
714724
}
715725
}
716726
}

sdk/storage/Azure.Storage.Files.DataLake/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/storage/Azure.Storage.Files.DataLake",
5-
"Tag": "net/storage/Azure.Storage.Files.DataLake_275c4dcbac"
5+
"Tag": "net/storage/Azure.Storage.Files.DataLake_c97d1635f5"
66
}

sdk/storage/Azure.Storage.Files.Shares/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/storage/Azure.Storage.Files.Shares",
5-
"Tag": "net/storage/Azure.Storage.Files.Shares_e7f070af73"
5+
"Tag": "net/storage/Azure.Storage.Files.Shares_772bdf674f"
66
}

0 commit comments

Comments
 (0)