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
17 changes: 17 additions & 0 deletions EventFlow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.PostgreSql", "Sou
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.PostgreSql.Tests", "Source\EventFlow.PostgreSql.Tests\EventFlow.PostgreSql.Tests.csproj", "{472095E5-7233-48AE-BBEA-56199F83707E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EntityFramework", "EntityFramework", "{EF3D7E6F-1AB6-4B84-83C4-21D1F49EDF45}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.EntityFramework", "Source\EventFlow.EntityFramework\EventFlow.EntityFramework.csproj", "{97A911C0-EBBB-45B0-8B84-065A5CC72368}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.EntityFramework.Tests", "Source\EventFlow.EntityFramework.Tests\EventFlow.EntityFramework.Tests.csproj", "{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -159,6 +165,14 @@ Global
{472095E5-7233-48AE-BBEA-56199F83707E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{472095E5-7233-48AE-BBEA-56199F83707E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{472095E5-7233-48AE-BBEA-56199F83707E}.Release|Any CPU.Build.0 = Release|Any CPU
{97A911C0-EBBB-45B0-8B84-065A5CC72368}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{97A911C0-EBBB-45B0-8B84-065A5CC72368}.Debug|Any CPU.Build.0 = Debug|Any CPU
{97A911C0-EBBB-45B0-8B84-065A5CC72368}.Release|Any CPU.ActiveCfg = Release|Any CPU
{97A911C0-EBBB-45B0-8B84-065A5CC72368}.Release|Any CPU.Build.0 = Release|Any CPU
{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -192,6 +206,9 @@ Global
{F8484014-DA21-4388-B74A-2D90108656E8} = {31881D2B-26BB-4EF5-B29A-800731368C21}
{E8B07B33-DBF1-4C9F-9C18-8825C3595FA4} = {3A68BD5F-FE8D-4CD4-A039-3EFBDEDE8865}
{472095E5-7233-48AE-BBEA-56199F83707E} = {3A68BD5F-FE8D-4CD4-A039-3EFBDEDE8865}
{EF3D7E6F-1AB6-4B84-83C4-21D1F49EDF45} = {5EE323DE-E69B-451A-8AC3-22DD6A004FBA}
{97A911C0-EBBB-45B0-8B84-065A5CC72368} = {EF3D7E6F-1AB6-4B84-83C4-21D1F49EDF45}
{FDA8C3EE-82C1-4D72-A82C-2F76F53DD6F8} = {EF3D7E6F-1AB6-4B84-83C4-21D1F49EDF45}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Description>Data transfer objects (DTOs) for ClearFlow's Value Objects</Description>
<PackageTags>CQRS ES event sourcing Dtos</PackageTags>
<PackageReleaseNotes>Initial release for basic value objects.</PackageReleaseNotes>
<Version>0.1.1</Version>
<Version>0.1.3</Version>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Description>Common value objects available with ClearFlow</Description>
<PackageTags>CQRS ES event sourcing value objects</PackageTags>
<PackageReleaseNotes>Initial release for basic value objects.</PackageReleaseNotes>
<Version>0.1.1</Version>
<Version>0.1.3</Version>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using EventFlow.EntityFramework.Tests.MsSql.IncludeTests.ReadModels;
using EventFlow.Extensions;
using EventFlow.TestHelpers.Aggregates.Entities;
using Microsoft.Extensions.DependencyInjection;

namespace EventFlow.EntityFramework.Tests
{
Expand All @@ -46,7 +47,7 @@ public static IEventFlowOptions ConfigureForSnapshotStoreTest(this IEventFlowOpt
public static IEventFlowOptions ConfigureForReadStoreTest(this IEventFlowOptions options)
{
return options
.RegisterServices(sr => sr.RegisterType(typeof(ThingyMessageLocator)))
.RegisterServices(sr => sr.AddTransient(typeof(ThingyMessageLocator)))
.UseEntityFrameworkReadModel<ThingyReadModelEntity, TestDbContext>()
.UseEntityFrameworkReadModel<ThingyMessageReadModelEntity, TestDbContext, ThingyMessageLocator>()
.AddQueryHandlers(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<IsPackable>False</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Npgsql" Version="4.1.14" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow.EntityFramework\EventFlow.EntityFramework.csproj" />
<ProjectReference Include="..\EventFlow.PostgreSql.Tests\EventFlow.PostgreSql.Tests.csproj" />
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
<ProjectReference Include="..\EventFlow\EventFlow.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageReference Include="Npgsql" Version="8.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0' Or '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.20" />
<PackageReference Include="Npgsql" Version="7.0.8" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.18" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow.EntityFramework\EventFlow.EntityFramework.csproj" />
<ProjectReference Include="..\EventFlow.PostgreSql.Tests\EventFlow.PostgreSql.Tests.csproj" />
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
<ProjectReference Include="..\EventFlow\EventFlow.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Threading.Tasks;
using EventFlow.Configuration;
using System;
using EventFlow.EntityFramework.Extensions;
using EventFlow.EntityFramework.Tests.Model;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Suites;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace EventFlow.EntityFramework.Tests.InMemory
{
[Category(Categories.Integration)]
public class EfInMemoryEventStoreTests : TestSuiteForEventStore
{
protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
var resolver = eventFlowOptions
.ConfigureEntityFramework(EntityFrameworkConfiguration.New)
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(Lifetime.Singleton)
.ConfigureForEventStoreTest()
.CreateResolver();
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(ServiceLifetime.Singleton)
.ConfigureForEventStoreTest();

var serviceProvider = base.Configure(resolver);

return serviceProvider;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using EventFlow.Configuration;
using EventFlow.EntityFramework.Extensions;
using EventFlow.EntityFramework.Tests.Model;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Suites;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;

namespace EventFlow.EntityFramework.Tests.InMemory
Expand All @@ -35,13 +35,16 @@ public class EfInMemoryReadStoreTests : TestSuiteForReadModelStore
{
protected override Type ReadModelType => typeof(ThingyReadModelEntity);

protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
var resolver = eventFlowOptions
.ConfigureEntityFramework(EntityFrameworkConfiguration.New)
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(Lifetime.Singleton)
.ConfigureForReadStoreTest()
.CreateResolver();
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(ServiceLifetime.Singleton)
.ConfigureForReadStoreTest();

var serviceProvider = base.Configure(resolver);

return serviceProvider;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using EventFlow.Configuration;
using EventFlow.EntityFramework.Extensions;
using EventFlow.EntityFramework.Tests.Model;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Suites;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using System;

namespace EventFlow.EntityFramework.Tests.InMemory
{
[Category(Categories.Integration)]
public class EfInMemorySnapshotTests : TestSuiteForSnapshotStore
{
protected override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions)
protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions)
{
return eventFlowOptions
var resolver = eventFlowOptions
.ConfigureEntityFramework(EntityFrameworkConfiguration.New)
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(Lifetime.Singleton)
.ConfigureForSnapshotStoreTest()
.CreateResolver();
.AddDbContextProvider<TestDbContext, InMemoryDbContextProvider>(ServiceLifetime.Singleton)
.ConfigureForSnapshotStoreTest();

var serviceProvider = base.Configure(resolver);

return serviceProvider;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace EventFlow.EntityFramework.Tests.InMemory
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Only for test")]
public class InMemoryDbContextProvider : IDbContextProvider<TestDbContext>
{
private readonly DbContextOptions<TestDbContext> _options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal;
using Microsoft.EntityFrameworkCore.InMemory.ValueGeneration.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
Expand All @@ -39,6 +40,12 @@ public class IndexingInMemoryTable : IInMemoryTable
private readonly HashSet<IndexEntry>[] _indexes;
private readonly IInMemoryTable _innerTable;

public IEnumerable<object[]> Rows => _innerTable.Rows;

public IInMemoryTable BaseTable => _innerTable;

public IEntityType EntityType => throw new InvalidOperationException("Property deprecated in newer versions so not used anymore.");

public IndexingInMemoryTable(IInMemoryTable innerTable, IIndex[] indexDefinitions)
{
_innerTable = innerTable;
Expand All @@ -51,8 +58,9 @@ public IReadOnlyList<object[]> SnapshotRows()
return _innerTable.SnapshotRows();
}

public void Create(IUpdateEntry entry)
public void Create(IUpdateEntry entry, IDiagnosticsLogger<DbLoggerCategory.Update> updateLogger)
{
//_entityType = entry.EntityType;
var indexEntries = _indexDefinitions
.Select(d => d.Properties.Select(entry.GetCurrentValue).ToArray())
.Select(values => new IndexEntry(values))
Expand All @@ -61,24 +69,29 @@ public void Create(IUpdateEntry entry)
if (indexEntries.Select((item, i) => _indexes[i].Contains(item)).Any(contains => contains))
throw new DbUpdateException("Error while updating.", new Exception("Unique constraint violated."));

_innerTable.Create(entry);
_innerTable.Create(entry, updateLogger);

indexEntries.Select((item, i) => _indexes[i].Add(item)).ToArray();
}

public void Delete(IUpdateEntry entry)
public void Delete(IUpdateEntry entry, IDiagnosticsLogger<DbLoggerCategory.Update> updateLogger)
{
_innerTable.Delete(entry, updateLogger);
}

public void Update(IUpdateEntry entry, IDiagnosticsLogger<DbLoggerCategory.Update> updateLogger)
{
_innerTable.Delete(entry);
_innerTable.Update(entry, updateLogger);
}

public void Update(IUpdateEntry entry)
public InMemoryIntegerValueGenerator<TProperty> GetIntegerValueGenerator<TProperty>(IProperty property, IReadOnlyList<IInMemoryTable> tables)
{
_innerTable.Update(entry);
return _innerTable.GetIntegerValueGenerator<TProperty>(property, tables);
}

public InMemoryIntegerValueGenerator<TProperty> GetIntegerValueGenerator<TProperty>(IProperty property)
public void BumpValueGenerators(object[] row)
{
return _innerTable.GetIntegerValueGenerator<TProperty>(property);
_innerTable.BumpValueGenerators(row);
}

private struct IndexEntry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System.Linq;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.InMemory.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.InMemory.Storage.Internal;
using Microsoft.EntityFrameworkCore.Metadata;

Expand All @@ -30,13 +31,13 @@ namespace EventFlow.EntityFramework.Tests.InMemory.Infrastructure
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "Only for test")]
public class IndexingInMemoryTableFactory : InMemoryTableFactory
{
public IndexingInMemoryTableFactory(ILoggingOptions loggingOptions) : base(loggingOptions)
public IndexingInMemoryTableFactory(ILoggingOptions loggingOptions, IInMemorySingletonOptions options) : base(loggingOptions, options)
{
}

public override IInMemoryTable Create(IEntityType entityType)
public override IInMemoryTable Create(IEntityType entityType, IInMemoryTable baseTable)
{
var innerTable = base.Create(entityType);
var innerTable = base.Create(entityType, baseTable);
var uniqueIndexes = entityType.GetIndexes().Where(i => i.IsUnique).ToArray();

return uniqueIndexes.Any()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EventFlow.Aggregates;
using EventFlow.ReadStores;
using EventFlow.TestHelpers.Aggregates;
Expand All @@ -41,19 +43,23 @@ public class ThingyMessageReadModelEntity : IReadModel,

public string Message { get; set; }

public void Apply(IReadModelContext context, IDomainEvent<ThingyAggregate, ThingyId, ThingyMessageAddedEvent> domainEvent)
public Task ApplyAsync(IReadModelContext context, IDomainEvent<ThingyAggregate, ThingyId, ThingyMessageAddedEvent> domainEvent, CancellationToken cancellationToken)
{
ThingyId = domainEvent.AggregateIdentity.Value;
Message = domainEvent.AggregateEvent.ThingyMessage.Message;

return Task.CompletedTask;
}

public void Apply(IReadModelContext context, IDomainEvent<ThingyAggregate, ThingyId, ThingyMessageHistoryAddedEvent> domainEvent)
public Task ApplyAsync(IReadModelContext context, IDomainEvent<ThingyAggregate, ThingyId, ThingyMessageHistoryAddedEvent> domainEvent, CancellationToken cancellationToken)
{
ThingyId = domainEvent.AggregateIdentity.Value;

var messageId = new ThingyMessageId(context.ReadModelId);
var thingyMessage = domainEvent.AggregateEvent.ThingyMessages.Single(m => m.Id == messageId);
Message = thingyMessage.Message;

return Task.CompletedTask;
}

public ThingyMessage ToThingyMessage()
Expand Down
Loading