|
|
|
@ -14,11 +14,16 @@ namespace Squidex.Infrastructure.Assets |
|
|
|
{ |
|
|
|
public abstract class AssetStoreTests<T> : IDisposable where T : IAssetStore |
|
|
|
{ |
|
|
|
private readonly MemoryStream assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|
|
|
private readonly string assetId = Guid.NewGuid().ToString(); |
|
|
|
private readonly string tempId = Guid.NewGuid().ToString(); |
|
|
|
private readonly Lazy<T> sut; |
|
|
|
|
|
|
|
protected AssetStoreTests() |
|
|
|
{ |
|
|
|
sut = new Lazy<T>(CreateStore); |
|
|
|
|
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
} |
|
|
|
|
|
|
|
protected T Sut |
|
|
|
@ -33,27 +38,18 @@ namespace Squidex.Infrastructure.Assets |
|
|
|
[Fact] |
|
|
|
public virtual Task Should_throw_exception_if_asset_to_download_is_not_found() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
|
|
|
|
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.DownloadAsync(Id(), 1, "suffix", new MemoryStream())); |
|
|
|
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.DownloadAsync(assetId, 1, "suffix", new MemoryStream())); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public Task Should_throw_exception_if_asset_to_copy_is_not_found() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
|
|
|
|
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.CopyAsync(Id(), Id(), 1, null)); |
|
|
|
return Assert.ThrowsAsync<AssetNotFoundException>(() => Sut.CopyAsync(tempId, assetId, 1, null)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_read_and_write_file() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
|
|
|
|
var assetId = Id(); |
|
|
|
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|
|
|
|
|
|
|
await Sut.UploadAsync(assetId, 1, "suffix", assetData); |
|
|
|
|
|
|
|
var readData = new MemoryStream(); |
|
|
|
@ -64,15 +60,16 @@ namespace Squidex.Infrastructure.Assets |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public virtual async Task Should_commit_temporary_file() |
|
|
|
public async Task Should_throw_exception_when_file_to_write_already_exists() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
|
|
|
|
var tempId = Id(); |
|
|
|
await Sut.UploadAsync(assetId, 1, "suffix", assetData); |
|
|
|
|
|
|
|
var assetId = Id(); |
|
|
|
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|
|
|
await Assert.ThrowsAsync<AssetAlreadyExistsException>(() => Sut.UploadAsync(assetId, 1, "suffix", assetData)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public virtual async Task Should_read_and_write_temporary_file() |
|
|
|
{ |
|
|
|
await Sut.UploadAsync(tempId, assetData); |
|
|
|
await Sut.CopyAsync(tempId, assetId, 1, "suffix"); |
|
|
|
|
|
|
|
@ -84,14 +81,26 @@ namespace Squidex.Infrastructure.Assets |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_ignore_when_deleting_twice_by_name() |
|
|
|
public async Task Should_throw_exception_when_temporary_file_to_write_already_exists() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
await Sut.UploadAsync(tempId, assetData); |
|
|
|
await Sut.CopyAsync(tempId, assetId, 1, "suffix"); |
|
|
|
|
|
|
|
var tempId = Id(); |
|
|
|
await Assert.ThrowsAsync<AssetAlreadyExistsException>(() => Sut.UploadAsync(tempId, assetData)); |
|
|
|
} |
|
|
|
|
|
|
|
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|
|
|
[Fact] |
|
|
|
public async Task Should_throw_exception_when_target_file_to_copy_to_already_exists() |
|
|
|
{ |
|
|
|
await Sut.UploadAsync(tempId, assetData); |
|
|
|
await Sut.CopyAsync(tempId, assetId, 1, "suffix"); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<AssetAlreadyExistsException>(() => Sut.CopyAsync(tempId, assetId, 1, "suffix")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_ignore_when_deleting_twice_by_name() |
|
|
|
{ |
|
|
|
await Sut.UploadAsync(tempId, assetData); |
|
|
|
await Sut.DeleteAsync(tempId); |
|
|
|
await Sut.DeleteAsync(tempId); |
|
|
|
@ -100,20 +109,9 @@ namespace Squidex.Infrastructure.Assets |
|
|
|
[Fact] |
|
|
|
public async Task Should_ignore_when_deleting_twice_by_id() |
|
|
|
{ |
|
|
|
((IInitializable)Sut).Initialize(); |
|
|
|
|
|
|
|
var tempId = Id(); |
|
|
|
|
|
|
|
var assetData = new MemoryStream(new byte[] { 0x1, 0x2, 0x3, 0x4 }); |
|
|
|
|
|
|
|
await Sut.UploadAsync(tempId, 0, null, assetData); |
|
|
|
await Sut.DeleteAsync(tempId, 0, null); |
|
|
|
await Sut.DeleteAsync(tempId, 0, null); |
|
|
|
} |
|
|
|
|
|
|
|
protected static string Id() |
|
|
|
{ |
|
|
|
return Guid.NewGuid().ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|