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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ ModelManifest.xml

# FAKE - F# Make
.fake/
/tests/GeekLearning.Integration.Test/appsettings.development.json
appsettings.development.json
7 changes: 7 additions & 0 deletions src/GeekLearning.Storage/IStore{TOptions}.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GeekLearning.Storage
{
public interface IStore<TOptions> : IStore
where TOptions : class, IStorageStoreOptions, new()
{
}
}
76 changes: 76 additions & 0 deletions src/GeekLearning.Storage/Internal/GenericStoreProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
namespace GeekLearning.Storage.Internal
{
using Microsoft.Extensions.Options;
using System;
using System.IO;
using System.Threading.Tasks;

public class GenericStoreProxy<TOptions> : IStore, IStore<TOptions>
where TOptions : class, IStorageStoreOptions, new()
{
private IStore innerStore;

public GenericStoreProxy(IStorageFactory factory, IOptions<TOptions> options)
{
this.innerStore = factory.GetStore(nameof(TOptions), options.Value);
}

public string Name
{
get
{
return innerStore.Name;
}
}

public Task DeleteAsync(IPrivateFileReference file)
{
return innerStore.DeleteAsync(file);
}

public Task<IFileReference> GetAsync(Uri file, bool withMetadata)
{
return innerStore.GetAsync(file, withMetadata);
}

public Task<IFileReference> GetAsync(IPrivateFileReference file, bool withMetadata)
{
return innerStore.GetAsync(file, withMetadata);
}

public Task<IFileReference[]> ListAsync(string path, bool recursive, bool withMetadata)
{
return innerStore.ListAsync(path, recursive, withMetadata);
}

public Task<IFileReference[]> ListAsync(string path, string searchPattern, bool recursive, bool withMetadata)
{
return innerStore.ListAsync(path, searchPattern, recursive, withMetadata);
}

public Task<byte[]> ReadAllBytesAsync(IPrivateFileReference file)
{
return innerStore.ReadAllBytesAsync(file);
}

public Task<string> ReadAllTextAsync(IPrivateFileReference file)
{
return innerStore.ReadAllTextAsync(file);
}

public Task<Stream> ReadAsync(IPrivateFileReference file)
{
return innerStore.ReadAsync(file);
}

public Task<IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType)
{
return innerStore.SaveAsync(data, file, contentType);
}

public Task<IFileReference> SaveAsync(byte[] data, IPrivateFileReference file, string contentType)
{
return innerStore.SaveAsync(data, file, contentType);
}
}
}
1 change: 1 addition & 0 deletions src/GeekLearning.Storage/StorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class StorageExtensions
public static IServiceCollection AddStorage(this IServiceCollection services)
{
services.TryAddTransient<IStorageFactory, Internal.StorageFactory>();
services.TryAdd(ServiceDescriptor.Transient(typeof(IStore<>), typeof(Internal.GenericStoreProxy<>)));
return services;
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/GeekLearning.Storage.Integration.Test/GenericIStoreTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace GeekLearning.Storage.Integration.Test
{
using Microsoft.Extensions.DependencyInjection;
using Storage;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(IntegrationCollection))]
[Trait("Kind", "Integration")]
public class GenericIStoreTests
{
private StoresFixture storeFixture;

public GenericIStoreTests(StoresFixture fixture)
{
this.storeFixture = fixture;
}

[Fact]
public async Task GenericListRootFiles()
{
var store = this.storeFixture.Services.GetRequiredService<IStore<TestStore>>();

var expected = new string[] { "TextFile.txt", "template.hbs" };

var results = await store.ListAsync(null);

var missingFiles = expected.Except(results.Select(f => f.Path)).ToArray();

var unexpectedFiles = results.Select(f => f.Path).Except(expected).ToArray();

Assert.Empty(missingFiles);
Assert.Empty(unexpectedFiles);
}
}
}
6 changes: 5 additions & 1 deletion tests/GeekLearning.Storage.Integration.Test/StoresFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public StoresFixture()
{
this.BasePath = PlatformServices.Default.Application.ApplicationBasePath;

var containerId = Guid.NewGuid().ToString("N").ToLower();

var builder = new ConfigurationBuilder()
.SetBasePath(BasePath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.development.json", optional: true)
.AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("Storage:Stores:azure:Parameters:Container", Guid.NewGuid().ToString("N").ToLower())
new KeyValuePair<string, string>("Storage:Stores:azure:Parameters:Container", containerId),
new KeyValuePair<string, string>("TestStore:Parameters:Container", containerId)
});

this.Configuration = builder.Build();
Expand All @@ -40,6 +43,7 @@ public StoresFixture()
.AddFileSystemExtendedProperties(o => { });

services.Configure<StorageOptions>(Configuration.GetSection("Storage"));
services.Configure<TestStore>(Configuration.GetSection("TestStore"));

this.Services = services.BuildServiceProvider();

Expand Down
11 changes: 11 additions & 0 deletions tests/GeekLearning.Storage.Integration.Test/TestStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GeekLearning.Storage.Integration.Test
{
using System.Collections.Generic;

public class TestStore : IStorageStoreOptions
{
public string Provider { get; set; }

public Dictionary<string, string> Parameters { get; set; }
}
}

This file was deleted.

6 changes: 6 additions & 0 deletions tests/GeekLearning.Storage.Integration.Test/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
}
},
"ExtendedPropertiesFolderNameFormat": ".{0}-extended-properties"
},
"TestStore": {
"Provider": "FileSystem",
"Parameters": {
"Path": "Templates"
}
}
}