diff --git a/DFlow.sln b/DFlow.sln index 5f51969..8df2dcf 100644 --- a/DFlow.sln +++ b/DFlow.sln @@ -9,10 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DFlow.Persistence", "src\DF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DFlow.Testing", "tests\DFlow.Testing\DFlow.Testing.csproj", "{8AA5683F-E4E6-4D43-95C1-30F7F5C1C301}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DFlow.Profiling", "tests\DFlow.NBench\DFlow.Profiling.csproj", "{497760E7-D2AB-448E-B098-5054F898B506}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DFlow", "src\DFlow\DFlow.csproj", "{3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DFlow.Persistence.Aggregates", "src\DFlow.Persistence.Aggregates\DFlow.Persistence.Aggregates.csproj", "{850C6B16-1FCB-4127-868D-A295A74A4F30}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,14 +37,6 @@ Global {8AA5683F-E4E6-4D43-95C1-30F7F5C1C301}.Release|Any CPU.Build.0 = Release|Any CPU {8AA5683F-E4E6-4D43-95C1-30F7F5C1C301}.Tests|Any CPU.ActiveCfg = Debug|Any CPU {8AA5683F-E4E6-4D43-95C1-30F7F5C1C301}.Tests|Any CPU.Build.0 = Debug|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Debug|Any CPU.Build.0 = Debug|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Release Profilling|Any CPU.ActiveCfg = Release Profilling|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Release Profilling|Any CPU.Build.0 = Release Profilling|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Release|Any CPU.ActiveCfg = Release|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Release|Any CPU.Build.0 = Release|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Tests|Any CPU.ActiveCfg = Debug|Any CPU - {497760E7-D2AB-448E-B098-5054F898B506}.Tests|Any CPU.Build.0 = Debug|Any CPU {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Debug|Any CPU.Build.0 = Debug|Any CPU {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Release Profilling|Any CPU.ActiveCfg = Release Profilling|Any CPU @@ -53,13 +45,20 @@ Global {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Release|Any CPU.Build.0 = Release|Any CPU {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Tests|Any CPU.ActiveCfg = Debug|Any CPU {3008E7CA-82EF-4FEC-BB5A-5098DC63BD37}.Tests|Any CPU.Build.0 = Debug|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Release Profilling|Any CPU.ActiveCfg = Release Profilling|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Release Profilling|Any CPU.Build.0 = Release Profilling|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Release|Any CPU.Build.0 = Release|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Tests|Any CPU.ActiveCfg = Debug|Any CPU + {850C6B16-1FCB-4127-868D-A295A74A4F30}.Tests|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {8AA5683F-E4E6-4D43-95C1-30F7F5C1C301} = {1D9940E4-09D4-42B9-B72D-2DA4D1AA00EB} - {497760E7-D2AB-448E-B098-5054F898B506} = {1D9940E4-09D4-42B9-B72D-2DA4D1AA00EB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {95BFE15C-2D7D-47F7-8108-AAD1B212E52D} diff --git a/src/DFlow.Persistence/DFlow.Persistence.csproj b/src/DFlow.Persistence/DFlow.Persistence.csproj index ff3d45e..4db1cd4 100644 --- a/src/DFlow.Persistence/DFlow.Persistence.csproj +++ b/src/DFlow.Persistence/DFlow.Persistence.csproj @@ -1,7 +1,16 @@  true - 10 - enable + + + + + + + + + + + diff --git a/src/DFlow.Persistence/Model/AggregateState.cs b/src/DFlow.Persistence/Model/AggregateState.cs new file mode 100644 index 0000000..a10d0ba --- /dev/null +++ b/src/DFlow.Persistence/Model/AggregateState.cs @@ -0,0 +1,25 @@ +// Copyright (C) 2020 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +using System; +using System.Text.Json; +using NodaTime; + +namespace DFlow.Persistence.Model; + +public sealed record AggregateState(Guid Id + , Guid AggregateId + , string AggregationType + , string EventType + , Instant EventDatetime + , JsonDocument EventData):IDisposable +{ + public void Dispose() + { + EventData.Dispose(); + } +} \ No newline at end of file diff --git a/src/DFlow.Persistence/Model/IsExternalInit.cs b/src/DFlow.Persistence/Model/IsExternalInit.cs new file mode 100644 index 0000000..695b61d --- /dev/null +++ b/src/DFlow.Persistence/Model/IsExternalInit.cs @@ -0,0 +1,4 @@ +namespace System.Runtime.CompilerServices +{ + internal static class IsExternalInit {} +} \ No newline at end of file diff --git a/src/DFlow.Persistence/Model/PersistentState.cs b/src/DFlow.Persistence/Model/PersistentState.cs index d9aadb6..e130251 100644 --- a/src/DFlow.Persistence/Model/PersistentState.cs +++ b/src/DFlow.Persistence/Model/PersistentState.cs @@ -6,23 +6,21 @@ using System; +namespace DFlow.Persistence.Model; -namespace DFlow.Persistence.Model +public abstract class PersistentState : IPersistentState { - public abstract class PersistentState : IPersistentState + protected PersistentState(DateTime createAt, byte[] rowVersion) { - protected PersistentState(DateTime createAt, byte[] rowVersion) - { - PersistenceId = Guid.NewGuid(); - CreateAt = createAt; - RowVersion = rowVersion; - } + PersistenceId = Guid.NewGuid(); + CreateAt = createAt; + RowVersion = rowVersion; + } - public DateTime CreateAt { get; set; } + public DateTime CreateAt { get;} - public byte[] RowVersion { get; set; } - public bool IsDeleted { get; set; } + public byte[] RowVersion { get; } + public bool IsDeleted { get; set; } - public Guid PersistenceId { get; set; } - } -} \ No newline at end of file + public Guid PersistenceId { get; set; } +} diff --git a/src/DFlow.Persistence/Outbox/IEventsExporting.cs b/src/DFlow.Persistence/Outbox/IEventsExporting.cs new file mode 100644 index 0000000..e262d4b --- /dev/null +++ b/src/DFlow.Persistence/Outbox/IEventsExporting.cs @@ -0,0 +1,17 @@ +// Copyright (C) 2023 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + + +using System.Collections.Generic; +using DFlow.BusinessObjects; +using DFlow.Persistence.Model; + +namespace DFlow.Persistence.Outbox; + +interface IEventsExporting +{ + IReadOnlyList ToOutBox(IDomainEvents entity); +} diff --git a/src/DFlow.Persistence/Repositories/IRepository.cs b/src/DFlow.Persistence/Repositories/IRepository.cs index 4a5a073..ae227b3 100644 --- a/src/DFlow.Persistence/Repositories/IRepository.cs +++ b/src/DFlow.Persistence/Repositories/IRepository.cs @@ -6,10 +6,9 @@ using System.Threading.Tasks; -namespace DFlow.Persistence.Repositories +namespace DFlow.Persistence.Repositories; + +public interface IRepository : IRepositoryAppendOnly { - public interface IRepository: IRepositoryAppendOnly - { - Task Remove(TModel entity); - } -} \ No newline at end of file + Task Remove(TModel entity); +} diff --git a/src/DFlow.Persistence/Repositories/IRepositoryAppendOnly.cs b/src/DFlow.Persistence/Repositories/IRepositoryAppendOnly.cs index 4603c91..499b572 100644 --- a/src/DFlow.Persistence/Repositories/IRepositoryAppendOnly.cs +++ b/src/DFlow.Persistence/Repositories/IRepositoryAppendOnly.cs @@ -11,11 +11,12 @@ using System.Threading; using System.Threading.Tasks; -namespace DFlow.Persistence.Repositories +namespace DFlow.Persistence.Repositories; + +public interface IRepositoryAppendOnly { - public interface IRepositoryAppendOnly - { - Task Add(TModel entity); - Task> FindAsync(Expression> predicate, CancellationToken cancellationToken); - } + Task Add(TModel entity); + + Task> FindAsync(Expression> predicate, + CancellationToken cancellationToken); } \ No newline at end of file diff --git a/src/DFlow/Aggregates/AggregateBase.cs b/src/DFlow/Aggregates/AggregateBase.cs index c0a7968..feb0f4d 100644 --- a/src/DFlow/Aggregates/AggregateBase.cs +++ b/src/DFlow/Aggregates/AggregateBase.cs @@ -4,12 +4,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DFlow.Aggregates; using DFlow.BusinessObjects; using DFlow.Events; using DFlow.Validation; -namespace DFlow.Domain.Aggregates +namespace DFlow.Aggregates { public abstract class AggregateBase:BaseValidation, IAggregate where TChange: EntityBase diff --git a/src/DFlow/BusinessObjects/AggregateId.cs b/src/DFlow/BusinessObjects/AggregateId.cs new file mode 100644 index 0000000..9a1fe07 --- /dev/null +++ b/src/DFlow/BusinessObjects/AggregateId.cs @@ -0,0 +1,23 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DFlow.BusinessObjects +{ + public sealed class AggregateId : ValueOf + { + public static AggregateId Empty() + { + return From(Guid.Empty); + } + + public static AggregateId New() + { + return From(Guid.NewGuid()); + } + } +} \ No newline at end of file diff --git a/src/DFlow/BusinessObjects/EntityBase.cs b/src/DFlow/BusinessObjects/EntityBase.cs index 61cab0a..100c86e 100644 --- a/src/DFlow/BusinessObjects/EntityBase.cs +++ b/src/DFlow/BusinessObjects/EntityBase.cs @@ -12,63 +12,61 @@ using DFlow.Events; using DFlow.Validation; -namespace DFlow.BusinessObjects +namespace DFlow.BusinessObjects; + +public abstract class EntityBase : BaseValidation, + IEntityIdentity, IDomainEvents { - public abstract class EntityBase: BaseValidation, - IEntityIdentity + private readonly IList _events = new List(); + + protected EntityBase(TIdentity identity, VersionId version) { - private readonly IList _events = new List(); - - protected EntityBase(TIdentity identity, VersionId version) - { - Identity = identity; - Version = version; - } - - public TIdentity Identity { get; } - - public VersionId Version { get; } + Identity = identity; + Version = version; + } - public bool IsNew() => Version.IsNew; + public TIdentity Identity { get; } - public void RaisedEvent(DomainEvent @event) - { - this._events.Add(@event); - } - - public IReadOnlyList GetEvents() - { - return this._events.ToImmutableList(); - } + public VersionId Version { get; } - - public override string ToString() - { - return $"[ENTITY]:[IDENTITY: {Identity}]"; - } - - protected abstract IEnumerable GetEqualityComponents(); + public bool IsNew() => Version.IsNew; - public override bool Equals(object obj) - { - if (obj == null) - { - return false; - } + public void RaisedEvent(DomainEvent @event) + { + this._events.Add(@event); + } - if (GetType() != obj.GetType()) - { - return false; - } + public IReadOnlyList GetEvents() + { + return this._events.ToImmutableList(); + } - var entity = (EntityBase)obj; + public override string ToString() + { + return $"[ENTITY]:[IDENTITY: {Identity}]"; + } + + protected abstract IEnumerable GetEqualityComponents(); - return GetEqualityComponents().SequenceEqual(entity.GetEqualityComponents()); + public override bool Equals(object obj) + { + if (obj == null) + { + return false; } - public override int GetHashCode() + if (GetType() != obj.GetType()) { - return HashCode.Combine(GetEqualityComponents()); + return false; } + + var entity = (EntityBase)obj; + + return GetEqualityComponents().SequenceEqual(entity.GetEqualityComponents()); + } + + public override int GetHashCode() + { + return HashCode.Combine(GetEqualityComponents()); } } \ No newline at end of file diff --git a/src/DFlow/BusinessObjects/EntityId.cs b/src/DFlow/BusinessObjects/EntityId.cs new file mode 100644 index 0000000..53476bd --- /dev/null +++ b/src/DFlow/BusinessObjects/EntityId.cs @@ -0,0 +1,23 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; + +namespace DFlow.BusinessObjects +{ + public sealed class EntityId : ValueOf + { + public static EntityId Empty() + { + return From(Guid.Empty); + } + + public static EntityId New() + { + return From(Guid.NewGuid()); + } + } +} \ No newline at end of file diff --git a/src/DFlow/DFlow.csproj b/src/DFlow/DFlow.csproj index 1bbc99b..d20b0be 100644 --- a/src/DFlow/DFlow.csproj +++ b/src/DFlow/DFlow.csproj @@ -3,11 +3,11 @@ Debug;Release;Release Profilling AnyCPU - enable - 10 + + diff --git a/src/DFlow/Validation/BaseValidation.cs b/src/DFlow/Validation/BaseValidation.cs index a6aaff1..97d4210 100644 --- a/src/DFlow/Validation/BaseValidation.cs +++ b/src/DFlow/Validation/BaseValidation.cs @@ -8,24 +8,23 @@ using System.Collections.Generic; using System.Collections.Immutable; -namespace DFlow.Validation +namespace DFlow.Validation; + +public abstract class BaseValidation : IValidable { - public abstract class BaseValidation: IValidable - { - private readonly List _failures = new (); + private readonly List _failures = new(); - public void AppendValidationResult(Failure failure) - { - _failures.Add(failure); - } + public void AppendValidationResult(Failure failure) + { + _failures.Add(failure); + } - public void AppendValidationResult(IReadOnlyList failures) - { - _failures.AddRange(failures); - } + public void AppendValidationResult(IReadOnlyList failures) + { + _failures.AddRange(failures); + } - public IReadOnlyList Failures => _failures.ToImmutableList(); + public IReadOnlyList Failures => _failures.ToImmutableList(); - public bool IsValid => _failures.Count == 0; - } + public bool IsValid => _failures.Count == 0; } \ No newline at end of file diff --git a/src/DFlow/Validation/ValidationResult.cs b/src/DFlow/Validation/ValidationResult.cs index 431000c..c079430 100644 --- a/src/DFlow/Validation/ValidationResult.cs +++ b/src/DFlow/Validation/ValidationResult.cs @@ -7,42 +7,41 @@ using System.Collections.Generic; using System.Collections.Immutable; -namespace DFlow.Validation +namespace DFlow.Validation; + +public sealed class ValidationResult { - public sealed class ValidationResult - { - private readonly List _failures = new(); + private readonly List _failures = new(); - public ValidationResult( IReadOnlyList failures) + public ValidationResult(IReadOnlyList failures) + { + if (failures.Count > 0) { - if (failures.Count > 0) - { - _failures.AddRange(failures); - } + _failures.AddRange(failures); } - - public bool IsValid => Failures.Count == 0; + } - public IReadOnlyList Failures => _failures; + public bool IsValid => Failures.Count == 0; - public void Append(Failure failure) - { - _failures.Add(failure); - } - - public static ValidationResult For(IReadOnlyList failures) - { - return new ValidationResult(failures); - } - - public static ValidationResult For(Failure failure) - { - return new ValidationResult(new List{failure}); - } - - public static ValidationResult Empty() - { - return new ValidationResult(ImmutableList.Empty); - } + public IReadOnlyList Failures => _failures; + + public void Append(Failure failure) + { + _failures.Add(failure); + } + + public static ValidationResult For(IReadOnlyList failures) + { + return new ValidationResult(failures); + } + + public static ValidationResult For(Failure failure) + { + return new ValidationResult(new List { failure }); + } + + public static ValidationResult Empty() + { + return new ValidationResult(ImmutableList.Empty); } } \ No newline at end of file diff --git a/tests/DFlow.Testing/DFlow.Testing.csproj b/tests/DFlow.Testing/DFlow.Testing.csproj index e650736..2405ffe 100644 --- a/tests/DFlow.Testing/DFlow.Testing.csproj +++ b/tests/DFlow.Testing/DFlow.Testing.csproj @@ -11,6 +11,7 @@ enable 10 + Library diff --git a/tests/DFlow.Testing/Domain/AggregateEntityTests.cs b/tests/DFlow.Testing/Domain/AggregateEntityTests.cs index 89276e0..a44aed2 100644 --- a/tests/DFlow.Testing/Domain/AggregateEntityTests.cs +++ b/tests/DFlow.Testing/Domain/AggregateEntityTests.cs @@ -4,6 +4,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +using DFlow.BusinessObjects; +using DFlow.Testing.Supporting.DataProviders; using DFlow.Testing.Supporting.DomainObjects; using DFlow.Testing.Supporting.DomainObjects.Aggregates; using Xunit; @@ -12,11 +14,13 @@ namespace DFlow.Testing.Domain; public class AggregateEntityTests { - // [Theory] - // [ClassData(typeof(SimpleEntityValid))] - // public void CreatePrimaryAggregate(PrimaryEntityAggregateFactory, PrimaryEntityAggregate expected) - // { - // // var entity = SimpleEntity.From(simpleEntityId, name, versionId); - // // Assert.Equal(expected, entity); - // } + [Theory] + [ClassData(typeof(PrimaryEntityForAggregate))] + public void CreatePrimaryAggregate(SecondaryEntity inputSecondary, SimpleValueObject inputValue, + PrimaryEntity expected) + { + var agg = PrimaryEntityAggregate.CreateFrom(inputSecondary, inputValue); + Assert.Equal(expected.Secondary, agg.GetChange().Secondary); + Assert.Equal(expected.SimpleValue, agg.GetChange().SimpleValue); + } } \ No newline at end of file diff --git a/tests/DFlow.Testing/Domain/PrimaryEntityTests.cs b/tests/DFlow.Testing/Domain/PrimaryEntityTests.cs new file mode 100644 index 0000000..3b207a3 --- /dev/null +++ b/tests/DFlow.Testing/Domain/PrimaryEntityTests.cs @@ -0,0 +1,32 @@ +// Copyright (C) 2023 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using DFlow.Testing.Supporting.DataProviders; +using DFlow.Testing.Supporting.DomainObjects; +using DFlow.Testing.Supporting.DomainObjects.Events; +using Xunit; + +namespace DFlow.Testing.Domain; + +public class PrimaryEntityTests +{ + [Theory] + [ClassData(typeof(PrimaryEntityValid))] + public void PrimaryEntity_Create_Valid(SecondaryEntity secondary, SimpleValueObject name, int expected) + { + var entity = PrimaryEntity.NewEntity(secondary,name); + Assert.Equal(expected, entity.GetEvents().Count); + } + + [Theory] + [ClassData(typeof(SecondaryEntityUpdate))] + public void SecondaryEntity_Updated(PrimaryEntity primary, SecondaryEntity toUpdate, SecondaryEntity expected) + { + primary.UpdateSecondary(toUpdate); + var raisedEvent = primary.GetEvents()[0] as SecondaryEntityUpdatedEvent; + Assert.Equal(expected.Identity.Value, raisedEvent.SecondaryEntityId); + } +} \ No newline at end of file diff --git a/tests/DFlow.Testing/Domain/SimpleEntityTests.cs b/tests/DFlow.Testing/Domain/SimpleEntityTests.cs index d88916b..62bbcc2 100644 --- a/tests/DFlow.Testing/Domain/SimpleEntityTests.cs +++ b/tests/DFlow.Testing/Domain/SimpleEntityTests.cs @@ -7,16 +7,15 @@ using DFlow.BusinessObjects; using DFlow.Testing.Supporting.DataProviders; using DFlow.Testing.Supporting.DomainObjects; -using Ecommerce.Domain; using Xunit; -namespace Ecommerce.Tests.Domain; +namespace DFlow.Testing.Domain; public class SimpleEntityTests { [Theory] [ClassData(typeof(SimpleEntityValid))] - public void CreateValidProduct( + public void SimpleEntity_Create_Valid( SimpleEntityId simpleEntityId, SimpleValueObject name, VersionId versionId, SimpleEntity expected) @@ -24,4 +23,11 @@ public void CreateValidProduct( var entity = SimpleEntity.From(simpleEntityId, name, versionId); Assert.Equal(expected, entity); } + + [Theory] + [ClassData(typeof(SimpleEntityInvalid))] + public void SimpleEntity_Create_InValid(SimpleEntity entity, bool expected) + { + Assert.Equal(expected, entity.IsValid); + } } \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityForAggregate.cs b/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityForAggregate.cs new file mode 100644 index 0000000..f325741 --- /dev/null +++ b/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityForAggregate.cs @@ -0,0 +1,43 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections; +using System.Collections.Generic; +using DFlow.BusinessObjects; +using DFlow.Testing.Supporting.DomainObjects; +using Ecommerce.Domain; + +namespace DFlow.Testing.Supporting.DataProviders; + +public class PrimaryEntityForAggregate : IEnumerable +{ + static SecondaryEntity secondary = SecondaryEntity.From( + SecondaryEntityId.NewId(), + SimpleValueObject.From("secondary"), + VersionId.New()); + private static SimpleValueObject simpleValue = SimpleValueObject.From("name"); + + private readonly List _data = new() + { + new object[] + { + secondary + , simpleValue + , PrimaryEntity.NewEntity(secondary,simpleValue) + } + }; + + public IEnumerator GetEnumerator() + { + return this._data.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityValid.cs b/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityValid.cs new file mode 100644 index 0000000..a2d7ee3 --- /dev/null +++ b/tests/DFlow.Testing/Supporting/DataProviders/PrimaryEntityValid.cs @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections; +using System.Collections.Generic; +using DFlow.BusinessObjects; +using DFlow.Testing.Supporting.DomainObjects; +using Ecommerce.Domain; + +namespace DFlow.Testing.Supporting.DataProviders; + +public class PrimaryEntityValid : IEnumerable +{ + private readonly List _data = new() + { + new object[] + { + SecondaryEntity.From(SecondaryEntityId.NewId(), SimpleValueObject.From("secondary"),VersionId.New()) + , SimpleValueObject.From("name") + , 1 + } + }; + + public IEnumerator GetEnumerator() + { + return this._data.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DataProviders/SecondaryEntityUpdate.cs b/tests/DFlow.Testing/Supporting/DataProviders/SecondaryEntityUpdate.cs new file mode 100644 index 0000000..61a9916 --- /dev/null +++ b/tests/DFlow.Testing/Supporting/DataProviders/SecondaryEntityUpdate.cs @@ -0,0 +1,48 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections; +using System.Collections.Generic; +using DFlow.BusinessObjects; +using DFlow.Testing.Supporting.DomainObjects; +using DFlow.Testing.Supporting.DomainObjects.Events; +using Ecommerce.Domain; + +namespace DFlow.Testing.Supporting.DataProviders; + +public class SecondaryEntityUpdate : IEnumerable +{ + static SecondaryEntity secondary = SecondaryEntity.From(SecondaryEntityId.NewId(), + SimpleValueObject.From("secondary-updated") + , VersionId.New()); + + private readonly List _data = new() + { + new object[] + { + PrimaryEntity.From( PrimaryEntityId.NewId(), + SecondaryEntity.From(SecondaryEntityId.NewId(), + SimpleValueObject.From("secondary"),VersionId.New()), + SimpleValueObject.From("secondary"), + VersionId.New()) + , secondary, + SecondaryEntity.From(secondary.Identity, + secondary.SimpleValue, + VersionId.Next(secondary.Version)) + } + }; + + public IEnumerator GetEnumerator() + { + return this._data.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DataProviders/SimpleEntityInvalid.cs b/tests/DFlow.Testing/Supporting/DataProviders/SimpleEntityInvalid.cs new file mode 100644 index 0000000..f3a9fc2 --- /dev/null +++ b/tests/DFlow.Testing/Supporting/DataProviders/SimpleEntityInvalid.cs @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Road to Agility +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +using System; +using System.Collections; +using System.Collections.Generic; +using DFlow.BusinessObjects; +using DFlow.Testing.Supporting.DomainObjects; +using Ecommerce.Domain; + +namespace DFlow.Testing.Supporting.DataProviders; + +public class SimpleEntityInvalid : IEnumerable +{ + private static Guid entityId = Guid.Empty; + private static readonly SimpleEntity entity = SimpleEntity.From( + SimpleEntityId.From(entityId), + SimpleValueObject.From(""), + VersionId.Empty() + ); + + private readonly List _data = new() + { + new object[] + { + entity, false + } + }; + + public IEnumerator GetEnumerator() + { + return this._data.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/IAggregateFactory.cs b/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/IAggregateFactory.cs deleted file mode 100644 index 56ebf79..0000000 --- a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/IAggregateFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2020 Road to Agility -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -namespace DFlow.Testing.Supporting.DomainObjects.Aggregates -{ - public interface IAggregateFactory - { - TAggregate Create(TCreateFrom source); - } -} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregate.cs b/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregate.cs index 25679fd..da96529 100644 --- a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregate.cs +++ b/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregate.cs @@ -5,7 +5,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. -using DFlow.Domain.Aggregates; +using DFlow.Aggregates; using DFlow.Testing.Supporting.DomainObjects.Events; using Ecommerce.Domain; @@ -42,4 +42,9 @@ public void Update(SecondaryEntity secondary) AppendValidationResult(primary.Failures); } + + public static PrimaryEntityAggregate CreateFrom(SecondaryEntity secondary, SimpleValueObject simpleValue) + { + return new PrimaryEntityAggregate(PrimaryEntity.NewEntity(secondary,simpleValue)); + } } \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregateFactory.cs b/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregateFactory.cs deleted file mode 100644 index 4c07238..0000000 --- a/tests/DFlow.Testing/Supporting/DomainObjects/Aggregates/PrimaryEntityAggregateFactory.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2020 Road to Agility -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - - -using System; -using DFlow.Domain.Aggregates; - -namespace DFlow.Testing.Supporting.DomainObjects.Aggregates; - -public sealed class PrimaryEntityAggregateFactory : IAggregateFactory -{ - public PrimaryEntityAggregate Create(PrimaryEntity source) - { - if (!source.IsValid) - { - throw new ArgumentException(); - } - - return new PrimaryEntityAggregate(source); - } -} \ No newline at end of file diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/PrimaryEntity.cs b/tests/DFlow.Testing/Supporting/DomainObjects/PrimaryEntity.cs index 817beeb..bad8d65 100644 --- a/tests/DFlow.Testing/Supporting/DomainObjects/PrimaryEntity.cs +++ b/tests/DFlow.Testing/Supporting/DomainObjects/PrimaryEntity.cs @@ -43,7 +43,9 @@ public static PrimaryEntity From(PrimaryEntityId id, SecondaryEntity secondary, public static PrimaryEntity NewEntity(SecondaryEntity secondary, SimpleValueObject simpleObject) { - return From(PrimaryEntityId.NewId(), secondary, simpleObject, VersionId.New()); + var entity = From(PrimaryEntityId.NewId(), secondary, simpleObject, VersionId.New()); + entity.RaisedEvent(PrimaryEntityCreatedEvent.For(entity)); + return entity; } public static PrimaryEntity Combine(PrimaryEntity primary, SecondaryEntity secondary) diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/SecondaryEntity.cs b/tests/DFlow.Testing/Supporting/DomainObjects/SecondaryEntity.cs index d491ae8..f8c4323 100644 --- a/tests/DFlow.Testing/Supporting/DomainObjects/SecondaryEntity.cs +++ b/tests/DFlow.Testing/Supporting/DomainObjects/SecondaryEntity.cs @@ -17,7 +17,7 @@ public sealed class SecondaryEntity : EntityBase public SecondaryEntity(SecondaryEntityId identity, SimpleValueObject simpleValue, VersionId version) : base(identity, version) { - + SimpleValue = simpleValue; AppendValidationResult(identity.ValidationStatus.Failures); AppendValidationResult(simpleValue.ValidationStatus.Failures); diff --git a/tests/DFlow.Testing/Supporting/DomainObjects/SimpleEntity.cs b/tests/DFlow.Testing/Supporting/DomainObjects/SimpleEntity.cs index b6c9315..ce6420a 100644 --- a/tests/DFlow.Testing/Supporting/DomainObjects/SimpleEntity.cs +++ b/tests/DFlow.Testing/Supporting/DomainObjects/SimpleEntity.cs @@ -7,8 +7,6 @@ using System.Collections.Generic; using DFlow.BusinessObjects; using DFlow.Testing.Supporting.DomainObjects.Events; -using DFlow.Validation; -using Ecommerce.Domain; namespace DFlow.Testing.Supporting.DomainObjects; @@ -17,8 +15,8 @@ public class SimpleEntity : EntityBase public SimpleEntity(SimpleEntityId identity, SimpleValueObject simpleValue, VersionId version) : base(identity, version) { + SimpleValue = simpleValue; - AppendValidationResult(identity.ValidationStatus.Failures); AppendValidationResult(simpleValue.ValidationStatus.Failures); } diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index ef83571..d74849b 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -7,9 +7,11 @@ - net6.0;netcoreapp3.1 + net6.0;netstandard2.1 Debug;Release;Release Profilling AnyCPU + 10 + enable - \ No newline at end of file +