Browse Source

Fix app thumbnail store.

pull/737/head
Sebastian 5 years ago
parent
commit
acc4b1555f
  1. 17
      backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs
  2. 36
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DefaultAppImageStoreTests.cs

17
backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs

@ -8,7 +8,9 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Squidex.Assets;
using Squidex.Domain.Apps.Entities.Assets;
using Squidex.Infrastructure;
namespace Squidex.Domain.Apps.Entities.Apps
@ -16,10 +18,14 @@ namespace Squidex.Domain.Apps.Entities.Apps
public sealed class DefaultAppImageStore : IAppImageStore
{
private readonly IAssetStore assetStore;
private readonly AssetOptions options;
public DefaultAppImageStore(IAssetStore assetStore)
public DefaultAppImageStore(IAssetStore assetStore,
IOptions<AssetOptions> options)
{
this.assetStore = assetStore;
this.options = options.Value;
}
public Task DownloadAsync(DomainId appId, Stream stream,
@ -38,9 +44,16 @@ namespace Squidex.Domain.Apps.Entities.Apps
return assetStore.UploadAsync(fileName, stream, true, ct);
}
private static string GetFileName(DomainId appId)
private string GetFileName(DomainId appId)
{
if (options.FolderPerApp)
{
return $"{appId}/thumbnail";
}
else
{
return appId.ToString();
}
}
}
}

36
backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/DefaultAppImageStoreTests.cs

@ -9,7 +9,9 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using FakeItEasy;
using Microsoft.Extensions.Options;
using Squidex.Assets;
using Squidex.Domain.Apps.Entities.Assets;
using Squidex.Infrastructure;
using Xunit;
@ -19,36 +21,56 @@ namespace Squidex.Domain.Apps.Entities.Apps
{
private readonly IAssetStore assetStore = A.Fake<IAssetStore>();
private readonly DomainId appId = DomainId.NewGuid();
private readonly string fileName;
private readonly string fileNameDefault;
private readonly string fileNameFolder;
private readonly AssetOptions options = new AssetOptions();
private readonly DefaultAppImageStore sut;
public DefaultAppImageStoreTests()
{
fileName = appId.ToString();
fileNameDefault = appId.ToString();
fileNameFolder = $"{appId}/thumbnail";
sut = new DefaultAppImageStore(assetStore);
sut = new DefaultAppImageStore(assetStore, Options.Create(options));
}
[Fact]
public async Task Should_invoke_asset_store_to_upload_archive()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task Should_invoke_asset_store_to_upload_archive(bool folderPerApp)
{
var stream = new MemoryStream();
options.FolderPerApp = folderPerApp;
var fileName = GetFileName(folderPerApp);
await sut.UploadAsync(appId, stream);
A.CallTo(() => assetStore.UploadAsync(fileName, stream, true, CancellationToken.None))
.MustHaveHappened();
}
[Fact]
public async Task Should_invoke_asset_store_to_download_archive()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task Should_invoke_asset_store_to_download_archive(bool folderPerApp)
{
var stream = new MemoryStream();
options.FolderPerApp = folderPerApp;
var fileName = GetFileName(folderPerApp);
await sut.DownloadAsync(appId, stream);
A.CallTo(() => assetStore.DownloadAsync(fileName, stream, default, CancellationToken.None))
.MustHaveHappened();
}
private string GetFileName(bool folderPerApp)
{
return folderPerApp ? fileNameFolder : fileNameDefault;
}
}
}

Loading…
Cancel
Save