Skip to content
Draft
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
681 changes: 466 additions & 215 deletions EventFlow.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public static class EntityFrameworkTestExtensions
public static IEventFlowOptions ConfigureForEventStoreTest(this IEventFlowOptions options)
{
return options
.UseEntityFrameworkEventStore<TestDbContext>();
.UseEntityFrameworkEventStore<TestDbContext>()
.AddNewtonsoftJson();
}

public static IEventFlowOptions ConfigureForSnapshotStoreTest(this IEventFlowOptions options)
{
return options
.UseEntityFrameworkSnapshotStore<TestDbContext>();
.UseEntityFrameworkSnapshotStore<TestDbContext>()
.AddNewtonsoftJson();
}

public static IEventFlowOptions ConfigureForReadStoreTest(this IEventFlowOptions options)
Expand All @@ -53,14 +55,16 @@ public static IEventFlowOptions ConfigureForReadStoreTest(this IEventFlowOptions
.AddQueryHandlers(
typeof(EfThingyGetQueryHandler),
typeof(EfThingyGetVersionQueryHandler),
typeof(EfThingyGetMessagesQueryHandler));
typeof(EfThingyGetMessagesQueryHandler))
.AddNewtonsoftJson();
}

public static IEventFlowOptions ConfigureForReadStoreIncludeTest(this IEventFlowOptions options)
{
return options
.UseEntityFrameworkReadModel<PersonReadModelEntity, TestDbContext>(cfg => cfg.Include(x => x.Addresses))
.AddQueryHandlers(typeof(PersonGetQueryHandler));
.AddQueryHandlers(typeof(PersonGetQueryHandler))
.AddNewtonsoftJson();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EventFlow.Examples.Shipping\EventFlow.Examples.Shipping.csproj" />
<ProjectReference Include="..\EventFlow.Serialization.NewtonsoftJson\EventFlow.Serialization.NewtonsoftJson.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static IEventFlowOptions ConfigureShippingQueriesInMemory(
return eventFlowOptions
.AddQueryHandlers(Assembly)
.UseInMemoryReadStoreFor<VoyageReadModel>()
.UseInMemoryReadStoreFor<CargoReadModel>();
.UseInMemoryReadStoreFor<CargoReadModel>()
.AddNewtonsoftJson();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

using EventFlow.Core;
using EventFlow.ValueObjects;
using Newtonsoft.Json;

namespace EventFlow.Examples.Shipping.Domain.Model.CargoModel
{
[JsonConverter(typeof(SingleValueObjectConverter))]
public class CargoId : Identity<CargoId>
{
public CargoId(string value) : base(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

using EventFlow.Core;
using EventFlow.ValueObjects;
using Newtonsoft.Json;

namespace EventFlow.Examples.Shipping.Domain.Model.CargoModel.Entities
{
[JsonConverter(typeof(SingleValueObjectConverter))]
public class TransportLegId : Identity<TransportLegId>
{
public TransportLegId(string value) : base(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
using System.Text.RegularExpressions;
using EventFlow.Core;
using EventFlow.ValueObjects;
using Newtonsoft.Json;

namespace EventFlow.Examples.Shipping.Domain.Model.LocationModel
{
[JsonConverter(typeof(SingleValueObjectConverter))]
public class LocationId : SingleValueObject<string>, IIdentity
{
private static readonly Regex ValidValues = new Regex("[a-zA-Z]{2}[a-zA-Z2-9]{3}", RegexOptions.Compiled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

using EventFlow.Core;
using EventFlow.ValueObjects;
using Newtonsoft.Json;

namespace EventFlow.Examples.Shipping.Domain.Model.VoyageModel
{
[JsonConverter(typeof(SingleValueObjectConverter))]
public class VoyageId : SingleValueObject<string>, IIdentity
{
public VoyageId(string value) : base(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using EventFlow.ValueObjects;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;

namespace EventFlow.MongoDB.ValueObjects
{
Expand All @@ -34,25 +33,19 @@ public class MongoDbEventDataModel : ValueObject, ICommittedDomainEvent
[BsonElement("_id")]
public long _id { get; set; }

[JsonProperty("batchId")]
[BsonGuidRepresentation(GuidRepresentation.Standard)]
public Guid BatchId { get; set; }

long? _version { get; set; }

[JsonProperty("aggregateId")]
public string AggregateId { get; set; }

[JsonProperty("aggregateName")]
public string AggregateName { get; set; }

[JsonProperty("aggregateSequenceNumber")]
public int AggregateSequenceNumber { get; set; }

[JsonProperty("data")]
public string Data { get; set; }

[JsonProperty("metaData")]
public string Metadata { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using EventFlow.ValueObjects;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Newtonsoft.Json;

namespace EventFlow.MongoDB.ValueObjects
{
Expand All @@ -32,15 +31,10 @@ public class MongoDbSnapshotDataModel : ValueObject
[BsonElement("_id")]
public ObjectId _id { get; set; }
long? _version { get; set; }
[JsonProperty("aggregateId")]
public string AggregateId { get; set; }
[JsonProperty("aggregateName")]
public string AggregateName { get; set; }
[JsonProperty("aggregateSequenceNumber")]
public int AggregateSequenceNumber { get; set; }
[JsonProperty("data")]
public string Data { get; set; }
[JsonProperty("metaData")]
public string Metadata { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ [MagicId] ASC
)");

_serviceProvider = EventFlowOptions.New()
.AddNewtonsoftJson()
.AddEvents(new []{typeof(MagicEvent)})
.AddCommands(new []{typeof(MagicCommand)})
.AddCommandHandlers(typeof(MagicCommandHandler))
Expand Down
3 changes: 2 additions & 1 deletion Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ private IServiceProvider BuildProvider(Exchange exchange, Func<IEventFlowOptions
var eventFlowOptions = configure(EventFlowOptions.New()
.PublishToRabbitMq(RabbitMqConfiguration.With(_uri, false, exchange: exchange.Value))
.AddDefaults(EventFlowTestHelpers.Assembly)
.RegisterServices(c => c.AddTransient<IScopedContext, ScopedContext>()));
.RegisterServices(c => c.AddTransient<IScopedContext, ScopedContext>()))
.AddNewtonsoftJson();

return eventFlowOptions.ServiceCollection.BuildServiceProvider();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net6.0;net8.0;net10.0</TargetFrameworks>
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj" />
<ProjectReference Include="..\EventFlow.Serialization.NewtonsoftJson\EventFlow.Serialization.NewtonsoftJson.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2025 Rasmus Mikkelsen
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// 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.Core;
using EventFlow.TestHelpers.Suites;
using Newtonsoft.Json;
using NUnit.Framework;
using Shouldly;

namespace EventFlow.Serialization.NewtonsoftJson.Tests
{
[TestFixture]
public class NewtonsoftJsonSerializerTests : TestSuiteForJsonSerializer
{
protected override IJsonSerializer CreateSerializer()
{
return new NewtonsoftJsonSerializer();
}

[Test]
public void JsonProperty_RenamesPropertyOnSerialize()
{
var sut = CreateSerializer();

var json = sut.Serialize(new WithAttributes {Renamed = "value"});

json.ShouldContain("\"custom_name\"");
json.ShouldNotContain(nameof(WithAttributes.Renamed));
}

[Test]
public void JsonProperty_RenamedPropertyRoundTrips()
{
var sut = CreateSerializer();

var json = sut.Serialize(new WithAttributes {Renamed = "value"});
var result = sut.Deserialize<WithAttributes>(json);

result.Renamed.ShouldBe("value");
}

[Test]
public void JsonIgnore_OmitsPropertyOnSerialize()
{
var sut = CreateSerializer();

var json = sut.Serialize(new WithAttributes {Ignored = "secret"});

json.ShouldNotContain("secret");
json.ShouldNotContain(nameof(WithAttributes.Ignored));
}

[Test]
public void JsonIgnore_IgnoredPropertyIsNotRestoredOnDeserialize()
{
var sut = CreateSerializer();

var json = sut.Serialize(new WithAttributes {Ignored = "secret"});
var result = sut.Deserialize<WithAttributes>(json);

result.Ignored.ShouldBeNull();
}

public class WithAttributes
{
[JsonProperty("custom_name")]
public string Renamed { get; set; }

[JsonIgnore]
public string Ignored { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using NUnit.Framework;
using Shouldly;

namespace EventFlow.Tests.UnitTests.ValueObjects
namespace EventFlow.Serialization.NewtonsoftJson.Tests
{
[Category(Categories.Unit)]
public class SingleValueObjectConverterTests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netcoreapp3.1;net6.0;net8.0;net10.0</TargetFrameworks>
<Title>EventFlow.Serialization.NewtonsoftJson</Title>
<Description>Newtonsoft.Json based JSON serializer for EventFlow - https://docs.geteventflow.net/</Description>
<PackageTags>CQRS ES event sourcing json newtonsoft</PackageTags>
<PackageReleaseNotes>UPDATED BY BUILD</PackageReleaseNotes>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\EventFlow.Serialization.NewtonsoftJson.xml</DocumentationFile>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2021.1.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EventFlow\EventFlow.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// The MIT License (MIT)
//
//
// Copyright (c) 2015-2025 Rasmus Mikkelsen
// https://github.com/eventflow/EventFlow
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
Expand All @@ -21,25 +21,22 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System;
using EventFlow.Configuration.Serialization;
using EventFlow.Core;
using EventFlow.Serialization.NewtonsoftJson;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;

namespace EventFlow.Extensions
{
public static class EventFlowOptionsJsonConfigurationExtensions
public static class EventFlowOptionsNewtonsoftJsonExtensions
{
public static IEventFlowOptions ConfigureJson(
public static IEventFlowOptions AddNewtonsoftJson(
this IEventFlowOptions eventFlowOptions,
Func<IJsonOptions, IJsonOptions> configure)
Action<JsonSerializerSettings> configure = null)
{
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}

var config = configure(JsonOptions.New);
eventFlowOptions.ServiceCollection.AddTransient(_ => config);
eventFlowOptions.ServiceCollection
.AddSingleton<IJsonSerializer>(_ => new NewtonsoftJsonSerializer(configure));
return eventFlowOptions;
}
}
}
}
Loading
Loading