|
|
@ -9,9 +9,9 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using FakeItEasy; |
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Moq; |
|
|
|
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Newtonsoft.Json.Linq; |
|
|
using Squidex.Domain.Apps.Core; |
|
|
using Squidex.Domain.Apps.Core; |
|
|
@ -59,32 +59,29 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
.AddOrUpdateField(new GeolocationField(9, "my-geolocation", Partitioning.Invariant, |
|
|
.AddOrUpdateField(new GeolocationField(9, "my-geolocation", Partitioning.Invariant, |
|
|
new GeolocationFieldProperties())); |
|
|
new GeolocationFieldProperties())); |
|
|
|
|
|
|
|
|
private readonly Mock<ISchemaRepository> schemaRepository = new Mock<ISchemaRepository>(); |
|
|
private readonly ISchemaRepository schemaRepository = A.Fake<ISchemaRepository>(); |
|
|
private readonly Mock<IContentRepository> contentRepository = new Mock<IContentRepository>(); |
|
|
private readonly ISchemaEntity schemaEntity = A.Fake<ISchemaEntity>(); |
|
|
private readonly Mock<IAssetRepository> assetRepository = new Mock<IAssetRepository>(); |
|
|
private readonly IContentRepository contentRepository = A.Fake<IContentRepository>(); |
|
|
private readonly IAppEntity app; |
|
|
private readonly IAssetRepository assetRepository = A.Fake<IAssetRepository>(); |
|
|
|
|
|
private readonly IAppEntity appEntity = A.Dummy<IAppEntity>(); |
|
|
private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); |
|
|
private readonly IMemoryCache cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); |
|
|
private readonly IGraphQLService sut; |
|
|
private readonly IGraphQLService sut; |
|
|
|
|
|
|
|
|
public GraphQLTests() |
|
|
public GraphQLTests() |
|
|
{ |
|
|
{ |
|
|
var appEntity = new Mock<IAppEntity>(); |
|
|
A.CallTo(() => appEntity.Id).Returns(appId); |
|
|
appEntity.Setup(x => x.Id).Returns(appId); |
|
|
A.CallTo(() => appEntity.PartitionResolver).Returns(x => InvariantPartitioning.Instance); |
|
|
appEntity.Setup(x => x.PartitionResolver).Returns(x => InvariantPartitioning.Instance); |
|
|
|
|
|
|
|
|
|
|
|
app = appEntity.Object; |
|
|
A.CallTo(() => schemaEntity.Id).Returns(schemaId); |
|
|
|
|
|
A.CallTo(() => schemaEntity.Name).Returns(schema.Name); |
|
|
|
|
|
A.CallTo(() => schemaEntity.Schema).Returns(schema); |
|
|
|
|
|
A.CallTo(() => schemaEntity.IsPublished).Returns(true); |
|
|
|
|
|
|
|
|
var schemaEntity = new Mock<ISchemaEntity>(); |
|
|
var schemas = new List<ISchemaEntity> { schemaEntity }; |
|
|
schemaEntity.Setup(x => x.Id).Returns(schemaId); |
|
|
|
|
|
schemaEntity.Setup(x => x.Name).Returns(schema.Name); |
|
|
|
|
|
schemaEntity.Setup(x => x.Schema).Returns(schema); |
|
|
|
|
|
schemaEntity.Setup(x => x.IsPublished).Returns(true); |
|
|
|
|
|
|
|
|
|
|
|
var schemas = new List<ISchemaEntity> { schemaEntity.Object }; |
|
|
A.CallTo(() => schemaRepository.QueryAllAsync(appId)).Returns(Task.FromResult<IReadOnlyList<ISchemaEntity>>(schemas)); |
|
|
|
|
|
|
|
|
schemaRepository.Setup(x => x.QueryAllAsync(appId)).Returns(Task.FromResult<IReadOnlyList<ISchemaEntity>>(schemas)); |
|
|
sut = new CachingGraphQLService(cache, schemaRepository, assetRepository, contentRepository, new FakeUrlGenerator()); |
|
|
|
|
|
|
|
|
sut = new CachingGraphQLService(cache, schemaRepository.Object, assetRepository.Object, contentRepository.Object, new FakeUrlGenerator()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -115,11 +112,10 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
|
|
|
|
|
|
var assets = new List<IAssetEntity> { assetEntity }; |
|
|
var assets = new List<IAssetEntity> { assetEntity }; |
|
|
|
|
|
|
|
|
assetRepository.Setup(x => x.QueryAsync(app.Id, null, null, "my-query", 30, 5)) |
|
|
A.CallTo(() => assetRepository.QueryAsync(appEntity.Id, null, null, "my-query", 30, 5)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IAssetEntity>>(assets)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IAssetEntity>>(assets)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -150,8 +146,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
assetRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -181,11 +175,10 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}} |
|
|
}} |
|
|
}}";
|
|
|
}}";
|
|
|
|
|
|
|
|
|
assetRepository.Setup(x => x.FindAssetAsync(assetId)) |
|
|
A.CallTo(() => assetRepository.FindAssetAsync(assetId)) |
|
|
.Returns(Task.FromResult(assetEntity)) |
|
|
.Returns(Task.FromResult(assetEntity)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -213,8 +206,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
assetRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -257,11 +248,10 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
|
|
|
|
|
|
var contents = new List<IContentEntity> { contentEntity }; |
|
|
var contents = new List<IContentEntity> { contentEntity }; |
|
|
|
|
|
|
|
|
contentRepository.Setup(x => x.QueryAsync(app, schemaId, false, null, "?$top=30&$skip=5")) |
|
|
A.CallTo(() => contentRepository.QueryAsync(appEntity, schemaId, false, null, "?$top=30&$skip=5")) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IContentEntity>>(contents)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IContentEntity>>(contents)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -318,8 +308,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
contentRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -361,11 +349,10 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}} |
|
|
}} |
|
|
}}";
|
|
|
}}";
|
|
|
|
|
|
|
|
|
contentRepository.Setup(x => x.FindContentAsync(app, schemaId, contentId)) |
|
|
A.CallTo(() => contentRepository.FindContentAsync(appEntity, schemaId, contentId)) |
|
|
.Returns(Task.FromResult(contentEntity)) |
|
|
.Returns(Task.FromResult(contentEntity)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -419,8 +406,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
contentRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -448,15 +433,13 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
|
|
|
|
|
|
var refContents = new List<IContentEntity> { contentRefEntity }; |
|
|
var refContents = new List<IContentEntity> { contentRefEntity }; |
|
|
|
|
|
|
|
|
contentRepository.Setup(x => x.FindContentAsync(app, schemaId, contentId)) |
|
|
A.CallTo(() => contentRepository.FindContentAsync(appEntity, schemaId, contentId)) |
|
|
.Returns(Task.FromResult(contentEntity)) |
|
|
.Returns(Task.FromResult(contentEntity)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
contentRepository.Setup(x => x.QueryAsync(app, schemaId, false, new HashSet<Guid> {contentRefId }, null)) |
|
|
A.CallTo(() => contentRepository.QueryAsync(appEntity, schemaId, false, A<HashSet<Guid>>.That.Matches(x => x.Contains(contentRefId)), null)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IContentEntity>>(refContents)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IContentEntity>>(refContents)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -483,8 +466,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
contentRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
@ -512,15 +493,13 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
|
|
|
|
|
|
var refAssets = new List<IAssetEntity> { assetRefEntity }; |
|
|
var refAssets = new List<IAssetEntity> { assetRefEntity }; |
|
|
|
|
|
|
|
|
contentRepository.Setup(x => x.FindContentAsync(app, schemaId, contentId)) |
|
|
A.CallTo(() => contentRepository.FindContentAsync(appEntity, schemaId, contentId)) |
|
|
.Returns(Task.FromResult(contentEntity)) |
|
|
.Returns(Task.FromResult(contentEntity)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
assetRepository.Setup(x => x.QueryAsync(app.Id, null, new HashSet<Guid> { assetRefId }, null, int.MaxValue, 0)) |
|
|
A.CallTo(() => assetRepository.QueryAsync(appEntity.Id, null, A<HashSet<Guid>>.That.Matches(x => x.Contains(assetRefId)), null, int.MaxValue, 0)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IAssetEntity>>(refAssets)) |
|
|
.Returns(Task.FromResult<IReadOnlyList<IAssetEntity>>(refAssets)); |
|
|
.Verifiable(); |
|
|
|
|
|
|
|
|
|
|
|
var result = await sut.QueryAsync(app, new GraphQLQuery { Query = query }); |
|
|
var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query }); |
|
|
|
|
|
|
|
|
var expected = new |
|
|
var expected = new |
|
|
{ |
|
|
{ |
|
|
@ -547,8 +526,6 @@ namespace Squidex.Domain.Apps.Read.Contents |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
AssertJson(expected, new { data = result.Data }); |
|
|
|
|
|
|
|
|
contentRepository.VerifyAll(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static IContentEntity CreateContent(Guid id, Guid refId, Guid assetId) |
|
|
private static IContentEntity CreateContent(Guid id, Guid refId, Guid assetId) |
|
|
|