From e20c4395bbc73a6e5be96ec5a33be6d08e4dfea1 Mon Sep 17 00:00:00 2001 From: Mauro van der Gun Date: Fri, 29 Dec 2023 22:57:27 -0400 Subject: [PATCH] fix disposed memory streams --- .../AmazonS3AdapterTest.cs | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs b/Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs index ae41f01..0342332 100644 --- a/Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs +++ b/Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs @@ -404,31 +404,14 @@ public async Task Test_Read_File_Async() var amazonS3Adapter = new AmazonS3Adapter("prefix-1", "root-path-1", amazonS3Client, "bucket-1"); var fileSystem = new SharpGrip.FileSystem.FileSystem(new List {amazonS3Adapter}); - var getObjectResponse1 = Substitute.For(); - var getObjectResponse2 = Substitute.For(); - var getObjectResponse3 = Substitute.For(); - - getObjectResponse1.Key = "test1.txt"; - getObjectResponse1.ContentLength = 1; - getObjectResponse1.LastModified = new DateTime(1970, 1, 1); - - getObjectResponse2.Key = "test1.txt"; - getObjectResponse2.ContentLength = 1; - getObjectResponse2.LastModified = new DateTime(1970, 1, 1); - - getObjectResponse3.Key = "test1.txt"; - getObjectResponse3.ContentLength = 1; - getObjectResponse3.LastModified = new DateTime(1970, 1, 1); - getObjectResponse3.ResponseStream = new MemoryStream("test1"u8.ToArray()); - - amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test1.txt").Returns(getObjectResponse1, getObjectResponse2, getObjectResponse3); + amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test1.txt").Returns(GetObjectResponse("test1.txt"), GetObjectResponse("test1.txt"), GetObjectResponse("test1.txt")); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test2.txt").ThrowsAsync(noSuchKeyException); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test3.txt").ThrowsAsync(invalidAccessKeyIdException); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test4.txt").ThrowsAsync(invalidSecurityException); var fileContents = await fileSystem.ReadFileAsync("prefix-1://test1.txt"); - Assert.Equal("test1", Encoding.UTF8.GetString(fileContents)); + Assert.Equal("test1.txt", Encoding.UTF8.GetString(fileContents)); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test2.txt")); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test3.txt")); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test4.txt")); @@ -458,14 +441,14 @@ public async Task Test_Read_Text_File_Async() getObjectResponse3.LastModified = new DateTime(1970, 1, 1); getObjectResponse3.ResponseStream = new MemoryStream("test1"u8.ToArray()); - amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test1.txt").Returns(getObjectResponse1, getObjectResponse2, getObjectResponse3); + amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test1.txt").Returns(GetObjectResponse("test1.txt"), GetObjectResponse("test1.txt"), GetObjectResponse("test1.txt")); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test2.txt").ThrowsAsync(noSuchKeyException); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test3.txt").ThrowsAsync(invalidAccessKeyIdException); amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test4.txt").ThrowsAsync(invalidSecurityException); var fileContents = await fileSystem.ReadTextFileAsync("prefix-1://test1.txt"); - Assert.Equal("test1", fileContents); + Assert.Equal("test1.txt", fileContents); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test2.txt")); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test3.txt")); await Assert.ThrowsAsync(() => fileSystem.ReadFileAsync("prefix-1://test4.txt"));