Skip to content

Commit

Permalink
PR - devops/azureit integration (#59)
Browse files Browse the repository at this point in the history
* update unit tests

* update pipeline

* update pipeline naming

* tipo

* change workflow trigger policy

* added status badge

* chore

* update trigger

---------

Co-authored-by: medevod <devteam@evodim.com>
  • Loading branch information
medevod and medevod committed Jul 21, 2023
1 parent e400089 commit 43beb29
Show file tree
Hide file tree
Showing 9 changed files with 689 additions and 1,144 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/publish-internal.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: PR internal deployment

name: pull-request alpha build and deploy
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Test scenario tags'
pull_request:
branches: [ main ]
paths: [src/**]
branches: [ main ]
paths: [src/**, tests/**]
env:
GITHUB_PACKAGES_URL: https://nuget.pkg.github.com/evodim/index.json
BUILD_CONFIGURATION: 'Release' # set this mto the appropriate build configuration
Expand All @@ -28,8 +35,13 @@ jobs:
APP_VERSION=`minver`
echo "Adding version to GITHUB_ENV: APP_VERSION=$APP_VERSION"
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
# Setup .NET Core SDK dqsdqs
# Install Azure sorage emulator
- name: Install Azurite
id: azuright
uses: potatoqualitee/azuright@v1.1
with:
self-signed-cert: true
# Setup .NET Core SDK
- name: dotnet add nuget source
run: |
dotnet nuget add source --username medevod --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github '${{ env.GITHUB_PACKAGES_URL }}'
Expand All @@ -38,6 +50,7 @@ jobs:
run: |
dotnet restore
dotnet build --configuration '${{ env.BUILD_CONFIGURATION }}' --version-suffix '${{ env.APP_VERSION }}'
dotnet test --configuration '${{ env.BUILD_CONFIGURATION }}' -v n
dotnet pack -c '${{ env.BUILD_CONFIGURATION }}' --no-build --version-suffix '${{ env.APP_VERSION }}'
# Publish the package to Azure Artifacts
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/publish-public.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: MAIN public deployment

name: preview and release build and deploy

on:
push:
Expand Down Expand Up @@ -38,13 +37,18 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

# Install Azure sorage emulator
- name: Install Azurite
id: azuright
uses: potatoqualitee/azuright@v1.1
with:
self-signed-cert: true
# Run dotnet build and package
- name: dotnet build and test
run: |
dotnet restore
dotnet build --configuration '${{ env.BUILD_CONFIGURATION }}'
dotnet test --configuration '${{ env.BUILD_CONFIGURATION }}'
dotnet test --configuration '${{ env.BUILD_CONFIGURATION }}' -v n
az-artifacts-build-and-deploy:
needs: build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,4 @@ MigrationBackup/
**/launchSettings.json

/.vscode
__azurite_db_*
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## Manage your entities in Azure Storage without tears !

![internal](https://github.com/evodim/Azure.EntityServices/actions/workflows/publish-internal.yml/badge.svg)
![public](https://github.com/evodim/Azure.EntityServices/actions/workflows/publish-public.yml/badge.svg)

## What is Azure Entity Services?

Azure Entity Services is an abstraction layer library which help you to **store**, **query**, **update** any entities classes in Azure Storage Table and Blob
Expand Down
1 change: 1 addition & 0 deletions samples/Common.Samples/Models/PersonEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum DocumentType
public class PersonEntity
{
public string TenantId { get; set; }
public DateTimeOffset? CreatedEntity { get; }
public DateTimeOffset? Created { get; set; }
public DateTime? LocalCreated { get; set; }
public DateTimeOffset Updated { get; set; }
Expand Down
192 changes: 77 additions & 115 deletions tests/Azure.EntityServices.Tests/Blob/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,21 @@ public async Task Should_Download_File()
var container = new BlobContainerClient(connectionString, containerName);
await container.CreateIfNotExistsAsync();

var fileName = GenerateRandomBlobName(nameof(Should_Download_File));
// Get a reference to a blob named "sample-file"
var blob = container.GetBlobClient(fileName);

try
// First upload something the blob so we have something to download
await using (var fs = GenerateBlob(sampleFileContent))
{
var fileName = GenerateRandomBlobName(nameof(Should_Download_File));
// Get a reference to a blob named "sample-file"
var blob = container.GetBlobClient(fileName);

// First upload something the blob so we have something to download
await using (var fs = GenerateBlob(sampleFileContent))
{
await blob.UploadAsync(fs);
}
await blob.UploadAsync(fs);
}

await using var downloadedFs = await client.DownloadAsync(fileName);
downloadedFs.Seek(0, SeekOrigin.Begin);
sampleFileContent.Should().Be(await new StreamReader(downloadedFs).ReadToEndAsync());
await using var downloadedFs = await client.DownloadAsync(fileName);
downloadedFs.Seek(0, SeekOrigin.Begin);
sampleFileContent.Should().Be(await new StreamReader(downloadedFs).ReadToEndAsync());

// Verify the contents
}
finally
{
await container.DeleteIfExistsAsync();
}
// Verify the contents
}

/// <summary>
Expand All @@ -84,28 +76,22 @@ public async Task Should_List()
var blobNames = new List<string> { $"{blobPath}/{nameof(file1)}", $"{blobPath}/{nameof(file2)}", $"{blobPath}/{nameof(file3)}" };

await container.CreateIfNotExistsAsync();
try
{
// Upload a couple of blobs so we have something to list
await container.UploadBlobAsync($"{blobPath}/{nameof(file1)}", GenerateBlob(file1));
await container.UploadBlobAsync($"{blobPath}/{nameof(file2)}", GenerateBlob(file2));
await container.UploadBlobAsync($"{blobPath}/{nameof(file3)}", GenerateBlob(file3));

var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });

// List all the blobs
var blobs = new List<IDictionary<string, string>>();
await foreach (var page in client.ListAsync(blobPath))
{
blobs.AddRange(page);
}
blobs.Select(b => b["_Name"]).Should().BeEquivalentTo(blobNames);
}
finally

// Upload a couple of blobs so we have something to list
await container.UploadBlobAsync($"{blobPath}/{nameof(file1)}", GenerateBlob(file1));
await container.UploadBlobAsync($"{blobPath}/{nameof(file2)}", GenerateBlob(file2));
await container.UploadBlobAsync($"{blobPath}/{nameof(file3)}", GenerateBlob(file3));

var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });

// List all the blobs
var blobs = new List<IDictionary<string, string>>();
await foreach (var page in client.ListAsync(blobPath))
{
await container.DeleteIfExistsAsync();
blobs.AddRange(page);
}
blobs.Select(b => b["_Name"]).Should().BeEquivalentTo(blobNames);
}

/// <summary>
Expand Down Expand Up @@ -151,29 +137,23 @@ public async Task Should_Upload_File()
var container = new BlobContainerClient(connectionString, containerName);

await container.CreateIfNotExistsAsync();
try
{
// Get a reference to a blob
var fileName = GenerateRandomBlobName(nameof(Should_Upload_File));

var blob = container.GetBlobClient(fileName);

var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
// Open the file and upload its data
await using (var fs = GenerateBlob(sampleFileContent))
{
await client.UploadAsync(fileName, fs);
}

// Verify we uploaded some content
BlobProperties properties = await blob.GetPropertiesAsync();
((long)sampleFileContent.Length).Should().Be(properties.ContentLength);
}
finally

// Get a reference to a blob
var fileName = GenerateRandomBlobName(nameof(Should_Upload_File));

var blob = container.GetBlobClient(fileName);

var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
// Open the file and upload its data
await using (var fs = GenerateBlob(sampleFileContent))
{
await container.DeleteIfExistsAsync();
await client.UploadAsync(fileName, fs);
}

// Verify we uploaded some content
BlobProperties properties = await blob.GetPropertiesAsync();
((long)sampleFileContent.Length).Should().Be(properties.ContentLength);
}

/// <summary>
Expand All @@ -191,30 +171,24 @@ public async Task Should_List_By_Tags()
var blobsToUpload = new List<string>();
var tag = Guid.NewGuid().ToString();
await container.CreateIfNotExistsAsync();
try

var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
for (var i = 0; i < 11; i++)
{
var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
for (var i = 0; i < 11; i++)
{
var name = GenerateRandomBlobName(nameof(Should_List_By_Tags));
blobsToUpload.Add(name);
await client.UploadAsync(name, GenerateBlob(file1), new Dictionary<string, string>() { ["TenantId"] = tag }, null);
}

// List all the blobs
var blobs = new List<IDictionary<string, string>>();
await Task.Delay(2000);
await foreach (var page in client.ListByTagsAsync($"\"TenantId\" = '{tag}'"))
{
blobs.AddRange(page);
}
blobs.Select(p => p["_Name"]).Should().BeEquivalentTo(blobsToUpload);
var name = GenerateRandomBlobName(nameof(Should_List_By_Tags));
blobsToUpload.Add(name);
await client.UploadAsync(name, GenerateBlob(file1), new Dictionary<string, string>() { ["TenantId"] = tag }, null);
}
finally

// List all the blobs
var blobs = new List<IDictionary<string, string>>();
await Task.Delay(2000);
await foreach (var page in client.ListByTagsAsync($"\"TenantId\" = '{tag}'"))
{
await container.DeleteIfExistsAsync();
blobs.AddRange(page);
}
blobs.Select(p => p["_Name"]).Should().BeEquivalentTo(blobsToUpload);
}

[TestMethod]
Expand All @@ -226,24 +200,18 @@ public async Task Should_Add_And_Get_Properties()
var containerName = TempContainerName();
// Get a reference to a container named "sample-container" and then create it
var container = new BlobContainerClient(connectionString, containerName);
try
{
var name = $"{nameof(Should_Add_And_Get_Properties)}-{DateTime.UtcNow.Ticks}";
var propValue = Guid.NewGuid().ToString();
var propValue2 = Guid.NewGuid().ToString();
await container.CreateIfNotExistsAsync();
var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
await client.UploadAsync(name, GenerateBlob(file1), null, new Dictionary<string, string>() { ["Property1"] = propValue, ["Property2"] = propValue2 });
var props = await client.GetBlobProperiesAsync(name);

props.Should().ContainKeys("Property1", "Property2");
props.Should().ContainValues(propValue, propValue2);
}
finally
{
await container.DeleteIfExistsAsync();
}

var name = $"{nameof(Should_Add_And_Get_Properties)}-{DateTime.UtcNow.Ticks}";
var propValue = Guid.NewGuid().ToString();
var propValue2 = Guid.NewGuid().ToString();
await container.CreateIfNotExistsAsync();
var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
await client.UploadAsync(name, GenerateBlob(file1), null, new Dictionary<string, string>() { ["Property1"] = propValue, ["Property2"] = propValue2 });
var props = await client.GetBlobProperiesAsync(name);

props.Should().ContainKeys("Property1", "Property2");
props.Should().ContainValues(propValue, propValue2);
}

[TestMethod]
Expand All @@ -255,23 +223,17 @@ public async Task Should_Add_And_Get_Header_Properties()
var containerName = TempContainerName();
// Get a reference to a container named "sample-container" and then create it
var container = new BlobContainerClient(connectionString, containerName);
try
{
var name = $"{nameof(Should_Add_And_Get_Header_Properties)}-{DateTime.UtcNow.Ticks}";
var contentType = "application/json";
var contentEncoding = "gzip";
await container.CreateIfNotExistsAsync();
var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
await client.UploadAsync(name, GenerateBlob(file1), null, new Dictionary<string, string>() { ["ContentType"] = contentType, ["ContentEncoding"] = contentEncoding });
var props = await client.GetBlobProperiesAsync(name);
props.Should().ContainKeys("ContentType", "ContentEncoding");
props.Should().ContainValues(contentType, contentEncoding);
}
finally
{
await container.DeleteIfExistsAsync();
}

var name = $"{nameof(Should_Add_And_Get_Header_Properties)}-{DateTime.UtcNow.Ticks}";
var contentType = "application/json";
var contentEncoding = "gzip";
await container.CreateIfNotExistsAsync();
var client = new BlobService(_blobServiceClient)
.Configure(new BlobServiceOptions() { ContainerName = containerName });
await client.UploadAsync(name, GenerateBlob(file1), null, new Dictionary<string, string>() { ["ContentType"] = contentType, ["ContentEncoding"] = contentEncoding });
var props = await client.GetBlobProperiesAsync(name);
props.Should().ContainKeys("ContentType", "ContentEncoding");
props.Should().ContainValues(contentType, contentEncoding);
}

private static Stream GenerateBlob(string content)
Expand Down
Loading

0 comments on commit 43beb29

Please sign in to comment.