public async Task DeleteDirectoryAsync_DoesNotThrowIfDirectoryDoesNotExist()
        {
            // Arrange
            var directoryName = AzureFileStorageTestHelper.CreateRandomString();

            // Act
            await _sut.DeleteDirectoryAsync(directoryName);
        }
        public async Task DeleteDirectoryAsync_SucceedsIfDirectoryExistsAndEmpty()
        {
            // Arrange
            var directoryName = AzureFileStorageTestHelper.CreateRandomString();
            await AzureFileStorageTestHelper.CreateTestDirectoryAsync(_fileShare, directoryName);

            // Act
            await _sut.DeleteDirectoryAsync(directoryName);

            // Assert
            Assert.False(await AzureFileStorageTestHelper.DirectoryExistsAsync(_fileShare, directoryName));
        }
        public async Task SaveFileAsync_SucceedsForFileInSubDirectory()
        {
            // Arrange
            var fileName = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());

            var contents = AzureFileStorageTestHelper.CreateRandomString();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
            {
                // Act
                await _sut.SaveFileAsync(fileName, stream);
            }
        }
        public async Task GetDirectoryContentsAsync_ReturnsFileList()
        {
            // Arrange
            var filesCount = AzureFileStorageTestHelper.CreateRandomNumber();

            await AzureFileStorageTestHelper.CreateTestFilesAsync(_fileShare, filesCount);

            // Act
            var result = await _sut.GetDirectoryContentsAsync(string.Empty);

            // Assert
            Assert.Equal(filesCount, result.Count());
        }
        public async Task DeleteFileAsync_CanDeleteFromSubDirectory()
        {
            // Arrange
            var fileName = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, fileName);

            // Act
            await _sut.DeleteFileAsync(fileName);

            // Assert
            Assert.False(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, fileName));
        }
        public async Task DeleteFileAsync_SucceedsIfFileExists()
        {
            // Arrange
            var fileName = Path.GetRandomFileName();

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, fileName);

            // Act
            await _sut.DeleteFileAsync(fileName);

            // Assert
            Assert.False(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, fileName));
        }
        public async Task CopyFileAsync_CanMoveAcrossSubDirectories()
        {
            // Arrange
            var source = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());
            var target = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, source);

            // Act
            await _sut.CopyFileAsync(source, target);

            // Assert
            Assert.True(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, source));
            Assert.True(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, target));
        }
        public async Task CopyFileAsync_SucceedsIfSourceFileExists()
        {
            // Arrange
            var source = Path.GetRandomFileName();
            var target = Path.GetRandomFileName();

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, source);

            // Act
            await _sut.CopyFileAsync(source, target);

            // Assert
            Assert.True(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, source));
            Assert.True(await AzureFileStorageTestHelper.ExistsAsync(_fileShare, target));
        }
        public async Task SaveFileAsync_SavesCorrectContent()
        {
            // Arrange
            var fileName = Path.GetRandomFileName();

            var expectedContents = AzureFileStorageTestHelper.CreateRandomString();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(expectedContents)))
            {
                // Act
                await _sut.SaveFileAsync(fileName, stream);
            }

            // Assert
            var actualContents = await AzureFileStorageTestHelper.ReadFileContents(_fileShare, fileName);

            Assert.Equal(expectedContents, actualContents);
        }
        public async Task GetDirectoryContentsAsync_ReturnsFileListForSubDirectory()
        {
            // Arrange
            var subpath = Path.GetRandomFileName();

            var filesCount = AzureFileStorageTestHelper.CreateRandomNumber();

            await AzureFileStorageTestHelper.CreateTestFilesAsync(
                _fileShare,
                filesCount,
                subpath);

            // Act
            var result = await _sut.GetDirectoryContentsAsync(subpath);

            // Assert
            Assert.Equal(filesCount, result.Count());
        }
        public async Task GetFileStreamAsync_ReturnsFileStreamForFileInSubDirectory()
        {
            // Arrange
            var fileName = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());

            var expectedContents = AzureFileStorageTestHelper.CreateRandomString();

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, fileName, expectedContents);

            // Act
            using (var stream = await _sut.GetFileStreamAsync(fileName))
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    var contents = reader.ReadToEnd();

                    // Assert
                    Assert.Equal(expectedContents, contents);
                }
        }
        public async Task GetFileInfoAsync_ReturnsFileInfoForFileInSubDirectory()
        {
            // Arrange
            var fileName = Path.Combine(Path.GetRandomFileName(), Path.GetRandomFileName());

            var expectedFileName = Path.GetFileName(fileName);
            var expectedFilePath = fileName;

            await AzureFileStorageTestHelper.CreateTestFileAsync(_fileShare, fileName);

            // Act
            var result = await _sut.GetFileInfoAsync(fileName);

            // Assert
            Assert.True(result.Exists);
            Assert.False(result.IsDirectory);
            Assert.Equal(expectedFileName, result.Name);
            Assert.Equal(expectedFilePath, result.Path);
        }
        public async Task DeleteDirectoryAsync_SucceedsIfDirectoryExists()
        {
            // Arrange
            var directoryName = AzureFileStorageTestHelper.CreateRandomString();

            var numberOfFilesToCreate = AzureFileStorageTestHelper.CreateRandomNumber(
                minValue: 1, // Ensure that we always create at least one test file.
                maxValue: byte.MaxValue);

            await AzureFileStorageTestHelper.CreateTestDirectoryAsync(_fileShare, directoryName);

            await AzureFileStorageTestHelper.CreateTestFilesAsync(_fileShare, numberOfFilesToCreate, directoryName);

            // Act
            await _sut.DeleteDirectoryAsync(directoryName);

            // Assert
            Assert.False(await AzureFileStorageTestHelper.DirectoryExistsAsync(_fileShare, directoryName));
        }