public async Task Should_add_assets_id_and_versions_as_dependency() { var doc1 = CreateAsset(DomainId.NewGuid(), 3, AssetType.Unknown, "Document1.docx"); var doc2 = CreateAsset(DomainId.NewGuid(), 4, AssetType.Unknown, "Document2.docx"); var contents = new[] { CreateContent( new[] { doc1.Id }, new[] { doc1.Id }), CreateContent( new[] { doc2.Id }, new[] { doc2.Id }) }; A.CallTo(() => assetQuery.QueryAsync( A <Context> .That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A <Q> .That.HasIds(doc1.Id, doc2.Id), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(4, doc1, doc2)); await sut.EnrichAsync(requestContext, contents, schemaProvider, default); A.CallTo(() => requestCache.AddDependency(doc1.UniqueId, doc1.Version)) .MustHaveHappened(); A.CallTo(() => requestCache.AddDependency(doc2.UniqueId, doc2.Version)) .MustHaveHappened(); }
public async Task Should_add_assets_id_and_versions_as_dependency() { var image1 = CreateAsset(Guid.NewGuid(), 1, true); var image2 = CreateAsset(Guid.NewGuid(), 2, true); var document1 = CreateAsset(Guid.NewGuid(), 3, false); var document2 = CreateAsset(Guid.NewGuid(), 4, false); var source = new IContentEntity[] { CreateContent( new[] { document1.Id, image1.Id }, new[] { document1.Id }), CreateContent( new[] { document1.Id }, new[] { document2.Id, image2.Id }) }; A.CallTo(() => assetQuery.QueryAsync(A <Context> .That.Matches(x => x.IsNoAssetEnrichment()), A <Q> .That.Matches(x => x.Ids.Count == 4))) .Returns(ResultList.CreateFrom(4, image1, image2, document1, document2)); var enriched = await sut.EnrichAsync(source, requestContext); var enriched1 = enriched.ElementAt(0); Assert.Contains(image1.Id, enriched1.CacheDependencies); Assert.Contains(image1.Version, enriched1.CacheDependencies); var enriched2 = enriched.ElementAt(1); Assert.Contains(image2.Id, enriched2.CacheDependencies); Assert.Contains(image2.Version, enriched2.CacheDependencies); }
public async Task Should_add_assets_id_and_versions_as_dependency() { var document1 = CreateAsset(Guid.NewGuid(), 3, AssetType.Unknown, "Document1.docx"); var document2 = CreateAsset(Guid.NewGuid(), 4, AssetType.Unknown, "Document2.docx"); var contents = new[] { CreateContent( new[] { document1.Id }, new[] { document1.Id }), CreateContent( new[] { document2.Id }, new[] { document2.Id }) }; A.CallTo(() => assetQuery.QueryAsync(A <Context> .That.Matches(x => !x.ShouldEnrichAsset()), null, A <Q> .That.Matches(x => x.Ids.Count == 2))) .Returns(ResultList.CreateFrom(4, document1, document2)); await sut.EnrichAsync(requestContext, contents, schemaProvider); A.CallTo(() => requestCache.AddDependency(document1.Id, document1.Version)) .MustHaveHappened(); A.CallTo(() => requestCache.AddDependency(document2.Id, document2.Version)) .MustHaveHappened(); }
public virtual async Task <IResultList <IEnrichedAssetEntity> > QueryAssetsAsync(Q q) { IResultList <IEnrichedAssetEntity> assets; await maxRequests.WaitAsync(); try { assets = await assetQuery.QueryAsync(Context, null, q); } finally { maxRequests.Release(); } foreach (var asset in assets) { cachedAssets[asset.Id] = asset; } return(assets); }
private (ScriptVars, IAssetEntity) SetupAssetVars(int fileSize = 100) { var assetId = DomainId.NewGuid(); var asset = CreateAsset(assetId, 1, fileSize); var user = new ClaimsPrincipal(); var data = new ContentData() .AddField("assets", new ContentFieldData() .AddInvariant(JsonValue.Array(assetId))); A.CallTo(() => assetQuery.QueryAsync( A <Context> .That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A <Q> .That.HasIds(assetId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(2, asset)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; return(vars, asset); }
public async Task <IActionResult> GetAssets(string app, [FromQuery] Guid?parentId, [FromQuery] string?ids = null, [FromQuery] string?q = null) { var assets = await assetQuery.QueryAsync(Context, parentId, Q.Empty .WithIds(ids) .WithJsonQuery(q) .WithODataQuery(Request.QueryString.ToString())); var response = Deferred.Response(() => { return(AssetsDto.FromAssets(assets, this, app)); }); return(Ok(response)); }
public async Task Should_resolve_asset() { var assetId1 = DomainId.NewGuid(); var asset1 = CreateAsset(assetId1, 1); var user = new ClaimsPrincipal(); var data = new ContentData() .AddField("assets", new ContentFieldData() .AddInvariant(JsonValue.Array(assetId1))); A.CallTo(() => assetQuery.QueryAsync( A <Context> .That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A <Q> .That.HasIds(assetId1))) .Returns(ResultList.CreateFrom(1, asset1)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; var script = @" getAsset(data.assets.iv[0], function (assets) { var result1 = `Text: ${assets[0].fileName}`; complete(`${result1}`); })"; var expected = @" Text: file1.jpg "; var result = (await sut.ExecuteAsync(vars, script)).ToString(); Assert.Equal(Cleanup(expected), Cleanup(result)); }
public virtual async Task <IResultList <IEnrichedAssetEntity> > QueryAssetsAsync(string odata) { var q = Q.Empty.WithODataQuery(odata); IResultList <IEnrichedAssetEntity> assets; await maxRequests.WaitAsync(); try { assets = await assetQuery.QueryAsync(context, null, q); } finally { maxRequests.Release(); } foreach (var asset in assets) { cachedAssets[asset.Id] = asset; } return(assets); }
private async Task <ILookup <DomainId, IEnrichedAssetEntity> > GetAssetsAsync(Context context, HashSet <DomainId> ids) { if (ids.Count == 0) { return(EmptyAssets); } var queryContext = context.Clone(b => b .WithoutAssetEnrichment(true) .WithoutTotal()); var assets = await assetQuery.QueryAsync(queryContext, null, Q.Empty.WithIds(ids)); return(assets.ToLookup(x => x.Id)); }
public async Task <IActionResult> GetAssets(string app, [FromQuery] string ids = null) { var context = Context(); var assets = await assetQuery.QueryAsync(context, Q.Empty.WithODataQuery(Request.QueryString.ToString()).WithIds(ids)); var response = AssetsDto.FromAssets(assets); if (controllerOptions.Value.EnableSurrogateKeys && response.Items.Length <= controllerOptions.Value.MaxItemsForSurrogateKeys) { Response.Headers["Surrogate-Key"] = response.Items.ToSurrogateKeys(); } Response.Headers["ETag"] = response.Items.ToManyEtag(response.Total); return(Ok(response)); }
public async Task <IActionResult> GetAssets(string app, [FromQuery] string ids = null) { var assets = await assetQuery.QueryAsync(Context, Q.Empty.WithODataQuery(Request.QueryString.ToString()).WithIds(ids)); var response = Deferred.Response(() => { return(AssetsDto.FromAssets(assets, this, app)); }); if (controllerOptions.EnableSurrogateKeys && assets.Count <= controllerOptions.MaxItemsForSurrogateKeys) { Response.Headers["Surrogate-Key"] = assets.ToSurrogateKeys(); } Response.Headers[HeaderNames.ETag] = assets.ToEtag(); return(Ok(response)); }