Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit d437ed2

Browse files
authored
feat(AzureBlob): increases coverage (#163)
I achieved good coverage with most generic methods. Surely there are more situations we can test, but this is a initial harness that will enable us to more confidently make changes to this class. Closes #166.
1 parent f732504 commit d437ed2

File tree

14 files changed

+585
-74
lines changed

14 files changed

+585
-74
lines changed

.github/workflows/ci.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- name: Checkout code
16+
uses: actions/checkout@v1
17+
18+
- name: Start Azurite (Azure Blob Storage emulator)
19+
run: docker run --name azurite -d -p 10000:10000 -p 10001:10001 mcr.microsoft.com/azure-storage/azurite
20+
1621
- name: Setup .NET Core
1722
uses: actions/setup-dotnet@v1
18-
with:
23+
with:
1924
dotnet-version: 2.2.108
20-
- name: Test solution
21-
run: dotnet test
25+
26+
- name: Restore packages
27+
run: dotnet restore
28+
2229
- name: Build solution
23-
run: dotnet build --configuration Release
24-
30+
run: dotnet build
31+
32+
- name: Test solution
33+
run: dotnet test

Liquid.All.sln

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Base.Tests", "test\L
4747
EndProject
4848
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Domain.Tests", "test\Liquid.Domain.Tests\Liquid.Domain.Tests.csproj", "{90CF0830-CD3C-4DD7-8C90-584772885BE0}"
4949
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Liquid.Tests", "test\Liquid.Tests\Liquid.Tests.csproj", "{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5}"
50+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.Tests", "test\Liquid.Tests\Liquid.Tests.csproj", "{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5}"
51+
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Liquid.OnAzure.Tests", "test\Liquid.OnAzure.Tests\Liquid.OnAzure.Tests.csproj", "{9DEA4109-7542-40D5-9CCF-A673C9787E6D}"
5153
EndProject
5254
Global
5355
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -111,6 +113,10 @@ Global
111113
{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
112114
{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
113115
{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5}.Release|Any CPU.Build.0 = Release|Any CPU
116+
{9DEA4109-7542-40D5-9CCF-A673C9787E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
117+
{9DEA4109-7542-40D5-9CCF-A673C9787E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
118+
{9DEA4109-7542-40D5-9CCF-A673C9787E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
119+
{9DEA4109-7542-40D5-9CCF-A673C9787E6D}.Release|Any CPU.Build.0 = Release|Any CPU
114120
EndGlobalSection
115121
GlobalSection(SolutionProperties) = preSolution
116122
HideSolutionNode = FALSE
@@ -130,6 +136,7 @@ Global
130136
{5279F425-0A2C-4889-968D-FFEB25975453} = {6A0B6B3D-15FE-4C0B-97A1-7897E31C0C4E}
131137
{90CF0830-CD3C-4DD7-8C90-584772885BE0} = {6A0B6B3D-15FE-4C0B-97A1-7897E31C0C4E}
132138
{6BA7DC4B-0F66-415A-AE74-5DEA5D3943D5} = {6A0B6B3D-15FE-4C0B-97A1-7897E31C0C4E}
139+
{9DEA4109-7542-40D5-9CCF-A673C9787E6D} = {6A0B6B3D-15FE-4C0B-97A1-7897E31C0C4E}
133140
EndGlobalSection
134141
GlobalSection(ExtensibilityGlobals) = postSolution
135142
SolutionGuid = {1E0953B7-A30F-4440-9719-22CA017677B5}

src/Liquid.Base/Interfaces/Repository/ILightAttachment.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
namespace Liquid.Interfaces
45
{
@@ -9,6 +10,9 @@ public interface ILightAttachment
910
string ContentType { get; set; }
1011
string MediaLink { get; set; }
1112
Stream MediaStream { get; set; }
13+
/// <summary>
14+
/// The directory where the attachment will be stored into.
15+
/// </summary>
1216
string ResourceId { get; set; }
1317
}
1418
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
1-
using Liquid.Base.Interfaces;
1+
// Copyright (c) Avanade Inc. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
24
using System;
35
using System.Threading.Tasks;
6+
using Liquid.Base.Interfaces;
47

58
namespace Liquid.Interfaces
69
{
710
/// <summary>
8-
/// Public interface for all Media Storage Implementations
11+
/// Defines an object capable of storing arbritary media.
912
/// </summary>
1013
public interface ILightMediaStorage : IWorkbenchHealthCheck
11-
{
12-
string Conection { get; set; }
14+
{
15+
/// <summary>
16+
/// Gets or sets the connection string for the storage provider.
17+
/// </summary>
18+
[Obsolete("This property will be removed in later version. Please refrain from accessing it.")]
19+
string Connection { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the container name used to store data in the provider.
23+
/// </summary>
24+
[Obsolete("This property will be removed in later version. Please refrain from accessing it.")]
1325
string Container { get; set; }
26+
27+
/// <summary>
28+
/// Gets an <see cref="ILightAttachment"/> from storage.
29+
/// </summary>
30+
/// <param name="resourceId">The directory of the container.</param>
31+
/// <param name="id">The name of the media file.</param>
32+
/// <returns>
33+
/// A task that represents the asynchronous operation.
34+
/// The task result contains an object that encapsulates access to the data in the container entry.
35+
/// </returns>
36+
/// <exception cref="Exception">Throws when the resource doesn't exists.</exception>
1437
Task<ILightAttachment> GetAsync(string resourceId, string id);
15-
Task InsertUpdateAsync(ILightAttachment attachment);
16-
Task Remove(ILightAttachment attachment);
38+
39+
/// <summary>
40+
/// Upserts an <see cref="ILightAttachment"/> to the storage.
41+
/// </summary>
42+
/// <param name="attachment">Describes the data that will be stored/updated.</param>
43+
/// <returns>A task that represents the asynchronous operation.</returns>
44+
Task InsertUpdateAsync(ILightAttachment attachment);
45+
46+
/// <summary>
47+
/// Removes an item from the underlying storage.
48+
/// </summary>
49+
/// <param name="attachment">Describes the data that will be stored/updated.</param>
50+
/// <returns>A task that represents the asynchronous operation.</returns>
51+
Task Remove(ILightAttachment attachment);
1752
}
1853
}

src/Liquid.Base/StreamExtensions.cs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) Avanade Inc. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Liquid
10+
{
11+
/// <summary>
12+
/// Extensions to simplify the manipulation of streams.
13+
/// </summary>
14+
public static class StreamExtensions
15+
{
16+
/// <summary>
17+
/// Read the stream to the end and converts it to an UTF8 string.
18+
/// </summary>
19+
/// <param name="stream">The stream that will be read to the end.</param>
20+
/// <returns>The contents of the stream read as a string.</returns>
21+
public static string AsString(this Stream stream) => AsString(stream, Encoding.UTF8);
22+
23+
/// <summary>
24+
/// Read the stream to the end and converts it to a string accordingly to the desired encoding.
25+
/// </summary>
26+
/// <param name="stream">The stream that will be read to the end.</param>
27+
/// <param name="encoding">The encoding of the string in the stream.</param>
28+
/// <returns>The contents of the stream read as a string.</returns>
29+
public static string AsString(this Stream stream, Encoding encoding)
30+
{
31+
if (stream is null)
32+
{
33+
throw new ArgumentNullException(nameof(stream));
34+
}
35+
36+
if (encoding is null)
37+
{
38+
throw new ArgumentNullException(nameof(encoding));
39+
}
40+
41+
using (var reader = new StreamReader(stream, encoding))
42+
{
43+
return reader.ReadToEnd();
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Read the stream to the end and converts it to an UTF8 string asynchronously.
49+
/// </summary>
50+
/// <param name="stream">The stream that will be read to the end.</param>
51+
/// <returns>Task containg the result of the conversion from stream to string.</returns>
52+
public static Task<string> AsStringAsync(this Stream stream) => AsStringAsync(stream, Encoding.UTF8);
53+
54+
/// <summary>
55+
/// Read the stream to the end and converts it to a string accordingly to the desired encoding asynchronously.
56+
/// </summary>
57+
/// <param name="stream">The stream that will be read to the end.</param>
58+
/// <param name="encoding">The encoding of the string in the stream.</param>
59+
/// <returns>Task containg the result of the conversion from stream to string.</returns>
60+
public static Task<string> AsStringAsync(this Stream stream, Encoding encoding)
61+
{
62+
if (stream is null)
63+
{
64+
throw new ArgumentNullException(nameof(stream));
65+
}
66+
67+
if (encoding is null)
68+
{
69+
throw new ArgumentNullException(nameof(encoding));
70+
}
71+
72+
return AsStringAsyncImpl(stream, encoding);
73+
}
74+
75+
/// <summary>
76+
/// Read the stream to the end and converts it to a string accordingly to the desired encoding asynchronously.
77+
/// </summary>
78+
/// <param name="stream">The stream that will be read to the end.</param>
79+
/// <param name="encoding">The encoding of the string in the stream.</param>
80+
/// <returns>Task containg the result of the conversion from stream to string.</returns>
81+
private static async Task<string> AsStringAsyncImpl(this Stream stream, Encoding encoding)
82+
{
83+
using (var reader = new StreamReader(stream, encoding))
84+
{
85+
return await reader.ReadToEndAsync();
86+
}
87+
}
88+
}
89+
}

src/Liquid.OnAWS/Storages/S3.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Liquid.OnAWS
1111
{
1212
public class S3 : ILightMediaStorage
1313
{
14-
public string Conection { get; set; }
14+
public string Connection { get; set; }
1515
public string Container { get; set; }
1616
public dynamic mediaStorageConfiguration { get; set; }
1717

0 commit comments

Comments
 (0)