public async Task Should_enrich_asset_with_tag_names() { var source = new AssetEntity { Tags = new HashSet <string> { "id1", "id2" }, AppId = appId }; A.CallTo(() => tagService.DenormalizeTagsAsync(appId.Id, TagGroups.Assets, A <HashSet <string> > .That.IsSameSequenceAs("id1", "id2"))) .Returns(new Dictionary <string, string> { ["id1"] = "name1", ["id2"] = "name2" }); var result = await sut.EnrichAsync(source); Assert.Equal(new HashSet <string> { "name1", "name2" }, result.TagNames); }
public async Task Should_load_assets_with_query_and_resolve_tags() { var found1 = new AssetEntity { Id = Guid.NewGuid() }; var found2 = new AssetEntity { Id = Guid.NewGuid() }; var enriched1 = new AssetEntity(); var enriched2 = new AssetEntity(); A.CallTo(() => assetRepository.QueryAsync(appId.Id, A <Query> .Ignored)) .Returns(ResultList.CreateFrom(8, found1, found2)); A.CallTo(() => assetEnricher.EnrichAsync(A <IEnumerable <IAssetEntity> > .That.IsSameSequenceAs(found1, found2))) .Returns(new List <IEnrichedAssetEntity> { enriched1, enriched2 }); var result = await sut.QueryAsync(context, Q.Empty); Assert.Equal(8, result.Total); Assert.Equal(new[] { enriched1, enriched2 }, result.ToArray()); }
public async Task Should_load_assets_from_ids_and_resolve_tags() { var found1 = new AssetEntity { Id = Guid.NewGuid() }; var found2 = new AssetEntity { Id = Guid.NewGuid() }; var enriched1 = new AssetEntity(); var enriched2 = new AssetEntity(); var ids = HashSet.Of(found1.Id, found2.Id); A.CallTo(() => assetRepository.QueryAsync(appId.Id, A <HashSet <Guid> > .That.IsSameSequenceAs(ids))) .Returns(ResultList.CreateFrom(8, found1, found2)); A.CallTo(() => assetEnricher.EnrichAsync(A <IEnumerable <IAssetEntity> > .That.IsSameSequenceAs(found1, found2))) .Returns(new List <IEnrichedAssetEntity> { enriched1, enriched2 }); var result = await sut.QueryAsync(requestContext, Q.Empty.WithIds(ids)); Assert.Equal(8, result.Total); Assert.Equal(new[] { enriched1, enriched2 }, result.ToArray()); }
public void Should_always_format_to_empty() { var source = new AssetEntity(); var formatted = sut.Format(source); Assert.Empty(formatted); }
public void Should_format_to_empty_if_not_an_image() { var source = new AssetEntity(); var formatted = sut.Format(source); Assert.Empty(formatted); }
public async Task Should_not_enrich_if_asset_contains_null_tags() { var source = new AssetEntity { AppId = appId }; var result = await sut.EnrichAsync(source); Assert.Empty(result.TagNames); }
public void Should_not_format_audio() { var source = new AssetEntity { Type = AssetType.Audio }; var formatted = sut.Format(source); Assert.Empty(formatted); }
private void SetupSameHashAsset(string fileName, long fileSize, out IEnrichedAssetEntity duplicate) { duplicate = new AssetEntity { FileName = fileName, FileSize = fileSize }; A.CallTo(() => assetQuery.FindByHashAsync(requestContext, A <string> ._, fileName, fileSize)) .Returns(duplicate); }
private void SetupSameHashAsset(string fileName, long fileSize, out IEnrichedAssetEntity duplicate) { duplicate = new AssetEntity { FileName = fileName, FileSize = fileSize }; A.CallTo(() => assetQuery.QueryByHashAsync(A <Context> .That.Matches(x => !x.ShouldEnrichAsset()), A <Guid> .Ignored, A <string> .Ignored)) .Returns(new List <IEnrichedAssetEntity> { duplicate }); }
public void Should_format_with_dimensions_if_image() { var source = new AssetEntity { Metadata = new AssetMetadata() .SetPixelWidth(800) .SetPixelHeight(600), Type = AssetType.Image }; var formatted = sut.Format(source).First(); Assert.Equal("800x600px", formatted); }
public void Should_format_audio() { var source = new AssetEntity { Metadata = new AssetMetadata { ["duration"] = JsonValue.Create("00:10:12") }, Type = AssetType.Audio }; var formatted = sut.Format(source); Assert.Equal(new[] { "00:10:12" }, formatted.ToArray()); }
public async Task Should_not_invoke_enricher_if_already_enriched() { var result = new AssetEntity(); var command = CreateCommand(new MyCommand()); var context = CreateContextForCommand(command); context.Complete(result); await sut.HandleAsync(context); Assert.Same(result, context.Result <IEnrichedAssetEntity>()); A.CallTo(() => assetEnricher.EnrichAsync(A <IEnrichedAssetEntity> .Ignored, requestContext)) .MustNotHaveHappened(); }
public void Should_format_image() { var source = new AssetEntity { Metadata = new AssetMetadata { ["pixelWidth"] = JsonValue.Create(128), ["pixelHeight"] = JsonValue.Create(55) }, Type = AssetType.Image }; var formatted = sut.Format(source); Assert.Equal(new[] { "128x55px" }, formatted); }
public void Should_format_video() { var source = new AssetEntity { Metadata = new AssetMetadata { ["videoWidth"] = JsonValue.Create(128), ["videoHeight"] = JsonValue.Create(55), ["duration"] = JsonValue.Create("00:10:12") }, Type = AssetType.Video }; var formatted = sut.Format(source); Assert.Equal(new[] { "128x55pt", "00:10:12" }, formatted); }
public async Task Should_enrich_asset_result() { var result = A.Fake <IAssetEntity>(); var command = CreateCommand(new MyCommand()); var context = CreateContextForCommand(command); context.Complete(result); var enriched = new AssetEntity(); A.CallTo(() => assetEnricher.EnrichAsync(result, requestContext)) .Returns(enriched); await sut.HandleAsync(context); Assert.Same(enriched, context.Result <IEnrichedAssetEntity>()); }
public async Task Should_find_asset_by_id_and_enrich_it() { var found = new AssetEntity { Id = Guid.NewGuid() }; var enriched = new AssetEntity(); A.CallTo(() => assetRepository.FindAssetAsync(found.Id, false)) .Returns(found); A.CallTo(() => assetEnricher.EnrichAsync(found)) .Returns(enriched); var result = await sut.FindAssetAsync(found.Id); Assert.Same(enriched, result); }
public async Task Should_find_assets_by_hash_and_and_enrich_it() { var found = new AssetEntity { Id = Guid.NewGuid() }; var enriched = new AssetEntity(); A.CallTo(() => assetRepository.QueryByHashAsync(appId.Id, "hash")) .Returns(new List <IAssetEntity> { found }); A.CallTo(() => assetEnricher.EnrichAsync(A <IEnumerable <IAssetEntity> > .That.IsSameSequenceAs(found))) .Returns(new List <IEnrichedAssetEntity> { enriched }); var result = await sut.QueryByHashAsync(appId.Id, "hash"); Assert.Same(enriched, result.Single()); }