Skip to content

Commit efef11b

Browse files
Merge pull request #57 from sergiobarriel/feature/azurite
Added Azurite
2 parents 53413c7 + 2c68a28 commit efef11b

26 files changed

Lines changed: 503 additions & 740 deletions

.github/workflows/run-tests-and-deploy.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ jobs:
1212
- name: '⚙️ Setup .NET Core'
1313
uses: actions/setup-dotnet@v1
1414
with:
15-
dotnet-version: '7.0.x'
15+
dotnet-version: '8.0.x'
1616

1717
- name: '🧱 dotnet build'
1818
run: 'dotnet build'
1919
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper'
20-
20+
21+
- name: '💾 azurite'
22+
run: |
23+
npm install -g azurite
24+
mkdir -p azurite
25+
azurite --location ./azurite --debug ./azurite/debug.log &
26+
2127
- name: '🚨 dotnet test'
2228
run: dotnet test --environment AZURE_STORAGE_CONNECTION_STRING="${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
2329
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper.Tests'

.github/workflows/run-tests.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@ on:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
1415
steps:
1516
- uses: actions/checkout@v3
1617

1718
- name: '⚙️ Setup .NET Core'
1819
uses: actions/setup-dotnet@v1
1920
with:
20-
dotnet-version: '7.0.x'
21+
dotnet-version: '8.0.x'
2122

2223
- name: '🧱 dotnet build'
2324
run: dotnet build
2425
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper'
25-
26+
27+
- name: '💾 azurite'
28+
run: |
29+
npm install -g azurite
30+
mkdir -p azurite
31+
azurite --location ./azurite --debug ./azurite/debug.log &
32+
2633
- name: '🚨 dotnet test'
2734
run: dotnet test --environment AZURE_STORAGE_CONNECTION_STRING="${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
2835
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper.Tests'
36+
37+

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ The upload commands have a property called `UseVirtualFolder` which by default h
153153

154154
**Be careful.** If you make that change, the files will NOT be saved in virtual directories, and file names may collide, causing files to be overwritten.
155155

156-
In this case, you must be responsible for establishing your own mechanism to generate unique file names.
156+
> In this case, you must be responsible for establishing your own mechanism to generate unique file names.
157157
158158
```csharp
159159
var base64 = "SGVsbG8g8J+Zgg==";
@@ -170,7 +170,7 @@ var command = new UploadBase64()
170170
var response = await _azureStorageWrapper.UploadBlobAsync(command);
171171
```
172172

173-
## Download blobs
173+
## Download blob references
174174

175175
To download a blob reference, you need specify the *Uri*.
176176

@@ -270,6 +270,7 @@ These individuals have contributed to the repository through suggestions, error
270270

271271
- [ginodcs](https://github.com/ginodcs)
272272
- [christian-cell](https://github.com/christian-cell)
273+
- [scabrera](https://github.com/scabrera)
273274

274275
# Sponsor
275276

src/AzureStorageWrapper/AzureStorageWrapper.Tests/AzureStorageWrapper.Tests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<UserSecretsId>4125ba48-a89c-4eba-989b-dab2cbd677c4</UserSecretsId>
@@ -12,9 +12,8 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
1615
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
1817
<PackageReference Include="xunit" Version="2.8.1" />
1918
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
2019
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/AzureStorageWrapper/AzureStorageWrapper.Tests/Should/BaseShould.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ protected static async Task<bool> PingAsync(string uri)
1515

1616
return response.IsSuccessStatusCode;
1717
}
18-
19-
20-
public static IEnumerable<object[]> InvalidMetadata() => new List<object[]>()
21-
{
22-
new object[] { new Dictionary<string, string>() },
23-
new object[] { null },
24-
};
18+
2519

2620
public static IEnumerable<object[]> InvalidExpiresIn() => new List<object[]>()
2721
{
@@ -36,7 +30,7 @@ protected static async Task<bool> PingAsync(string uri)
3630
/// order: container, fileName, fileExtension
3731
/// </summary>
3832
/// <returns></returns>
39-
public static IEnumerable<object[]> InvalidFilePropertiesCombination() => new List<object[]>()
33+
public static IEnumerable<object[]> WrongUploadBlobCommandProperties() => new List<object[]>()
4034
{
4135
new object[] { "", "", "" },
4236
new object[] { "files", "", "" },
Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using AzureStorageWrapper.Commands;
1+
using AzureStorageWrapper.Commands;
22
using AzureStorageWrapper.Exceptions;
33
using AzureStorageWrapper.Tests.Sources;
44
using Xunit;
5-
5+
66
namespace AzureStorageWrapper.Tests.Should.Download
77
{
88
public class DownloadBlobReferenceShould : BaseShould
@@ -17,49 +17,96 @@ public DownloadBlobReferenceShould(IAzureStorageWrapper azureStorageWrapper)
1717
[Fact]
1818
public async Task DownloadBlobReference_WithManyDots_Should_ReturnReference()
1919
{
20-
var command = new DownloadBlobReference()
20+
var base64 = "SGVsbG8g8J+Zgg==";
21+
22+
var uploadBlobCommand = new UploadBase64()
2123
{
22-
Uri = Uris.ExistingFileWithManyDots,
23-
ExpiresIn = 360,
24+
Base64 = base64,
25+
Container = "files",
26+
Name = "hello.world.hello.world",
27+
Extension = "md",
28+
Metadata = new Dictionary<string, string>()
29+
{{"hello", "world"}}
2430
};
2531

26-
var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
32+
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);
33+
34+
var downloadBlobReferenceCommand = new DownloadBlobReference()
35+
{
36+
Uri = uploadBlobResponse.Uri,
37+
ExpiresIn = 360,
38+
};
2739

28-
Assert.NotNull(response);
40+
// Act
41+
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);
2942

30-
Assert.True(await PingAsync(response.SasUri));
43+
// Assert
44+
Assert.NotNull(blobReference);
45+
Assert.True(await PingAsync(blobReference.SasUri));
3146
}
3247

3348
[Fact]
3449
public async Task DownloadBlobReference_WithExtensions_Should_ReturnReference()
3550
{
36-
var command = new DownloadBlobReference()
51+
var base64 = "SGVsbG8g8J+Zgg==";
52+
53+
var uploadBlobCommand = new UploadBase64()
3754
{
38-
Uri = Uris.ExistingFileWithManyExtensions,
39-
ExpiresIn = 360,
55+
Base64 = base64,
56+
Container = "files",
57+
Name = "hello",
58+
Extension = "md.md.md",
59+
Metadata = new Dictionary<string, string>()
60+
{{"hello", "world"}}
4061
};
4162

42-
var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
63+
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);
64+
65+
var downloadBlobReferenceCommand = new DownloadBlobReference()
66+
{
67+
Uri = uploadBlobResponse.Uri,
68+
ExpiresIn = 360,
69+
};
4370

44-
Assert.NotNull(response);
71+
// Act
72+
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);
4573

46-
Assert.True(await PingAsync(response.SasUri));
74+
// Assert
75+
Assert.NotNull(blobReference);
76+
Assert.True(await PingAsync(blobReference.SasUri));
4777
}
4878

4979
[Fact]
5080
public async Task DownloadBlobReference_Should_ReturnReference()
5181
{
52-
var command = new DownloadBlobReference()
82+
// Arrange
83+
84+
var base64 = "SGVsbG8g8J+Zgg==";
85+
86+
var uploadBlobCommand = new UploadBase64()
5387
{
54-
Uri = Uris.ExistingFile,
55-
ExpiresIn = 360,
88+
Base64 = base64,
89+
Container = "files",
90+
Name = "hello",
91+
Extension = "md",
92+
Metadata = new Dictionary<string, string>()
93+
{{"hello", "world"}}
5694
};
5795

58-
var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
96+
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);
97+
98+
var downloadBlobReferenceCommand = new DownloadBlobReference()
99+
{
100+
Uri = uploadBlobResponse.Uri,
101+
ExpiresIn = 360,
102+
};
59103

60-
Assert.NotNull(response);
104+
// Act
105+
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);
61106

62-
Assert.True(await PingAsync(response.SasUri));
107+
// Assert
108+
Assert.NotNull(blobReference);
109+
Assert.True(await PingAsync(blobReference.SasUri));
63110
}
64111

65112
[Fact]
@@ -84,7 +131,7 @@ public async Task DownloadBlobReference_WithUnExistingUri_Should_ThrowException(
84131
{
85132
var command = new DownloadBlobReference()
86133
{
87-
Uri = Uris.UnExistingFile,
134+
Uri = "",
88135
ExpiresIn = 360,
89136
};
90137

@@ -94,39 +141,7 @@ await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
94141
_ = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
95142
});
96143
}
97-
98-
99-
[Theory]
100-
[MemberData(nameof(InvalidExpiresIn))]
101-
public async Task DownloadBlobReference_WithWrongExpiration_Should_ReturnReference(int expiresIn)
102-
{
103-
var command = new DownloadBlobReference()
104-
{
105-
Uri = Uris.ExistingFile,
106-
ExpiresIn = expiresIn,
107-
};
108-
109-
var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
110-
111-
Assert.NotNull(response);
112-
113-
Assert.True(await PingAsync(response.SasUri));
114-
}
115-
116-
[Fact]
117-
public async Task DownloadBlobReference_WithHighExpiration_Should_ThrowException()
118-
{
119-
var command = new DownloadBlobReference()
120-
{
121-
Uri = Uris.ExistingFile,
122-
ExpiresIn = int.MaxValue,
123-
};
124-
125-
await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
126-
{
127-
_ = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
128-
});
129-
}
144+
130145

131146
}
132147
}

src/AzureStorageWrapper/AzureStorageWrapper.Tests/Should/Download/DownloadBlobStreamShould.cs

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,67 @@ public DownloadBlobStreamShould(IAzureStorageWrapper azureStorageWrapper)
1717
[Fact]
1818
public async Task DownloadBlob_Should_ReturnBlob()
1919
{
20-
var commandReference = new DownloadBlobReference()
20+
// Arrange
21+
22+
var base64 = "SGVsbG8g8J+Zgg==";
23+
24+
var uploadBlobCommand = new UploadBase64()
2125
{
22-
Uri = Uris.ExistingFile,
23-
ExpiresIn = 60
26+
Base64 = base64,
27+
Container = "files",
28+
Name = "hello world",
29+
Extension = "md",
30+
Metadata = new Dictionary<string, string>()
31+
{{"hello", "world"}}
2432
};
2533

26-
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);
34+
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);
35+
36+
var downloadBlobCommand = new DownloadBlobReference()
37+
{
38+
Uri = uploadBlobResponse.Uri,
39+
ExpiresIn = 360,
40+
};
41+
42+
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobCommand);
2743

2844
var command = new DownloadBlob()
2945
{
3046
Uri = blobReference.SasUri,
3147
};
3248

49+
// Act
50+
3351
var response = await _azureStorageWrapper.DownloadBlobAsync(command);
3452

53+
// Assert
3554
Assert.NotNull(response);
3655

3756
Assert.NotNull(response.Stream);
3857
Assert.True(response.Stream.Length > 0);
3958
}
4059

4160

42-
[Fact]
43-
public async Task DownloadBlob_WithInvalidUri_Should_ReturnBlob()
44-
{
45-
var commandReference = new DownloadBlobReference()
46-
{
47-
Uri = Uris.ExistingFile,
48-
ExpiresIn = 60
49-
};
50-
51-
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);
52-
53-
var command = new DownloadBlob()
54-
{
55-
Uri = blobReference.Uri,
56-
};
57-
58-
await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
59-
{
60-
_ = await _azureStorageWrapper.DownloadBlobAsync(command);
61-
});
62-
}
61+
// [Fact]
62+
// public async Task DownloadBlob_WithInvalidUri_Should_ReturnBlob()
63+
// {
64+
// var commandReference = new DownloadBlobReference()
65+
// {
66+
// Uri = Uris.ExistingFile,
67+
// ExpiresIn = 60
68+
// };
69+
//
70+
// var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);
71+
//
72+
// var command = new DownloadBlob()
73+
// {
74+
// Uri = blobReference.Uri,
75+
// };
76+
//
77+
// await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
78+
// {
79+
// _ = await _azureStorageWrapper.DownloadBlobAsync(command);
80+
// });
81+
// }
6382
}
6483
}

0 commit comments

Comments
 (0)