Browse Source

More tests with states stores.

pull/309/head
Sebastian 8 years ago
parent
commit
ed960c8027
  1. 8
      src/Squidex.Domain.Apps.Entities/Backup/CleanerGrain.cs
  2. 10
      src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesByAppIndexGrain.cs
  3. 10
      src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasByAppIndexGrain.cs
  4. 2
      src/Squidex.Infrastructure/States/IStore.cs
  5. 2
      src/Squidex.Infrastructure/States/Store.cs
  6. 28
      tests/Squidex.Infrastructure.Tests/States/PersistenceEventSourcingTests.cs
  7. 26
      tests/Squidex.Infrastructure.Tests/States/PersistenceSnapshotTests.cs

8
src/Squidex.Domain.Apps.Entities/Backup/CleanerGrain.cs

@ -126,14 +126,14 @@ namespace Squidex.Domain.Apps.Entities.Backup
foreach (var ruleId in ruleIds)
{
await store.ClearSnapshotAsync<RuleState>(ruleId);
await store.RemoveSnapshotAsync<RuleState>(ruleId);
}
var schemaIds = await grainFactory.GetGrain<ISchemasByAppIndex>(appId).GetSchemaIdsAsync();
foreach (var schemaId in schemaIds)
{
await store.ClearSnapshotAsync<SchemaState>(schemaId);
await store.RemoveSnapshotAsync<SchemaState>(schemaId);
}
foreach (var storage in storages)
@ -141,12 +141,12 @@ namespace Squidex.Domain.Apps.Entities.Backup
await storage.ClearAsync(appId);
}
await store.ClearSnapshotAsync<AppState>(appId);
await store.RemoveSnapshotAsync<AppState>(appId);
}
private async Task DeleteAsync<TState>(Guid id)
{
await store.ClearSnapshotAsync<TState>(id);
await store.RemoveSnapshotAsync<TState>(id);
}
}
}

10
src/Squidex.Domain.Apps.Entities/Rules/Indexes/RulesByAppIndexGrain.cs

@ -65,16 +65,16 @@ namespace Squidex.Domain.Apps.Entities.Rules.Indexes
return persistence.WriteSnapshotAsync(state);
}
public Task<List<Guid>> GetRuleIdsAsync()
{
return Task.FromResult(state.Rules.ToList());
}
public Task ClearAsync()
{
state = new State();
return persistence.DeleteAsync();
}
public Task<List<Guid>> GetRuleIdsAsync()
{
return Task.FromResult(state.Rules.ToList());
}
}
}

10
src/Squidex.Domain.Apps.Entities/Schemas/Indexes/SchemasByAppIndexGrain.cs

@ -72,16 +72,16 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Indexes
return Task.FromResult(schemaId);
}
public Task<List<Guid>> GetSchemaIdsAsync()
{
return Task.FromResult(state.Schemas.Values.ToList());
}
public Task ClearAsync()
{
state = new State();
return persistence.DeleteAsync();
}
public Task<List<Guid>> GetSchemaIdsAsync()
{
return Task.FromResult(state.Schemas.Values.ToList());
}
}
}

2
src/Squidex.Infrastructure/States/IStore.cs

@ -23,6 +23,6 @@ namespace Squidex.Infrastructure.States
Task ClearSnapshotsAsync<TState>();
Task ClearSnapshotAsync<TState>(TKey key);
Task RemoveSnapshotAsync<TState>(TKey key);
}
}

2
src/Squidex.Infrastructure/States/Store.cs

@ -63,7 +63,7 @@ namespace Squidex.Infrastructure.States
return GetSnapshotStore<TState>().ClearAsync();
}
public Task ClearSnapshotAsync<TState>(TKey key)
public Task RemoveSnapshotAsync<TState>(TKey key)
{
return GetSnapshotStore<TState>().RemoveAsync(key);
}

28
tests/Squidex.Infrastructure.Tests/States/PersistenceEventSourcingTests.cs

@ -205,6 +205,34 @@ namespace Squidex.Infrastructure.States
await Assert.ThrowsAsync<DomainObjectVersionException>(() => persistence.WriteEventsAsync(new[] { new MyEvent(), new MyEvent() }.Select(Envelope.Create)));
}
[Fact]
public async Task Should_delete_events_but_not_snapshot_when_deleted_snapshot_only()
{
var persistence = sut.WithEventSourcing<object, string>(key, x => { });
await persistence.DeleteAsync();
A.CallTo(() => eventStore.DeleteStreamAsync(key))
.MustHaveHappened();
A.CallTo(() => snapshotStore.RemoveAsync(key))
.MustNotHaveHappened();
}
[Fact]
public async Task Should_delete_events_and_snapshot_when_deleted()
{
var persistence = sut.WithSnapshotsAndEventSourcing<object, object, string>(key, x => { }, x => { });
await persistence.DeleteAsync();
A.CallTo(() => eventStore.DeleteStreamAsync(key))
.MustHaveHappened();
A.CallTo(() => snapshotStore.RemoveAsync(key))
.MustHaveHappened();
}
private void SetupEventStore(int count, int eventOffset = 0, int readPosition = 0)
{
SetupEventStore(Enumerable.Repeat(0, count).Select(x => new MyEvent()).ToArray(), eventOffset, readPosition);

26
tests/Squidex.Infrastructure.Tests/States/PersistenceSnapshotTests.cs

@ -146,5 +146,31 @@ namespace Squidex.Infrastructure.States
await Assert.ThrowsAsync<DomainObjectVersionException>(() => persistence.WriteSnapshotAsync(100));
}
[Fact]
public async Task Should_delete_snapshot_but_not_events_when_deleted()
{
var persistence = sut.WithSnapshots<object, int, string>(key, x => { });
await persistence.DeleteAsync();
A.CallTo(() => eventStore.DeleteStreamAsync(A<string>.Ignored))
.MustNotHaveHappened();
A.CallTo(() => snapshotStore.RemoveAsync(key))
.MustHaveHappened();
}
[Fact]
public async Task Should_delete_snapshot_but_not_events_when_deleted_from_store()
{
await sut.RemoveSnapshotAsync<int>(key);
A.CallTo(() => eventStore.DeleteStreamAsync(A<string>.Ignored))
.MustNotHaveHappened();
A.CallTo(() => snapshotStore.RemoveAsync(key))
.MustHaveHappened();
}
}
}
Loading…
Cancel
Save