Browse Source

Tests fixed.

pull/715/head
Sebastian Stehle 5 years ago
parent
commit
8a81ead611
  1. 41
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHash.cs
  2. 5
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHashEntity.cs
  3. 6
      backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs
  4. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs
  5. 2
      backend/src/Squidex.Domain.Apps.Entities/Contents/ReferencesJintExtension.cs
  6. 2
      backend/src/Squidex.Domain.Apps.Entities/Schemas/ISchemasHash.cs
  7. 7
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterCompareTests.cs
  8. 7
      backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs
  9. 7
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs
  10. 3
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Counter/CounterJintExtensionTests.cs
  11. 9
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DynamicContentWorkflowTests.cs
  12. 7
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs
  13. 4
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerTests_Mongo.cs
  14. 7
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/MongoDb/SchemasHashTests.cs
  15. 4
      backend/tests/Squidex.Infrastructure.Tests/EventSourcing/EventStoreTests.cs

41
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHash.cs

@ -39,7 +39,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
public string EventsFilter public string EventsFilter
{ {
get => "^(app-|schema-)"; get => "^schema-";
} }
public MongoSchemasHash(IMongoDatabase database, bool setup = false) public MongoSchemasHash(IMongoDatabase database, bool setup = false)
@ -63,30 +63,17 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
continue; continue;
} }
switch (@event.Payload) if (@event.Payload is SchemaEvent schemaEvent)
{ {
case SchemaEvent schemaEvent: writes.Add(
new UpdateOneModel<MongoSchemasHashEntity>(
Filter.Eq(x => x.AppId, schemaEvent.AppId.Id.ToString()),
Update
.Set($"s.{schemaEvent.SchemaId.Id}", @event.Headers.EventStreamNumber())
.Set(x => x.Updated, @event.Headers.Timestamp()))
{ {
writes.Add( IsUpsert = true
new UpdateOneModel<MongoSchemasHashEntity>( });
Filter.Eq(x => x.AppId, schemaEvent.AppId.Id.ToString()),
Update
.Set($"s.{schemaEvent.SchemaId.Id}", @event.Headers.EventStreamNumber())
.Set(x => x.Updated, @event.Headers.Timestamp())));
break;
}
case AppEvent appEvent:
writes.Add(
new UpdateOneModel<MongoSchemasHashEntity>(
Filter.Eq(x => x.AppId, appEvent.AppId.Id.ToString()),
Update
.Set(x => x.AppVersion, @event.Headers.EventStreamNumber())
.Set(x => x.Updated, @event.Headers.Timestamp()))
{
IsUpsert = true
});
break;
} }
} }
@ -98,9 +85,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
return Collection.BulkWriteAsync(writes); return Collection.BulkWriteAsync(writes);
} }
public async Task<(Instant Create, string Hash)> GetCurrentHashAsync(DomainId appId) public async Task<(Instant Create, string Hash)> GetCurrentHashAsync(IAppEntity app)
{ {
var entity = await Collection.Find(x => x.AppId == appId.ToString()).FirstOrDefaultAsync(); Guard.NotNull(app, nameof(app));
var entity = await Collection.Find(x => x.AppId == app.Id.ToString()).FirstOrDefaultAsync();
if (entity == null) if (entity == null)
{ {
@ -109,7 +98,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
var ids = var ids =
entity.SchemaVersions.Select(x => (x.Key, x.Value)) entity.SchemaVersions.Select(x => (x.Key, x.Value))
.Union(Enumerable.Repeat((entity.AppId, entity.AppVersion), 1)); .Union(Enumerable.Repeat((app.Id.ToString(), app.Version), 1));
var hash = CreateHash(ids); var hash = CreateHash(ids);

5
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Schemas/MongoSchemasHashEntity.cs

@ -11,16 +11,13 @@ using NodaTime;
namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas namespace Squidex.Domain.Apps.Entities.MongoDb.Schemas
{ {
[BsonIgnoreExtraElements]
public sealed class MongoSchemasHashEntity public sealed class MongoSchemasHashEntity
{ {
[BsonId] [BsonId]
[BsonElement] [BsonElement]
public string AppId { get; set; } public string AppId { get; set; }
[BsonRequired]
[BsonElement("v")]
public long AppVersion { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement("s")] [BsonElement("s")]
public Dictionary<string, long> SchemaVersions { get; set; } public Dictionary<string, long> SchemaVersions { get; set; }

6
backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsJintExtension.cs

@ -44,13 +44,13 @@ namespace Squidex.Domain.Apps.Entities.Assets
return; return;
} }
var action = new GetAssetsDelegate((references, callback) => GetReferences(context, appId, user, references, callback)); var action = new GetAssetsDelegate((references, callback) => GetAssets(context, appId, user, references, callback));
context.Engine.SetValue("getAsset", action); context.Engine.SetValue("getAsset", action);
context.Engine.SetValue("getAssets", action); context.Engine.SetValue("getAssets", action);
} }
private void GetReferences(ExecutionContext context, DomainId appId, ClaimsPrincipal user, JsValue references, Action<JsValue> callback) private void GetAssets(ExecutionContext context, DomainId appId, ClaimsPrincipal user, JsValue references, Action<JsValue> callback)
{ {
GetReferencesAsync(context, appId, user, references, callback).Forget(); GetReferencesAsync(context, appId, user, references, callback).Forget();
} }
@ -96,7 +96,7 @@ namespace Squidex.Domain.Apps.Entities.Assets
var assetQuery = serviceProvider.GetRequiredService<IAssetQueryService>(); var assetQuery = serviceProvider.GetRequiredService<IAssetQueryService>();
var assets = await assetQuery.QueryAsync(requestContext, null, Q.Empty.WithIds(ids)); var assets = await assetQuery.QueryAsync(requestContext, null, Q.Empty.WithIds(ids), context.CancellationToken);
callback(JsValue.FromObject(context.Engine, assets.ToArray())); callback(JsValue.FromObject(context.Engine, assets.ToArray()));
} }

2
backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/CachingGraphQLService.cs

@ -82,7 +82,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL
}, },
async entry => async entry =>
{ {
var (created, hash) = await schemasHash.GetCurrentHashAsync(app.Id); var (created, hash) = await schemasHash.GetCurrentHashAsync(app);
return created < entry.Created || string.Equals(hash, entry.Hash, StringComparison.OrdinalIgnoreCase); return created < entry.Created || string.Equals(hash, entry.Hash, StringComparison.OrdinalIgnoreCase);
}); });

2
backend/src/Squidex.Domain.Apps.Entities/Contents/ReferencesJintExtension.cs

@ -98,7 +98,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
var contentQuery = serviceProvider.GetRequiredService<IContentQueryService>(); var contentQuery = serviceProvider.GetRequiredService<IContentQueryService>();
var contents = await contentQuery.QueryAsync(requestContext, Q.Empty.WithIds(ids)); var contents = await contentQuery.QueryAsync(requestContext, Q.Empty.WithIds(ids), context.CancellationToken);
callback(JsValue.FromObject(context.Engine, contents.ToArray())); callback(JsValue.FromObject(context.Engine, contents.ToArray()));
} }

2
backend/src/Squidex.Domain.Apps.Entities/Schemas/ISchemasHash.cs

@ -15,7 +15,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas
{ {
public interface ISchemasHash public interface ISchemasHash
{ {
Task<(Instant Create, string Hash)> GetCurrentHashAsync(DomainId appId); Task<(Instant Create, string Hash)> GetCurrentHashAsync(IAppEntity app);
ValueTask<string> ComputeHashAsync(IAppEntity app, IEnumerable<ISchemaEntity> schemas); ValueTask<string> ComputeHashAsync(IAppEntity app, IEnumerable<ISchemaEntity> schemas);
} }

7
backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterCompareTests.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -110,7 +111,11 @@ namespace Squidex.Domain.Apps.Core.Operations.HandleRules
var cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
return new JintScriptEngine(cache, extensions); return new JintScriptEngine(cache, extensions)
{
TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
};
} }
[Theory] [Theory]

7
backend/tests/Squidex.Domain.Apps.Core.Tests/Operations/HandleRules/RuleEventFormatterTests.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -100,7 +101,11 @@ namespace Squidex.Domain.Apps.Core.Operations.HandleRules
var cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var cache = new MemoryCache(Options.Create(new MemoryCacheOptions()));
return new JintScriptEngine(cache, extensions); return new JintScriptEngine(cache, extensions)
{
TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
};
} }
[Fact] [Fact]

7
backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Security.Claims; using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -45,7 +46,11 @@ namespace Squidex.Domain.Apps.Entities.Assets
A.CallTo(() => appProvider.GetAppAsync(appId.Id, false)) A.CallTo(() => appProvider.GetAppAsync(appId.Id, false))
.Returns(Mocks.App(appId)); .Returns(Mocks.App(appId));
sut = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())), extensions); sut = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())), extensions)
{
TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
};
} }
[Fact] [Fact]

3
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Counter/CounterJintExtensionTests.cs

@ -33,7 +33,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Counter
sut = new JintScriptEngine(cache, extensions) sut = new JintScriptEngine(cache, extensions)
{ {
TimeoutScript = TimeSpan.FromSeconds(1) TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
}; };
} }

9
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DynamicContentWorkflowTests.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FakeItEasy; using FakeItEasy;
@ -92,9 +93,13 @@ namespace Squidex.Domain.Apps.Entities.Contents
A.CallTo(() => app.Workflows) A.CallTo(() => app.Workflows)
.Returns(workflows); .Returns(workflows);
var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var scriptEngine = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())))
{
TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
};
sut = new DynamicContentWorkflow(new JintScriptEngine(memoryCache), appProvider); sut = new DynamicContentWorkflow(scriptEngine, appProvider);
} }
[Fact] [Fact]

7
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System;
using System.Security.Claims; using System.Security.Claims;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -45,7 +46,11 @@ namespace Squidex.Domain.Apps.Entities.Contents
A.CallTo(() => appProvider.GetAppAsync(appId.Id, false)) A.CallTo(() => appProvider.GetAppAsync(appId.Id, false))
.Returns(Mocks.App(appId)); .Returns(Mocks.App(appId));
sut = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())), extensions); sut = new JintScriptEngine(new MemoryCache(Options.Create(new MemoryCacheOptions())), extensions)
{
TimeoutScript = TimeSpan.FromSeconds(2),
TimeoutExecution = TimeSpan.FromSeconds(10)
};
} }
[Fact] [Fact]

4
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerTests_Mongo.cs

@ -49,6 +49,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
{ {
BsonJsonConvention.Register(JsonSerializer.Create(TestUtils.CreateSerializerSettings())); BsonJsonConvention.Register(JsonSerializer.Create(TestUtils.CreateSerializerSettings()));
DomainIdSerializer.Register();
SupportsQuerySyntax = false; SupportsQuerySyntax = false;
SupportsGeo = true; SupportsGeo = true;
} }
@ -67,4 +69,4 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text
); );
} }
} }
} }

7
backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/MongoDb/SchemasHashTests.cs

@ -59,11 +59,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas.MongoDb
await _.SchemasHash.On(new[] await _.SchemasHash.On(new[]
{ {
Envelope.Create<IEvent>(new AppCreated
{
AppId = NamedId.Of(app.Id, "my-app")
}).SetEventStreamNumber(app.Version).SetTimestamp(timestamp),
Envelope.Create<IEvent>(new SchemaCreated Envelope.Create<IEvent>(new SchemaCreated
{ {
AppId = NamedId.Of(app.Id, "my-app"), AppId = NamedId.Of(app.Id, "my-app"),
@ -77,7 +72,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.MongoDb
}).SetEventStreamNumber(schema2.Version).SetTimestamp(timestamp) }).SetEventStreamNumber(schema2.Version).SetTimestamp(timestamp)
}); });
var (dbTime, dbHash) = await _.SchemasHash.GetCurrentHashAsync(app.Id); var (dbTime, dbHash) = await _.SchemasHash.GetCurrentHashAsync(app);
Assert.Equal(dbHash, computedHash); Assert.Equal(dbHash, computedHash);
Assert.Equal(dbTime, timestamp); Assert.Equal(dbTime, timestamp);

4
backend/tests/Squidex.Infrastructure.Tests/EventSourcing/EventStoreTests.cs

@ -112,8 +112,8 @@ namespace Squidex.Infrastructure.EventSourcing
{ {
new StoredEvent(streamName, "Position", 0, commit1[0]), new StoredEvent(streamName, "Position", 0, commit1[0]),
new StoredEvent(streamName, "Position", 1, commit1[1]), new StoredEvent(streamName, "Position", 1, commit1[1]),
new StoredEvent(streamName, "Position", 2, commit2[2]), new StoredEvent(streamName, "Position", 2, commit2[0]),
new StoredEvent(streamName, "Position", 3, commit2[3]) new StoredEvent(streamName, "Position", 3, commit2[1])
}; };
ShouldBeEquivalentTo(readEvents1, expected); ShouldBeEquivalentTo(readEvents1, expected);

Loading…
Cancel
Save