diff --git a/src/Storage.Tests/ObjectShould.cs b/src/Storage.Tests/ObjectShould.cs index ffd4018..921886e 100644 --- a/src/Storage.Tests/ObjectShould.cs +++ b/src/Storage.Tests/ObjectShould.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; using static Storage.Tests.StorageFixture; namespace Storage.Tests; @@ -8,8 +8,8 @@ public sealed class ObjectShould : IClassFixture private readonly S3Client _client; private readonly CancellationToken _ct; private readonly StorageFixture _fixture; - private readonly S3Client _notExistsBucketClient; // don't dispose it - + private readonly S3Client _notExistsBucketClient; // don't dispose it + public ObjectShould(StorageFixture fixture) { _ct = CancellationToken.None; @@ -136,9 +136,9 @@ public async Task DisposeFileStream() public async Task DisposeStorageFile() { var fileName = await CreateTestFile(); - using var fileGetResult = await _client.GetFile(fileName, _ct); - - // ReSharper disable once DisposeOnUsingVariable + using var fileGetResult = await _client.GetFile(fileName, _ct); + + // ReSharper disable once DisposeOnUsingVariable fileGetResult.Dispose(); await DeleteTestFile(fileName); @@ -370,20 +370,20 @@ public async Task ReadFileStream() var buffer = new byte[1024]; var file = await _client.GetFile(fileName, _ct); - var fileStream = await file.GetStream(_ct); - + var fileStream = await file.GetStream(_ct); + #pragma warning disable CA1835 var read = await fileStream.ReadAsync(buffer, _ct); read.Should().BeGreaterThan(0); read = await fileStream.ReadAsync(buffer, 10, 20, _ct); - read.Should().BeGreaterThan(0); - - // ReSharper disable once MethodHasAsyncOverloadWithCancellation + read.Should().BeGreaterThan(0); + + // ReSharper disable once MethodHasAsyncOverloadWithCancellation read = fileStream.Read(buffer, 10, 20); - read.Should().BeGreaterThan(0); + read.Should().BeGreaterThan(0); #pragma warning restore CA1835 - + await DeleteTestFile(fileName); } @@ -391,7 +391,7 @@ public async Task ReadFileStream() public async Task Upload() { var fileName = _fixture.Create(); - using var data = GetByteStream(12 * 1024 * 1024); // 12 Mb + using var data = GetByteStream(12 * 1024 * 1024); // 12 Mb var filePutResult = await _client.UploadFile(fileName, StreamContentType, data, _ct); filePutResult @@ -505,8 +505,27 @@ await _notExistsBucketClient await _notExistsBucketClient .Invoking(client => client.UploadFile(fileName, StreamContentType, fileArray, _ct)) .Should().ThrowAsync(); + } + + [Theory] + [InlineData("some/foo/audio.wav", 1024)] + [InlineData("another/path/test.mp3", 2048)] + public async Task UploadFileWithNestedPath(string nestedFileName, int dataSize) + { + var data = GetByteArray(dataSize); // Пример данных, которые вы хотите загрузить + + // Act + var result = await _client.UploadFile(nestedFileName, StreamContentType, data, _ct); + Assert.True(result); + + // Assert + var exists = await _client.IsFileExists(nestedFileName, _ct); + Assert.True(exists, "The object should exist in the S3 bucket"); + + await DeleteTestFile(nestedFileName); } + [Fact] public async Task ThrowIfUploadDisposed() { @@ -534,8 +553,8 @@ private async Task CreateTestFile( int? size = null) { fileName ??= _fixture.Create(); - using var data = GetByteStream(size ?? 1 * 1024 * 1024); // 1 Mb - + using var data = GetByteStream(size ?? 1 * 1024 * 1024); // 1 Mb + var uploadResult = await _client.UploadFile(fileName, contentType, data, _ct); uploadResult @@ -570,8 +589,8 @@ private async Task EnsureFileSame(string fileName, MemoryStream expectedBytes) memoryStream .ToArray().SequenceEqual(expectedBytes.ToArray()) .Should().BeTrue(); - } - + } + private Task DeleteTestFile(string fileName) { return _client.DeleteFile(fileName, _ct); diff --git a/src/Storage/Utils/HttpDescription.cs b/src/Storage/Utils/HttpDescription.cs index 74d7b19..130b1ae 100644 --- a/src/Storage/Utils/HttpDescription.cs +++ b/src/Storage/Utils/HttpDescription.cs @@ -1,4 +1,4 @@ -using System.Buffers; +using System.Buffers; using System.Collections.Frozen; using System.Text; @@ -7,7 +7,7 @@ namespace Storage.Utils; internal readonly struct HttpDescription { private static readonly FrozenSet _validUrlCharacters = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~".ToFrozenSet(); + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~/".ToFrozenSet(); private readonly string _headerEnd; private readonly string _headerStart; diff --git a/src/Storage/Utils/ValueStringBuilder.cs b/src/Storage/Utils/ValueStringBuilder.cs index 96a6776..61027e6 100644 --- a/src/Storage/Utils/ValueStringBuilder.cs +++ b/src/Storage/Utils/ValueStringBuilder.cs @@ -1,11 +1,11 @@ -using System.Buffers; +using System.Buffers; using System.Globalization; namespace Storage.Utils; -internal ref struct ValueStringBuilder(Span buffer) +internal ref struct ValueStringBuilder(Span initialBuffer) { - private Span _buffer = buffer; + private Span _buffer = initialBuffer; private int _length = 0; private char[]? _array = null;