Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/run-tests-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ jobs:
- name: '⚙️ Setup .NET Core'
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: '🧱 dotnet build'
run: 'dotnet build'
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper'


- name: '💾 azurite'
run: |
npm install -g azurite
mkdir -p azurite
azurite --location ./azurite --debug ./azurite/debug.log &

- name: '🚨 dotnet test'
run: dotnet test --environment AZURE_STORAGE_CONNECTION_STRING="${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper.Tests'
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: '⚙️ Setup .NET Core'
uses: actions/setup-dotnet@v1
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'

- name: '🧱 dotnet build'
run: dotnet build
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper'


- name: '💾 azurite'
run: |
npm install -g azurite
mkdir -p azurite
azurite --location ./azurite --debug ./azurite/debug.log &

- name: '🚨 dotnet test'
run: dotnet test --environment AZURE_STORAGE_CONNECTION_STRING="${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
working-directory: './src/AzureStorageWrapper/AzureStorageWrapper.Tests'


5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ The upload commands have a property called `UseVirtualFolder` which by default h

**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.

In this case, you must be responsible for establishing your own mechanism to generate unique file names.
> In this case, you must be responsible for establishing your own mechanism to generate unique file names.

```csharp
var base64 = "SGVsbG8g8J+Zgg==";
Expand All @@ -170,7 +170,7 @@ var command = new UploadBase64()
var response = await _azureStorageWrapper.UploadBlobAsync(command);
```

## Download blobs
## Download blob references

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

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

- [ginodcs](https://github.com/ginodcs)
- [christian-cell](https://github.com/christian-cell)
- [scabrera](https://github.com/scabrera)

# Sponsor

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>4125ba48-a89c-4eba-989b-dab2cbd677c4</UserSecretsId>
Expand All @@ -12,9 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@

return response.IsSuccessStatusCode;
}


public static IEnumerable<object[]> InvalidMetadata() => new List<object[]>()
{
new object[] { new Dictionary<string, string>() },
new object[] { null },
};


public static IEnumerable<object[]> InvalidExpiresIn() => new List<object[]>()
{
Expand All @@ -29,14 +23,14 @@
new object[] { - 360 },
new object[] { - 1 },
new object[] { 0 },
new object[] { null }

Check warning on line 26 in src/AzureStorageWrapper/AzureStorageWrapper.Tests/Should/BaseShould.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
};

/// <summary>
/// order: container, fileName, fileExtension
/// </summary>
/// <returns></returns>
public static IEnumerable<object[]> InvalidFilePropertiesCombination() => new List<object[]>()
public static IEnumerable<object[]> WrongUploadBlobCommandProperties() => new List<object[]>()
{
new object[] { "", "", "" },
new object[] { "files", "", "" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using AzureStorageWrapper.Commands;
using AzureStorageWrapper.Commands;
using AzureStorageWrapper.Exceptions;
using AzureStorageWrapper.Tests.Sources;
using Xunit;

namespace AzureStorageWrapper.Tests.Should.Download
{
public class DownloadBlobReferenceShould : BaseShould
{
private readonly IAzureStorageWrapper _azureStorageWrapper;

public DownloadBlobReferenceShould(IAzureStorageWrapper azureStorageWrapper)

Check warning on line 12 in src/AzureStorageWrapper/AzureStorageWrapper.Tests/Should/Download/DownloadBlobReferenceShould.cs

View workflow job for this annotation

GitHub Actions / build

Fixture argument 'azureStorageWrapper' does not have a fixture source (if it comes from a collection definition, ensure the definition is in the same assembly as the test) (https://xunit.net/xunit.analyzers/rules/xUnit1041)
{
_azureStorageWrapper = azureStorageWrapper;
}
Expand All @@ -17,49 +17,96 @@
[Fact]
public async Task DownloadBlobReference_WithManyDots_Should_ReturnReference()
{
var command = new DownloadBlobReference()
var base64 = "SGVsbG8g8J+Zgg==";

var uploadBlobCommand = new UploadBase64()
{
Uri = Uris.ExistingFileWithManyDots,
ExpiresIn = 360,
Base64 = base64,
Container = "files",
Name = "hello.world.hello.world",
Extension = "md",
Metadata = new Dictionary<string, string>()
{{"hello", "world"}}
};

var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);

var downloadBlobReferenceCommand = new DownloadBlobReference()
{
Uri = uploadBlobResponse.Uri,
ExpiresIn = 360,
};

Assert.NotNull(response);
// Act
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);

Assert.True(await PingAsync(response.SasUri));
// Assert
Assert.NotNull(blobReference);
Assert.True(await PingAsync(blobReference.SasUri));
}

[Fact]
public async Task DownloadBlobReference_WithExtensions_Should_ReturnReference()
{
var command = new DownloadBlobReference()
var base64 = "SGVsbG8g8J+Zgg==";

var uploadBlobCommand = new UploadBase64()
{
Uri = Uris.ExistingFileWithManyExtensions,
ExpiresIn = 360,
Base64 = base64,
Container = "files",
Name = "hello",
Extension = "md.md.md",
Metadata = new Dictionary<string, string>()
{{"hello", "world"}}
};

var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);

var downloadBlobReferenceCommand = new DownloadBlobReference()
{
Uri = uploadBlobResponse.Uri,
ExpiresIn = 360,
};

Assert.NotNull(response);
// Act
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);

Assert.True(await PingAsync(response.SasUri));
// Assert
Assert.NotNull(blobReference);
Assert.True(await PingAsync(blobReference.SasUri));
}

[Fact]
public async Task DownloadBlobReference_Should_ReturnReference()
{
var command = new DownloadBlobReference()
// Arrange

var base64 = "SGVsbG8g8J+Zgg==";

var uploadBlobCommand = new UploadBase64()
{
Uri = Uris.ExistingFile,
ExpiresIn = 360,
Base64 = base64,
Container = "files",
Name = "hello",
Extension = "md",
Metadata = new Dictionary<string, string>()
{{"hello", "world"}}
};

var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);

var downloadBlobReferenceCommand = new DownloadBlobReference()
{
Uri = uploadBlobResponse.Uri,
ExpiresIn = 360,
};

Assert.NotNull(response);
// Act
var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobReferenceCommand);

Assert.True(await PingAsync(response.SasUri));
// Assert
Assert.NotNull(blobReference);
Assert.True(await PingAsync(blobReference.SasUri));
}

[Fact]
Expand All @@ -84,7 +131,7 @@
{
var command = new DownloadBlobReference()
{
Uri = Uris.UnExistingFile,
Uri = "",
ExpiresIn = 360,
};

Expand All @@ -94,39 +141,7 @@
_ = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
});
}


[Theory]
[MemberData(nameof(InvalidExpiresIn))]
public async Task DownloadBlobReference_WithWrongExpiration_Should_ReturnReference(int expiresIn)
{
var command = new DownloadBlobReference()
{
Uri = Uris.ExistingFile,
ExpiresIn = expiresIn,
};

var response = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);

Assert.NotNull(response);

Assert.True(await PingAsync(response.SasUri));
}

[Fact]
public async Task DownloadBlobReference_WithHighExpiration_Should_ThrowException()
{
var command = new DownloadBlobReference()
{
Uri = Uris.ExistingFile,
ExpiresIn = int.MaxValue,
};

await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
{
_ = await _azureStorageWrapper.DownloadBlobReferenceAsync(command);
});
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
private readonly IAzureStorageWrapper _azureStorageWrapper;

public DownloadBlobStreamShould(IAzureStorageWrapper azureStorageWrapper)

Check warning on line 12 in src/AzureStorageWrapper/AzureStorageWrapper.Tests/Should/Download/DownloadBlobStreamShould.cs

View workflow job for this annotation

GitHub Actions / build

Fixture argument 'azureStorageWrapper' does not have a fixture source (if it comes from a collection definition, ensure the definition is in the same assembly as the test) (https://xunit.net/xunit.analyzers/rules/xUnit1041)
{
_azureStorageWrapper = azureStorageWrapper;
}
Expand All @@ -17,48 +17,67 @@
[Fact]
public async Task DownloadBlob_Should_ReturnBlob()
{
var commandReference = new DownloadBlobReference()
// Arrange

var base64 = "SGVsbG8g8J+Zgg==";

var uploadBlobCommand = new UploadBase64()
{
Uri = Uris.ExistingFile,
ExpiresIn = 60
Base64 = base64,
Container = "files",
Name = "hello world",
Extension = "md",
Metadata = new Dictionary<string, string>()
{{"hello", "world"}}
};

var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);
var uploadBlobResponse = await _azureStorageWrapper.UploadBlobAsync(uploadBlobCommand);

var downloadBlobCommand = new DownloadBlobReference()
{
Uri = uploadBlobResponse.Uri,
ExpiresIn = 360,
};

var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(downloadBlobCommand);

var command = new DownloadBlob()
{
Uri = blobReference.SasUri,
};

// Act

var response = await _azureStorageWrapper.DownloadBlobAsync(command);

// Assert
Assert.NotNull(response);

Assert.NotNull(response.Stream);
Assert.True(response.Stream.Length > 0);
}


[Fact]
public async Task DownloadBlob_WithInvalidUri_Should_ReturnBlob()
{
var commandReference = new DownloadBlobReference()
{
Uri = Uris.ExistingFile,
ExpiresIn = 60
};

var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);

var command = new DownloadBlob()
{
Uri = blobReference.Uri,
};

await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
{
_ = await _azureStorageWrapper.DownloadBlobAsync(command);
});
}
// [Fact]
// public async Task DownloadBlob_WithInvalidUri_Should_ReturnBlob()
// {
// var commandReference = new DownloadBlobReference()
// {
// Uri = Uris.ExistingFile,
// ExpiresIn = 60
// };
//
// var blobReference = await _azureStorageWrapper.DownloadBlobReferenceAsync(commandReference);
//
// var command = new DownloadBlob()
// {
// Uri = blobReference.Uri,
// };
//
// await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
// {
// _ = await _azureStorageWrapper.DownloadBlobAsync(command);
// });
// }
}
}
Loading
Loading