Browse Source

Fixing GraphQl Tests

pull/235/head
Derek Begnoche 8 years ago
parent
commit
fe3629c1c5
  1. 13
      src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs
  2. 2
      src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs
  3. 2
      src/Squidex.Domain.Apps.Entities/Contents/QueryContext.cs
  4. 6
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs

13
src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OData;
@ -64,6 +65,18 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
return ResultList.Create(assetEntities.OfType<IAssetEntity>().ToList(), assetCount);
}
public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, HashSet<Guid> ids)
{
var find = Collection
.Find(Filter.In(x => x.Id, ids))
.SortByDescending(x => x.LastModified);
var assetEntities = await find.ToListAsync();
var assetCount = await find.CountAsync();
return ResultList.Create(assetEntities.OfType<IAssetEntity>().ToList(), assetCount);
}
public async Task<IAssetEntity> FindAssetAsync(Guid id)
{
var assetEntity =

2
src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs

@ -16,6 +16,8 @@ namespace Squidex.Domain.Apps.Entities.Assets.Repositories
{
Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, string query = null);
Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, HashSet<Guid> ids);
Task<IAssetEntity> FindAssetAsync(Guid id);
}
}

2
src/Squidex.Domain.Apps.Entities/Contents/QueryContext.cs

@ -112,7 +112,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
if (notLoadedAssets.Count > 0)
{
var assets = await assetRepository.QueryAsync(app.Id, null);
var assets = await assetRepository.QueryAsync(app.Id, notLoadedAssets);
foreach (var asset in assets)
{

6
tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs

@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
var assets = new List<IAssetEntity> { asset };
A.CallTo(() => assetRepository.QueryAsync(app.Id, null))
A.CallTo(() => assetRepository.QueryAsync(app.Id, "?$take=30&$skip=5&$search=my-query"))
.Returns(ResultList.Create(assets, 0));
var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query });
@ -134,7 +134,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
var assets = new List<IAssetEntity> { asset };
A.CallTo(() => assetRepository.QueryAsync(app.Id, "my-query"))
A.CallTo(() => assetRepository.QueryAsync(app.Id, "?$take=30&$skip=5&$search=my-query"))
.Returns(ResultList.Create(assets, 10));
var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query });
@ -667,7 +667,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
A.CallTo(() => contentQuery.FindContentAsync(app, schema.Id.ToString(), user, contentId, EtagVersion.Any))
.Returns((schema, content));
A.CallTo(() => assetRepository.QueryAsync(app.Id, A<string>.That.Matches(x => x.Contains(assetRef.Id.ToString()))))
A.CallTo(() => assetRepository.QueryAsync(app.Id, A<HashSet<Guid>>.That.Matches(x => x.Contains(assetRefId))))
.Returns(ResultList.Create(refAssets, 0));
var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query });

Loading…
Cancel
Save