Browse Source

Fixed bugs.

pull/204/head
Sebastian Stehle 8 years ago
parent
commit
920fba61be
  1. 7
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs
  2. 2
      src/Squidex/Config/Domain/ReadServices.cs
  3. 2
      tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs
  4. 2
      tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs
  5. 25
      tests/Squidex.Infrastructure.Tests/States/StateSnapshotTests.cs

7
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs

@ -63,7 +63,12 @@ namespace Squidex.Infrastructure.EventSourcing
public async Task<IReadOnlyList<StoredEvent>> 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<StoredEvent>();

2
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<EdmModelBuilder>();
services.AddTransient(typeof(DomainObjectWrapper<>));
services.AddTransient<AppStateGrain>();
services.AddTransient<AppUserGrain>();

2
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]

2
tests/Squidex.Infrastructure.Tests/States/StateEventSourcingTests.cs

@ -209,8 +209,6 @@ namespace Squidex.Infrastructure.States
var actualObject2 = await sut.GetSynchronizedAsync<MyStatefulObject>(key);
Assert.Same(statefulObject, actualObject2);
A.CallTo(() => services.GetService(typeof(MyStatefulObject)))
.MustHaveHappened(Repeated.Exactly.Once);
}

25
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<MyStatefulObject>(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<MyStatefulObject>(key);
Assert.Same(statefulObject, actualObject1);
Assert.Null(cache.Get<object>(key));
var actualObject2 = await sut.GetDetachedAsync<MyStatefulObject>(key);
A.CallTo(() => services.GetService(typeof(MyStatefulObject)))
.MustHaveHappened(Repeated.Exactly.Twice);
}
[Fact]
public async Task Should_write_to_store_with_previous_version()
{

Loading…
Cancel
Save