Skip to content

Commit 7fac388

Browse files
author
dudchenko610
committed
tested azure blob storage functionality except list fetching
1 parent 319aaf2 commit 7fac388

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

ManagedCode.Storage.Azure/AzureBlobStorage.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public async Task DeleteAsync(IEnumerable<Blob> blobs, CancellationToken cancell
6161

6262
#endregion
6363

64+
#region Download
65+
6466
public async Task<Stream> DownloadAsStreamAsync(string blob, CancellationToken cancellationToken = default)
6567
{
6668
var blobClient = _blobContainerClient.GetBlobClient(blob);
@@ -89,6 +91,8 @@ public async Task<LocalFile> DownloadAsync(Blob blob, CancellationToken cancella
8991
return await DownloadAsync(blob.Name, cancellationToken);
9092
}
9193

94+
#endregion
95+
9296
#region Exists
9397

9498
public async Task<bool> ExistsAsync(string blob, CancellationToken cancellationToken = default)
@@ -127,6 +131,8 @@ public async IAsyncEnumerable<bool> ExistsAsync(IEnumerable<Blob> blobs,
127131

128132
#endregion
129133

134+
#region Get
135+
130136
public async Task<Blob> GetBlobAsync(string blob, CancellationToken cancellationToken = default)
131137
{
132138
await Task.Yield();
@@ -150,6 +156,8 @@ public IAsyncEnumerable<Blob> GetBlobListAsync(CancellationToken cancellationTok
150156
throw new System.NotImplementedException();
151157
}
152158

159+
#endregion
160+
153161
#region Upload
154162

155163
public async Task UploadAsync(string blob, Stream dataStream, bool append = false, CancellationToken cancellationToken = default)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ManagedCode.Storage.Core.Builders;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace ManagedCode.Storage.Azure.Builders
5+
{
6+
public class AzureProviderBuilder : ProviderBuilder
7+
{
8+
public AzureProviderBuilder(IServiceCollection serviceCollection) : base(serviceCollection) {}
9+
10+
11+
}
12+
}

ManagedCode.Storage.Tests/Azure/DependencyInjectionTests.cs renamed to ManagedCode.Storage.Tests/Azure/AzureStorageTests.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
using System.Threading.Tasks;
55
using Xunit;
66
using FluentAssertions;
7+
using System.IO;
8+
using System.Text;
79

810
namespace ManagedCode.Storage.Tests.Azure
911
{
10-
public class DependencyInjectionTests
12+
public class AzureStorageTests
1113
{
1214
private IPhotoStorage _photoStorage;
1315
private IDocumentStorage _documentStorage;
1416

15-
public DependencyInjectionTests()
17+
public AzureStorageTests()
1618
{
1719
var services = new ServiceCollection();
1820

@@ -46,5 +48,44 @@ public async Task WhenSingleBlobExistsIsCalled()
4648

4749
result.Should().BeTrue();
4850
}
51+
52+
[Fact]
53+
public async Task WhenDownloadAsyncIsCalled()
54+
{
55+
var stream = await _documentStorage.DownloadAsStreamAsync("a.txt");
56+
using var sr = new StreamReader(stream, Encoding.UTF8);
57+
58+
string content = sr.ReadToEnd();
59+
60+
content.Should().NotBeNull();
61+
}
62+
63+
[Fact]
64+
public async Task WhenDownloadAsyncToFileIsCalled()
65+
{
66+
var tempFile = await _documentStorage.DownloadAsync("a.txt");
67+
using var sr = new StreamReader(tempFile.FileStream, Encoding.UTF8);
68+
69+
string content = sr.ReadToEnd();
70+
71+
content.Should().NotBeNull();
72+
}
73+
74+
[Fact]
75+
public async Task WhenUploadAsyncIsCalled()
76+
{
77+
var lineToUpload = "some crazy text";
78+
79+
var byteArray = Encoding.ASCII.GetBytes(lineToUpload);
80+
var stream = new MemoryStream(byteArray);
81+
82+
await _documentStorage.UploadAsync("b.txt", stream);
83+
}
84+
85+
[Fact]
86+
public async Task WhenDeleteAsyncIsCalled()
87+
{
88+
await _documentStorage.DeleteAsync("a.txt");
89+
}
4990
}
5091
}

0 commit comments

Comments
 (0)