Browse Source

Mini improvement.

pull/728/head
Sebastian 5 years ago
parent
commit
515c61b22f
  1. 2
      backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs
  2. 17
      backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerState.cs
  3. 5
      backend/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs
  4. 32
      backend/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerStateTests.cs

2
backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerGrain.cs

@ -178,7 +178,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
await ClearAsync();
State = EventConsumerState.Reset();
State = EventConsumerState.Initial;
Subscribe();
});

17
backend/src/Squidex.Infrastructure/EventSourcing/Grains/EventConsumerState.cs

@ -12,13 +12,15 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
{
public sealed class EventConsumerState
{
public bool IsStopped { get; set; }
public static readonly EventConsumerState Initial = new EventConsumerState();
public int Count { get; set; }
public bool IsStopped { get; init; }
public string? Error { get; set; }
public string? Error { get; init; }
public string? Position { get; set; }
public string? Position { get; init; }
public int Count { get; init; }
public bool IsPaused
{
@ -41,11 +43,6 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
Count = count;
}
public static EventConsumerState Reset()
{
return new EventConsumerState();
}
public EventConsumerState Handled(string position, int offset = 1)
{
return new EventConsumerState(position, Count + offset);
@ -58,7 +55,7 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
public EventConsumerState Started()
{
return new EventConsumerState(Position, Count) { IsStopped = false };
return new EventConsumerState(Position, Count);
}
public EventConsumerInfo ToInfo(string name)

5
backend/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerGrainTests.cs

@ -70,7 +70,10 @@ namespace Squidex.Infrastructure.EventSourcing.Grains
public EventConsumerGrainTests()
{
grainState.Value.Position = initialPosition;
grainState.Value = new EventConsumerState
{
Position = initialPosition
};
consumerName = eventConsumer.GetType().Name;

32
backend/tests/Squidex.Infrastructure.Tests/EventSourcing/Grains/EventConsumerStateTests.cs

@ -0,0 +1,32 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using FluentAssertions;
using Squidex.Infrastructure.TestHelpers;
using Xunit;
namespace Squidex.Infrastructure.EventSourcing.Grains
{
public class EventConsumerStateTests
{
[Fact]
public void Should_serialize_and_deserialize()
{
var state = new EventConsumerState
{
Count = 1,
IsStopped = true,
Error = "Error",
Position = "Position"
};
var serialized = state.SerializeAndDeserialize();
serialized.Should().BeEquivalentTo(state);
}
}
}
Loading…
Cancel
Save