-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Upgraded to .NET core 2.1 * Downgraded version of EntityFramework, because it uses newer version of Npgsql because it collides with Marten * Unified EventStore usage * Ignored Pending events for Client entity framework entity
- Loading branch information
1 parent
cdc0263
commit a579edb
Showing
16 changed files
with
271 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
using Domain.Events; | ||
|
||
namespace Domain.Aggregates | ||
{ | ||
public interface IEventSourcedAggregate : IAggregate | ||
{ | ||
Queue<IEvent> PendingEvents { get; } | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
Marten.Integration.Tests/EventStore/Aggregate/OutOfOrder/OutOfOrderProjectionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Marten.Integration.Tests.TestsInfrasructure; | ||
using SharpTestsEx; | ||
using Xunit; | ||
|
||
namespace Marten.Integration.Tests.EventStore.Projections | ||
{ | ||
public class OutOfOrderProjectionsTest : MartenTest | ||
{ | ||
private interface ITaskEvent | ||
{ | ||
Guid TaskId { get; set; } | ||
|
||
int TaskVersion { get; set; } | ||
} | ||
|
||
private class TaskCreated : ITaskEvent | ||
{ | ||
public Guid TaskId { get; set; } | ||
public string Description { get; set; } | ||
|
||
public int TaskVersion { get; set; } | ||
} | ||
|
||
private class TaskUpdated : ITaskEvent | ||
{ | ||
public Guid TaskId { get; set; } | ||
public string Description { get; set; } | ||
|
||
public int TaskVersion { get; set; } | ||
} | ||
|
||
private class Task | ||
{ | ||
public Guid TaskId { get; set; } | ||
|
||
public string Description { get; set; } | ||
} | ||
|
||
private class TaskList | ||
{ | ||
public Guid Id { get; set; } | ||
public List<Task> List { get; private set; } | ||
|
||
public TaskList() | ||
{ | ||
List = new List<Task>(); | ||
} | ||
|
||
public void Apply(TaskCreated @event) | ||
{ | ||
List.Add(new Task { TaskId = @event.TaskId, Description = @event.Description }); | ||
} | ||
|
||
public void Apply(TaskUpdated @event) | ||
{ | ||
var task = List.SingleOrDefault(t => t.TaskId == @event.TaskId); | ||
|
||
if (task == null) | ||
{ | ||
return; | ||
} | ||
|
||
task.Description = @event.Description; | ||
} | ||
} | ||
|
||
protected override IDocumentSession CreateSession(Action<StoreOptions> setStoreOptions) | ||
{ | ||
var store = DocumentStore.For(options => | ||
{ | ||
options.Connection(Settings.ConnectionString); | ||
options.AutoCreateSchemaObjects = AutoCreate.All; | ||
options.DatabaseSchemaName = SchemaName; | ||
options.Events.DatabaseSchemaName = SchemaName; | ||
|
||
//It's needed to manualy set that inline aggegation should be applied | ||
options.Events.InlineProjections.AggregateStreamsWith<TaskList>(); | ||
}); | ||
|
||
return store.OpenSession(); | ||
} | ||
|
||
[Fact] | ||
public void GivenOutOfOrderEvents_WhenPublishedWithSetVersion_ThenLiveAggregationWorksFine() | ||
{ | ||
var firstTaskId = Guid.NewGuid(); | ||
var secondTaskId = Guid.NewGuid(); | ||
|
||
var events = new ITaskEvent[] | ||
{ | ||
new TaskUpdated {TaskId = firstTaskId, Description = "Final First Task Description", TaskVersion = 4 }, | ||
new TaskCreated {TaskId = firstTaskId, Description = "First Task", TaskVersion = 1 }, | ||
new TaskCreated {TaskId = secondTaskId, Description = "Second Task 2", TaskVersion = 2 }, | ||
new TaskUpdated {TaskId = firstTaskId, Description = "Intermediate First Task Description", TaskVersion = 3}, | ||
new TaskUpdated {TaskId = secondTaskId, Description = "Final Second Task Description", TaskVersion = 5}, | ||
}; | ||
|
||
//1. Create events | ||
var streamId = EventStore.StartStream<TaskList>(events).Id; | ||
|
||
Session.SaveChanges(); | ||
|
||
//2. Get live agregation | ||
var taskListFromLiveAggregation = EventStore.AggregateStream<TaskList>(streamId); | ||
|
||
//3. Get inline aggregation | ||
var taskListFromInlineAggregation = Session.Load<TaskList>(streamId); | ||
|
||
taskListFromLiveAggregation.Should().Not.Be.Null(); | ||
taskListFromInlineAggregation.Should().Not.Be.Null(); | ||
|
||
taskListFromLiveAggregation.List.Count.Should().Be.EqualTo(2); | ||
taskListFromLiveAggregation.List.Count.Should().Be.EqualTo(taskListFromInlineAggregation.List.Count); | ||
} | ||
} | ||
} |
20 changes: 13 additions & 7 deletions
20
Sample/EventSourcing.Sample.Clients/Domain/Clients/Client.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
using Domain.Aggregates; | ||
using System; | ||
using Domain.Aggregates; | ||
using EventSourcing.Sample.Clients.Contracts.Clients.DTOs; | ||
using System; | ||
using EventSourcing.Sample.Clients.Contracts.Clients.Events; | ||
|
||
namespace EventSourcing.Sample.Clients.Domain.Clients | ||
{ | ||
public class Client : IAggregate | ||
public class Client : EventSourcedAggregate | ||
{ | ||
public Guid Id { get; private set; } | ||
|
||
public string Name { get; private set; } | ||
|
||
public string Email { get; private set; } | ||
|
||
public Client() | ||
{ | ||
|
||
} | ||
|
||
public Client(Guid id, string name, string email) | ||
{ | ||
Id = id; | ||
Name = name; | ||
Email = email; | ||
|
||
Append(new ClientCreated(id, new ClientInfo | ||
{ | ||
Email = email, | ||
Name = name | ||
})); | ||
} | ||
|
||
public void Update(ClientInfo clientInfo) | ||
{ | ||
Name = clientInfo.Name; | ||
Email = clientInfo.Email; | ||
|
||
Append(new ClientUpdated(Id, clientInfo)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.