public void Should_copy_with_id_and_version() { sut.CopyAsync(fileName, id, 1, string.Empty); A.CallTo(() => sut.CopyAsync(fileName, $"{id}_1", default)) .MustHaveHappened(); }
private void SetupStore(long version, Guid commitId) { A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), stream, CancellationToken.None)) .Returns(TaskHelper.Done); A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), assetId.ToString(), version, null, CancellationToken.None)) .Returns(TaskHelper.Done); A.CallTo(() => assetStore.DeleteAsync(commitId.ToString())) .Returns(TaskHelper.Done); }
public async override Task HandleAsync(CommandContext context, Func <Task> next) { switch (context.Command) { case CreateAsset createAsset: { createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead()); await assetStore.UploadAsync(context.ContextId.ToString(), createAsset.File.OpenRead()); try { var result = await ExecuteCommandAsync(createAsset) as AssetSavedResult; context.Complete(EntityCreatedResult.Create(createAsset.AssetId, result.Version)); await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } case UpdateAsset updateAsset: { updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead()); await assetStore.UploadAsync(context.ContextId.ToString(), updateAsset.File.OpenRead()); try { var result = await ExecuteCommandAsync(updateAsset) as AssetSavedResult; context.Complete(result); await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } default: await base.HandleAsync(context, next); break; } }
public Task CopyAsync(string tempFile, DomainId appId, DomainId id, long fileVersion, CancellationToken ct = default) { var fileName = GetFileName(appId, id, fileVersion); return(assetStore.CopyAsync(tempFile, fileName, ct)); }
public async Task Should_invoke_asset_store_to_copy_from_temporary_file() { await sut.CopyAsync("Temp", assetId, assetFileVersion); A.CallTo(() => assetStore.CopyAsync("Temp", fileName, CancellationToken.None)) .MustHaveHappened(); }
private void AssertAssetHasBeenUploaded(long version, Guid commitId) { A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), stream, CancellationToken.None)) .MustHaveHappened(); A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), assetId.ToString(), version, null, CancellationToken.None)) .MustHaveHappened(); A.CallTo(() => assetStore.DeleteAsync(commitId.ToString())) .MustHaveHappened(); }
private void AssertAssetHasBeenUploaded(long version, Guid commitId) { var fileName = AssetStoreExtensions.GetFileName(assetId.ToString(), version); A.CallTo(() => assetStore.UploadAsync(commitId.ToString(), A <HasherStream> .Ignored, false, CancellationToken.None)) .MustHaveHappened(); A.CallTo(() => assetStore.CopyAsync(commitId.ToString(), fileName, CancellationToken.None)) .MustHaveHappened(); A.CallTo(() => assetStore.DeleteAsync(commitId.ToString())) .MustHaveHappened(); }
public override async Task HandleAsync(CommandContext context, Func <Task> next) { switch (context.Command) { case CreateAsset createAsset: { if (createAsset.Tags == null) { createAsset.Tags = new HashSet <string>(); } createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead()); foreach (var tagGenerator in tagGenerators) { tagGenerator.GenerateTags(createAsset, createAsset.Tags); } var originalTags = new HashSet <string>(createAsset.Tags); await assetStore.UploadAsync(context.ContextId.ToString(), createAsset.File.OpenRead()); try { var result = await ExecuteCommandAsync(createAsset) as AssetSavedResult; context.Complete(new AssetCreatedResult(createAsset.AssetId, originalTags, result.Version)); await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } case UpdateAsset updateAsset: { updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead()); await assetStore.UploadAsync(context.ContextId.ToString(), updateAsset.File.OpenRead()); try { var result = await ExecuteCommandAsync(updateAsset) as AssetSavedResult; context.Complete(result); await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } default: await base.HandleAsync(context, next); break; } }
public override async Task HandleAsync(CommandContext context, Func <Task> next) { switch (context.Command) { case CreateAsset createAsset: { if (createAsset.Tags == null) { createAsset.Tags = new HashSet <string>(); } createAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(createAsset.File.OpenRead()); createAsset.FileHash = await UploadAsync(context, createAsset.File); try { var existings = await assetQuery.QueryByHashAsync(createAsset.AppId.Id, createAsset.FileHash); AssetCreatedResult result = null; foreach (var existing in existings) { if (IsDuplicate(createAsset, existing)) { result = new AssetCreatedResult( existing.Id, existing.Tags, existing.Version, existing.FileVersion, existing.FileHash, true); } break; } if (result == null) { foreach (var tagGenerator in tagGenerators) { tagGenerator.GenerateTags(createAsset, createAsset.Tags); } var commandResult = (AssetSavedResult) await ExecuteCommandAsync(createAsset); result = new AssetCreatedResult( createAsset.AssetId, createAsset.Tags, commandResult.Version, commandResult.FileVersion, commandResult.FileHash, false); await assetStore.CopyAsync(context.ContextId.ToString(), createAsset.AssetId.ToString(), result.FileVersion, null); } context.Complete(result); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } case UpdateAsset updateAsset: { updateAsset.ImageInfo = await assetThumbnailGenerator.GetImageInfoAsync(updateAsset.File.OpenRead()); updateAsset.FileHash = await UploadAsync(context, updateAsset.File); try { var result = (AssetSavedResult) await ExecuteCommandAsync(updateAsset); context.Complete(result); await assetStore.CopyAsync(context.ContextId.ToString(), updateAsset.AssetId.ToString(), result.FileVersion, null); } finally { await assetStore.DeleteAsync(context.ContextId.ToString()); } break; } default: await base.HandleAsync(context, next); break; } }
public static Task CopyAsync(this IAssetStore store, string sourceFileName, string id, long version, string suffix, CancellationToken ct = default) { return(store.CopyAsync(sourceFileName, GetFileName(id, version, suffix), ct)); }
public override async Task HandleAsync(CommandContext context, Func <Task> next) { var tempFile = context.ContextId.ToString(); switch (context.Command) { case CreateAsset createAsset: { await EnrichWithImageInfosAsync(createAsset); await EnrichWithHashAndUploadAsync(createAsset, tempFile); try { var existings = await assetQuery.QueryByHashAsync(createAsset.AppId.Id, createAsset.FileHash); foreach (var existing in existings) { if (IsDuplicate(existing, createAsset.File)) { var result = new AssetCreatedResult(existing, true); context.Complete(result); await next(); return; } } GenerateTags(createAsset); await HandleCoreAsync(context, next); var asset = context.Result <IEnrichedAssetEntity>(); context.Complete(new AssetCreatedResult(asset, false)); await assetStore.CopyAsync(tempFile, createAsset.AssetId.ToString(), asset.FileVersion, null); } finally { await assetStore.DeleteAsync(tempFile); } break; } case UpdateAsset updateAsset: { await EnrichWithImageInfosAsync(updateAsset); await EnrichWithHashAndUploadAsync(updateAsset, tempFile); try { await HandleCoreAsync(context, next); var asset = context.Result <IEnrichedAssetEntity>(); await assetStore.CopyAsync(tempFile, updateAsset.AssetId.ToString(), asset.FileVersion, null); } finally { await assetStore.DeleteAsync(tempFile); } break; } default: await HandleCoreAsync(context, next); break; } }
public static Task CopyAsync(this IAssetStore store, string sourceFileName, Guid id, long version, string?suffix, CancellationToken ct = default) { return(store.CopyAsync(sourceFileName, id.ToString(), version, suffix, ct)); }