diff --git a/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs b/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs index 10c8a13e1..0d14e580e 100644 --- a/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs +++ b/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs @@ -63,7 +63,12 @@ namespace Squidex.Infrastructure.EventSourcing public async Task> GetEventsAsync(string streamName, long streamPosition = 0) { - var commits = await Collection.Find(x => x.EventStreamOffset >= streamPosition).Sort(Sort.Ascending(TimestampField)).ToListAsync(); + var commits = + await Collection.Find( + Filter.And( + Filter.Eq(EventStreamField, streamName), + Filter.Gte(EventStreamOffsetField, streamPosition - 1))) + .Sort(Sort.Ascending(TimestampField)).ToListAsync(); var result = new List(); diff --git a/src/Squidex/Config/Domain/ReadServices.cs b/src/Squidex/Config/Domain/ReadServices.cs index 687977823..13f0ff490 100644 --- a/src/Squidex/Config/Domain/ReadServices.cs +++ b/src/Squidex/Config/Domain/ReadServices.cs @@ -29,6 +29,7 @@ using Squidex.Domain.Apps.Read.State.Grains; using Squidex.Domain.Users; using Squidex.Infrastructure; using Squidex.Infrastructure.Assets; +using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.EventSourcing.Grains; using Squidex.Infrastructure.States; @@ -120,6 +121,7 @@ namespace Squidex.Config.Domain services.AddSingletonAs(); + services.AddTransient(typeof(DomainObjectWrapper<>)); services.AddTransient(); services.AddTransient(); diff --git a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs index 30f111093..b5537df60 100644 --- a/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs +++ b/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs @@ -297,6 +297,8 @@ namespace Squidex.Infrastructure.EventSourcing.Grains A.CallTo(() => eventSubscription.StopAsync()) .MustHaveHappened(Repeated.Exactly.Once); + + sut.GetState().ShouldBeEquivalentTo(new EventConsumerInfo { Name = consumerName, IsStopped = true, Position = initialPosition, Error = ex.ToString() }); } [Fact] diff --git a/tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs b/tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs index 6a27dc263..76198d0b1 100644 --- a/tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs +++ b/tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs @@ -209,8 +209,6 @@ namespace Squidex.Infrastructure.States var actualObject2 = await sut.GetSynchronizedAsync(key); - Assert.Same(statefulObject, actualObject2); - A.CallTo(() => services.GetService(typeof(MyStatefulObject))) .MustHaveHappened(Repeated.Exactly.Once); } diff --git a/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs b/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs index 40b888c17..a57f05ab1 100644 --- a/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs +++ b/tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs @@ -17,7 +17,7 @@ using Xunit; namespace Squidex.Infrastructure.States { - public class StateSnapshotTests + public class StateSnapshotTests : IDisposable { private class MyStatefulObject : IStatefulObject { @@ -69,6 +69,11 @@ namespace Squidex.Infrastructure.States sut.Connect(); } + public void Dispose() + { + sut.Dispose(); + } + [Fact] public async Task Should_read_from_store() { @@ -141,12 +146,26 @@ namespace Squidex.Infrastructure.States var actualObject2 = await sut.GetSynchronizedAsync(key); - Assert.Same(statefulObject, actualObject2); - A.CallTo(() => services.GetService(typeof(MyStatefulObject))) .MustHaveHappened(Repeated.Exactly.Once); } + [Fact] + public async Task Should_not_serve_next_request_from_cache_when_detached() + { + statefulObject.ExpectedVersion = null; + + var actualObject1 = await sut.GetDetachedAsync(key); + + Assert.Same(statefulObject, actualObject1); + Assert.Null(cache.Get(key)); + + var actualObject2 = await sut.GetDetachedAsync(key); + + A.CallTo(() => services.GetService(typeof(MyStatefulObject))) + .MustHaveHappened(Repeated.Exactly.Twice); + } + [Fact] public async Task Should_write_to_store_with_previous_version() {