Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Shared.EventStore.Tests/DomainEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Shared.EventStore.Tests;
public class DomainEventTests{
[Fact]
public void DomainEvent_CanBeCreated_IsCreated(){
DomainEvent d = new DomainEvent(TestData.AggregateId, TestData.EventId);
DomainEvent d = new(TestData.AggregateId, TestData.EventId);
d.AggregateId.ShouldBe(TestData.AggregateId);
d.EventId.ShouldBe(TestData.EventId);
d.EventType.ShouldBe("DomainEvent");
Expand Down
20 changes: 10 additions & 10 deletions Shared.EventStore.Tests/EventDispatchHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Shared.EventStore.Tests;
public class EventDispatchHelperTests{
[Fact]
public async Task EventDispatchHelper_DispatchToHandlers_AllSuccessful(){
AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new List<IDomainEventHandler>();
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new();
handlers.Add(new TestDomainEventHandler());
Result result = await @event.DispatchToHandlers(handlers, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
Expand All @@ -27,12 +27,12 @@ public async Task EventDispatchHelper_DispatchToHandlers_AllSuccessful(){
[Fact]
public async Task EventDispatchHelper_DispatchToHandlers_HandlerThrowsException_ErrorThrown()
{
AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new List<IDomainEventHandler>();
Mock<IDomainEventHandler> domainEventHandler = new Mock<IDomainEventHandler>();
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new();
Mock<IDomainEventHandler> domainEventHandler = new();
domainEventHandler.Setup(s => s.Handle(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);
Mock<IDomainEventHandler> domainEventHandler2 = new Mock<IDomainEventHandler>();
Mock<IDomainEventHandler> domainEventHandler2 = new();
domainEventHandler2.Setup(s => s.Handle(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);
handlers.Add(domainEventHandler.Object);
Expand All @@ -45,12 +45,12 @@ public async Task EventDispatchHelper_DispatchToHandlers_HandlerThrowsException_
[Fact]
public async Task EventDispatchHelper_DispatchToHandlers_HandlersFail_ErrorThrown()
{
AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new List<IDomainEventHandler>();
Mock<IDomainEventHandler> domainEventHandler = new Mock<IDomainEventHandler>();
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
List<IDomainEventHandler> handlers = new();
Mock<IDomainEventHandler> domainEventHandler = new();
domainEventHandler.Setup(s => s.Handle(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure("Error Message 1"));
Mock<IDomainEventHandler> domainEventHandler2 = new Mock<IDomainEventHandler>();
Mock<IDomainEventHandler> domainEventHandler2 = new();
domainEventHandler2.Setup(s => s.Handle(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure(new List<String>() {
"Error Message 2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,51 @@ public void AddEventStore_HealthCheckAdded(){
public class EventStoreConnectionStringHealthCheckTests {
[Fact]
public async Task EventStoreConnectionStringHealthCheck_CheckHealthAsync_EventsReturned_Healthy() {
Mock<IEventStoreContext> context = new Mock<IEventStoreContext>();
AggregateNameSetEvent aggregateNameSetEvent = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, "Test");
Mock<IEventStoreContext> context = new();
AggregateNameSetEvent aggregateNameSetEvent = new(TestData.AggregateId, TestData.EventId, "Test");

EventRecord r = TestData.CreateEventRecord<AggregateNameSetEvent>(aggregateNameSetEvent, "TestAggregate");

var resolvedEvent = new ResolvedEvent(r, null,null);

context.Setup(c => c.ReadLastEventsFromAll(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(new List<ResolvedEvent>() { resolvedEvent }));
EventStoreConnectionStringHealthCheck healthCheck = new EventStoreConnectionStringHealthCheck(context.Object);
EventStoreConnectionStringHealthCheck healthCheck = new(context.Object);
var result = await healthCheck.CheckHealthAsync(new HealthCheckContext(), CancellationToken.None);
result.Status.ShouldBe(HealthStatus.Healthy);
}

[Fact]
public async Task EventStoreConnectionStringHealthCheck_CheckHealthAsync_NoEventsReturned_Unhealthy()
{
Mock<IEventStoreContext> context = new Mock<IEventStoreContext>();
AggregateNameSetEvent aggregateNameSetEvent = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, "Test");
Mock<IEventStoreContext> context = new();
AggregateNameSetEvent aggregateNameSetEvent = new(TestData.AggregateId, TestData.EventId, "Test");

context.Setup(c => c.ReadLastEventsFromAll(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(new List<ResolvedEvent>()));
EventStoreConnectionStringHealthCheck healthCheck = new EventStoreConnectionStringHealthCheck(context.Object);
EventStoreConnectionStringHealthCheck healthCheck = new(context.Object);
var result = await healthCheck.CheckHealthAsync(new HealthCheckContext(), CancellationToken.None);
result.Status.ShouldBe(HealthStatus.Unhealthy);
}

[Fact]
public async Task EventStoreConnectionStringHealthCheck_CheckHealthAsync_ReadLastEventsFromAll_Unhealthy()
{
Mock<IEventStoreContext> context = new Mock<IEventStoreContext>();
AggregateNameSetEvent aggregateNameSetEvent = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, "Test");
Mock<IEventStoreContext> context = new();
AggregateNameSetEvent aggregateNameSetEvent = new(TestData.AggregateId, TestData.EventId, "Test");

context.Setup(c => c.ReadLastEventsFromAll(It.IsAny<long>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
EventStoreConnectionStringHealthCheck healthCheck = new EventStoreConnectionStringHealthCheck(context.Object);
EventStoreConnectionStringHealthCheck healthCheck = new(context.Object);
var result = await healthCheck.CheckHealthAsync(new HealthCheckContext(), CancellationToken.None);
result.Status.ShouldBe(HealthStatus.Unhealthy);
}

[Fact]
public async Task EventStoreConnectionStringHealthCheck_CheckHealthAsync_ExceptionThrown_Unhealthy()
{
Mock<IEventStoreContext> context = new Mock<IEventStoreContext>();
AggregateNameSetEvent aggregateNameSetEvent = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, "Test");
Mock<IEventStoreContext> context = new();
AggregateNameSetEvent aggregateNameSetEvent = new(TestData.AggregateId, TestData.EventId, "Test");

context.Setup(c => c.ReadLastEventsFromAll(It.IsAny<long>(), It.IsAny<CancellationToken>())).ThrowsAsync(new Exception());
EventStoreConnectionStringHealthCheck healthCheck = new EventStoreConnectionStringHealthCheck(context.Object);
EventStoreConnectionStringHealthCheck healthCheck = new(context.Object);

var result = await healthCheck.CheckHealthAsync(new HealthCheckContext(), CancellationToken.None);
result.Status.ShouldBe(HealthStatus.Unhealthy);
Expand Down
62 changes: 31 additions & 31 deletions Shared.EventStore.Tests/ProjectionHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,60 @@ namespace Shared.EventStore.Tests
public class ProjectionHandlerTests{
[Fact]
public async Task ProjectionHandler_Handle_EventHandled(){
TestState originalState = new TestState();
TestState updatedState = new TestState{
TestState originalState = new();
TestState updatedState = new() {
Name = "Test Name"
};

Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new Mock<IProjectionStateRepository<TestState>>();
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new();
projectionStateRepository.Setup(p => p.Load(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IProjection<TestState>> projection = new Mock<IProjection<TestState>>();
Mock<IProjection<TestState>> projection = new();
projection.Setup(p => p.ShouldIHandleEvent(It.IsAny<IDomainEvent>())).Returns(true);
projection.Setup(p => p.Handle(It.IsAny<TestState>(), It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(updatedState);
Mock<IStateDispatcher<TestState>> dispatcher = new Mock<IStateDispatcher<TestState>>();
ProjectionHandler<TestState> handler = new ProjectionHandler<TestState>(projectionStateRepository.Object,
Mock<IStateDispatcher<TestState>> dispatcher = new();
ProjectionHandler<TestState> handler = new(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);

AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
await handler.Handle(@event, CancellationToken.None);
}

[Fact]
public async Task ProjectionHandler_Handle_StateNotChanged_EventHandled()
{
TestState originalState = new TestState();
TestState originalState = new();

Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new Mock<IProjectionStateRepository<TestState>>();
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new();
projectionStateRepository.Setup(p => p.Load(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IProjection<TestState>> projection = new Mock<IProjection<TestState>>();
Mock<IProjection<TestState>> projection = new();
projection.Setup(p => p.ShouldIHandleEvent(It.IsAny<IDomainEvent>())).Returns(true);
projection.Setup(p => p.Handle(It.IsAny<TestState>(), It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IStateDispatcher<TestState>> dispatcher = new Mock<IStateDispatcher<TestState>>();
ProjectionHandler<TestState> handler = new ProjectionHandler<TestState>(projectionStateRepository.Object,
Mock<IStateDispatcher<TestState>> dispatcher = new();
ProjectionHandler<TestState> handler = new(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);

AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
await handler.Handle(@event, CancellationToken.None);
}

[Fact]
public async Task ProjectionHandler_Handle_TraceHandlerSet_EventHandled()
{
TestState originalState = new TestState();
TestState originalState = new();

Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new Mock<IProjectionStateRepository<TestState>>();
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new();
projectionStateRepository.Setup(p => p.Load(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IProjection<TestState>> projection = new Mock<IProjection<TestState>>();
Mock<IProjection<TestState>> projection = new();
projection.Setup(p => p.ShouldIHandleEvent(It.IsAny<IDomainEvent>())).Returns(true);
projection.Setup(p => p.Handle(It.IsAny<TestState>(), It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IStateDispatcher<TestState>> dispatcher = new Mock<IStateDispatcher<TestState>>();
ProjectionHandler<TestState> handler = new ProjectionHandler<TestState>(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);
Mock<IStateDispatcher<TestState>> dispatcher = new();
ProjectionHandler<TestState> handler = new(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);

AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
await handler.Handle(@event, CancellationToken.None);
}

Expand All @@ -87,32 +87,32 @@ public async Task ProjectionHandler_Handle_NullEvent_EventHandled()
[Fact]
public async Task ProjectionHandler_Handle_EventNotHandled_EventHandled()
{
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new Mock<IProjectionStateRepository<TestState>>();
Mock<IProjection<TestState>> projection = new Mock<IProjection<TestState>>();
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new();
Mock<IProjection<TestState>> projection = new();
projection.Setup(p => p.ShouldIHandleEvent(It.IsAny<IDomainEvent>())).Returns(false);
Mock<IStateDispatcher<TestState>> dispatcher = new Mock<IStateDispatcher<TestState>>();
ProjectionHandler<TestState> handler = new ProjectionHandler<TestState>(projectionStateRepository.Object,
Mock<IStateDispatcher<TestState>> dispatcher = new();
ProjectionHandler<TestState> handler = new(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);

AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
await handler.Handle(@event, CancellationToken.None);
}

[Fact]
public async Task ProjectionHandler_Handle_NullState_EventHandled(){
TestState originalState = null;

Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new Mock<IProjectionStateRepository<TestState>>();
Mock<IProjectionStateRepository<TestState>> projectionStateRepository = new();
projectionStateRepository.Setup(p => p.Load(It.IsAny<IDomainEvent>(), It.IsAny<CancellationToken>())).ReturnsAsync(originalState);
Mock<IProjection<TestState>> projection = new Mock<IProjection<TestState>>();
Mock<IProjection<TestState>> projection = new();
projection.Setup(p => p.ShouldIHandleEvent(It.IsAny<IDomainEvent>())).Returns(true);
Mock<IStateDispatcher<TestState>> dispatcher = new Mock<IStateDispatcher<TestState>>();
ProjectionHandler<TestState> handler = new ProjectionHandler<TestState>(projectionStateRepository.Object,
Mock<IStateDispatcher<TestState>> dispatcher = new();
ProjectionHandler<TestState> handler = new(projectionStateRepository.Object,
projection.Object,
dispatcher.Object);

AggregateNameSetEvent @event = new AggregateNameSetEvent(TestData.AggregateId, TestData.EventId, TestData.EstateName);
AggregateNameSetEvent @event = new(TestData.AggregateId, TestData.EventId, TestData.EstateName);
await handler.Handle(@event, CancellationToken.None);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Shared.EventStore.Tests/TestObjects/TestAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void PlayEvent(AggregateNameSetEvent domainEvent)

public void SetAggregateName(string aggregateName, Guid eventId)
{
AggregateNameSetEvent aggregateNameSetEvent = new AggregateNameSetEvent(AggregateId, eventId, aggregateName);
AggregateNameSetEvent aggregateNameSetEvent = new(AggregateId, eventId, aggregateName);

ApplyAndAppend(aggregateNameSetEvent);
}
Expand Down
4 changes: 2 additions & 2 deletions Shared.EventStore.Tests/TestObjects/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public static EventRecord CreateEventRecord<T>(T domainEvent, string streamId, b
byte[] eventData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(domainEvent));
byte[] customEventMetaData = Encoding.UTF8.GetBytes(string.Empty);

Dictionary<string, string> metaData = new Dictionary<string, string>();
Dictionary<string, string> metaData = new();
metaData.Add("type", domainEvent.GetType().FullName);
metaData.Add("created", "1000000");
metaData.Add("content-type", "application-json");

if (addToMap)
TypeMap.AddType(typeof(T), domainEvent.GetType().FullName);

EventRecord r = new EventRecord(streamId,
EventRecord r = new(streamId,
Uuid.FromGuid(domainEvent.EventId),
0,
new Position(0, 0),
Expand Down
Loading
Loading