Skip to content

Commit

Permalink
fix disposed memory streams
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdgun committed Dec 30, 2023
1 parent 6261d9d commit e20c439
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAdapter> {amazonS3Adapter});

var getObjectResponse1 = Substitute.For<GetObjectResponse>();
var getObjectResponse2 = Substitute.For<GetObjectResponse>();
var getObjectResponse3 = Substitute.For<GetObjectResponse>();

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<FileNotFoundException>(() => fileSystem.ReadFileAsync("prefix-1://test2.txt"));
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.ReadFileAsync("prefix-1://test3.txt"));
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.ReadFileAsync("prefix-1://test4.txt"));
Expand Down Expand Up @@ -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<FileNotFoundException>(() => fileSystem.ReadFileAsync("prefix-1://test2.txt"));
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.ReadFileAsync("prefix-1://test3.txt"));
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.ReadFileAsync("prefix-1://test4.txt"));
Expand Down

0 comments on commit e20c439

Please sign in to comment.