Skip to content

Commit

Permalink
Merge pull request #19 from things-library/adding-services
Browse files Browse the repository at this point in the history
Adding storage libraries
  • Loading branch information
lanmark7 authored Aug 21, 2024
2 parents 15a947d + d1ad120 commit f6e481b
Show file tree
Hide file tree
Showing 87 changed files with 662 additions and 606 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@ namespace ThingsLibrary.Testing.Extensions
{
public static class TestContainerOptionsExtensions
{

/// <summary>
/// Create a container builder object based on the options object
/// </summary>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public static ContainerBuilder GetContainerBuilder(this TestContainerOptions options)
{
//_ = Guard.Argument(options.Image, nameof(options.Image))
// .NotNull()
// .NotUppercase();

//_ = Guard.Argument(options.Name, nameof(options.Name))
// .NotNull()
// .NotEmpty()
// .NotUppercase();
ArgumentNullException.ThrowIfNullOrWhiteSpace(options.Image);
ArgumentNullException.ThrowIfNullOrWhiteSpace(options.Name);

if (!Regex.IsMatch(options.Name, "^[a-z0-9_.-]*$", RegexOptions.Singleline | RegexOptions.CultureInvariant))
{
Expand Down
21 changes: 21 additions & 0 deletions Base/src/ThingsLibrary.Testing/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Extensions.Configuration;

namespace ThingsLibrary.Storage.Tests
{
public static class TypeExtensions
{
/// <summary>
/// Gets the configuration root with appSettings.json and user secrets
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static IConfigurationRoot GetConfigurationRoot(this Type type)
{
return new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false)
.AddUserSecrets(Assembly.GetAssembly(type)!)
.Build();
}
}
}

5 changes: 4 additions & 1 deletion Base/src/ThingsLibrary.Testing/ThingsLibrary.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="Testcontainers" Version="3.9.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Data.Tables" Version="12.8.2" />
<PackageReference Include="Azure.Data.Tables" Version="12.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Starlight.Entity.Interfaces;
using ThingsLibrary.Entity.Interfaces;

/* Unmerged change from project 'Starlight.Entity.Tests.Integration (net6.0)'
/* Unmerged change from project 'ThingsLibrary.Entity.Tests.Integration (net6.0)'
Before:
using System.IO;
After:
using Starlight.Entity.Tests.Integration.Base.TestData;
using ThingsLibrary.Entity.Tests.Integration.Base.TestData;
using System.IO;
*/
using Starlight.Entity.Tests.Integration.Base.TestData;
using ThingsLibrary.Entity.Tests.Integration.Base.TestData;
using System.IO;
using System.Reflection;

namespace Starlight.Entity.Tests.Integration.Base
namespace ThingsLibrary.Entity.Tests.Integration.Base
{
//[ExcludeFromCodeCoverage]
//public static class BaseTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.IO;
using System.Reflection;

using Starlight.Entity.Interfaces;
using ThingsLibrary.Entity.Interfaces;

namespace Starlight.Entity.Tests.Integration.Base
namespace ThingsLibrary.Entity.Tests.Integration.Base
{
[ExcludeFromCodeCoverage]
public class EntityStoreTester<TEntity> where TEntity : class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Starlight.Entity.Tests.Integration.Base
namespace ThingsLibrary.Entity.Tests.Integration.Base
{
public interface IBaseTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Org.BouncyCastle.Bcpg.OpenPgp;
using Starlight.Attributes;
using ThingsLibrary.Attributes;

namespace Starlight.Entity.Tests.Integration.Base.TestData
namespace ThingsLibrary.Entity.Tests.Integration.Base.TestData
{
//[ExcludeFromCodeCoverage]
//public class TestData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Base\src\Starlight.Testing\Starlight.Testing.csproj" />
<ProjectReference Include="..\..\src\Starlight.Entity\Starlight.Entity.csproj" />
<ProjectReference Include="..\..\src\ThingsLibrary.Entity\ThingsLibrary.Entity.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.2" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
51 changes: 0 additions & 51 deletions Storage/src/ThingsLibrary.Storage.Aws/CloudFile.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ThingsLibrary.Storage.Aws.Extensions
{
public static class CloudFileExtensions
{
public static CloudFile ToCloudFile(this GetObjectResponse awsObj)
public static FileItem ToCloudFile(this GetObjectResponse awsObj)
{
throw new NotImplementedException();
}
Expand Down
6 changes: 3 additions & 3 deletions Storage/src/ThingsLibrary.Storage.Aws/FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void OnTransferComplete(Exception error, bool cancelled)

#region --- File ---

public ICloudFile GetFile(string cloudFilePath)
public IFileItem GetFile(string cloudFilePath)
{
try
{
Expand All @@ -151,12 +151,12 @@ public ICloudFile GetFile(string cloudFilePath)
}
}

public IEnumerable<ICloudFile> GetFileVersions(string cloudFilePath)
public IEnumerable<IFileItem> GetFileVersions(string cloudFilePath)
{
throw new NotImplementedException();
}

public IEnumerable<ICloudFile> GetFiles(string cloudFolderPath)
public IEnumerable<IFileItem> GetFiles(string cloudFolderPath)
{
throw new NotImplementedException();
}
Expand Down
8 changes: 3 additions & 5 deletions Storage/src/ThingsLibrary.Storage.Aws/FileStores.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ThingsLibrary.Storage.Interfaces;

namespace ThingsLibrary.Storage.Aws
namespace ThingsLibrary.Storage.Aws
{
public class FileStores : IFileStores
{
Expand All @@ -19,9 +17,9 @@ public FileStores(string storageConnectionString)
}

/// <inheritdoc />
public IFileStore GetStore(string name)
public IFileStore GetStore(string bucketName)
{
return new FileStore(this.StorageConnectionString, name);
return new FileStore(this.StorageConnectionString, bucketName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,26 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

<IsPackable>true</IsPackable>
</PropertyGroup>

<PropertyGroup>
<PackageId>ThingsLibrary.Cloud.File.Aws</PackageId>
<ProductName>ThingsLibrary.Cloud.File.Aws</ProductName>
<Title>Cloud File AWS Framework Library</Title>
<PackageId>ThingsLibrary.Storage.Aws</PackageId>
<ProductName>ThingsLibrary.Storage.Aws</ProductName>
<Title>AWS Storage Framework Library</Title>
<Description>This is the shared library</Description>

<Authors>Mark Lanning</Authors>
<Company>Starlight Software Co.</Company>
</PropertyGroup>

<ItemGroup>
<Compile Remove="CloudFile.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.400.3" />
<PackageReference Include="AWSSDK.S3" Version="3.7.402" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ThingsLibrary.Storage\ThingsLibrary.Storage.csproj" />
<ProjectReference Include="..\ThingsLibrary.Storage\ThingsLibrary.Storage.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace ThingsLibrary.Storage.Azure.Extensions
{
public static class CloudFileExtensions
{
public static CloudFile ToCloudFile(this BlobItem blob)
public static FileItem ToCloudFile(this BlobItem blob)
{
var item = new CloudFile(blob.Name)
var item = new FileItem(blob.Name)
{
Attributes =
{
Expand All @@ -25,19 +25,19 @@ public static CloudFile ToCloudFile(this BlobItem blob)
{ "content_type", blob.Properties.ContentType },
{ "content_md5", (blob.Properties.ContentHash != null ? Convert.ToBase64String(blob.Properties.ContentHash) : null) },
{ "content_etag", blob.Properties.ETag.ToString() },

{ "created", blob.Properties.CreatedOn },
{ "updated", blob.Properties.LastModified }
});
});
}

return item;
}

public static CloudFile ToCloudFile(this BlobClient fromEntity)
public static FileItem ToCloudFile(this BlobClient fromEntity)
{
var item = new CloudFile(fromEntity.Name);
var item = new FileItem(fromEntity.Name);

var response = fromEntity.GetProperties();
if (response != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static IServiceCollection AddFileStores(this IServiceCollection services,
var fileStores = new FileStores(connectionString);

// Register lib services here...
services.AddSingleton<ICloudFileStores>(fileStores);
services.AddSingleton<IFileStores>(fileStores);

return services;
}
Expand Down
10 changes: 5 additions & 5 deletions Storage/src/ThingsLibrary.Storage.Azure/FileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace ThingsLibrary.Storage.Azure
{
public class FileStore : ICloudFileStore
public class FileStore : IFileStore
{
#region --- Transfer Events ---

Expand Down Expand Up @@ -51,7 +51,7 @@ private void OnTransferComplete(Exception error, bool cancelled)
public string BucketName { get; private set; }

/// <inheritdoc/>
public CloudFileStoreType StorageType { get; init; } = CloudFileStoreType.Azure_Blob;
public FileStoreType StorageType { get; init; } = FileStoreType.Azure_Blob;

/// <inheritdoc/>
public bool IsVersioning { get; set; } = false;
Expand Down Expand Up @@ -117,7 +117,7 @@ private void Init(BlobServiceClient blobServiceClient, string bucketName)

#region --- File ---

public ICloudFile GetFile(string cloudFilePath)
public IFileItem GetFile(string cloudFilePath)
{
Log.Debug("Getting File: '{CloudFilePath}'...", cloudFilePath);

Expand All @@ -129,7 +129,7 @@ public ICloudFile GetFile(string cloudFilePath)
return blobClient.ToCloudFile();
}

public IEnumerable<ICloudFile> GetFileVersions(string cloudFilePath)
public IEnumerable<IFileItem> GetFileVersions(string cloudFilePath)
{
Log.Debug("Getting File Versions: '{CloudFilePath}'...", cloudFilePath);

Expand All @@ -139,7 +139,7 @@ public IEnumerable<ICloudFile> GetFileVersions(string cloudFilePath)
return blobs.Select(x => x.ToCloudFile());
}

public IEnumerable<ICloudFile> GetFiles(string cloudFolderPath)
public IEnumerable<IFileItem> GetFiles(string cloudFolderPath)
{
// tack it on if it is missing
if (!string.IsNullOrEmpty(cloudFolderPath) && !cloudFolderPath.EndsWith("/"))
Expand Down
Loading

0 comments on commit f6e481b

Please sign in to comment.