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