-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from roadtoagility/feature_aggregate_factory
Feature aggregate factory
- Loading branch information
Showing
17 changed files
with
180 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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 DFlow.Domain.Validation; | ||
|
||
namespace DFlow.Domain.Aggregates | ||
{ | ||
public interface IAggregateFactory<out TAggregate, in TCreateFrom> | ||
where TCreateFrom: BaseValidation | ||
{ | ||
TAggregate Create(TCreateFrom source); | ||
} | ||
} |
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,22 @@ | ||
// 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.Validation; | ||
|
||
namespace DFlow.Domain.Command | ||
{ | ||
public class BaseCommand: BaseValidation, ICommand | ||
{ | ||
public DateTime When { get; } | ||
|
||
public BaseCommand() | ||
{ | ||
When = DateTime.Now; | ||
} | ||
} | ||
} |
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,16 @@ | ||
// 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; | ||
|
||
namespace DFlow.Domain.Command | ||
{ | ||
public interface ICommand | ||
{ | ||
DateTime When { get; } | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,14 +5,11 @@ | |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using AutoFixture; | ||
using AutoFixture.AutoNSubstitute; | ||
using DFlow.Domain.BusinessObjects; | ||
using DFlow.Domain.DomainEvents; | ||
using DFlow.Domain.Events; | ||
using DFlow.Tests.Supporting.DomainObjects; | ||
using DFlow.Tests.Supporting.DomainObjects.Commands; | ||
using Xunit; | ||
|
||
namespace DFlow.Tests.Domain | ||
|
@@ -31,7 +28,9 @@ public void Aggregate_create_a_valid() | |
public void Aggregate_reconstruct_a_valid() | ||
{ | ||
var be = BusinessEntity.From(EntityTestId.GetNext(), VersionId.New()); | ||
var agg = BusinessEntityAggregateRoot.ReconstructFrom(be); | ||
|
||
var factory = new ObjectBasedAggregateFactory(); | ||
var agg = factory.Create(be); | ||
|
||
Assert.True(agg.IsValid); | ||
} | ||
|
@@ -44,19 +43,19 @@ public void Aggregate_EventBased_create_a_valid() | |
fixture.Register<Name>(()=> Name.From(fixture.Create<String>())); | ||
fixture.Register<Email>(()=> Email.From("[email protected]")); | ||
|
||
var name = fixture.Create<Name>(); | ||
var email = fixture.Create<Email>(); | ||
var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email); | ||
var addEntity = fixture.Create<AddEntityCommand>(); | ||
|
||
var factory = new EventBasedAggregateFactory(); | ||
var agg = factory.Create(addEntity); | ||
Assert.Equal(nameof(EventStreamBusinessEntityAggregateRoot),agg.GetChange().Name.Value); | ||
Assert.True(agg.IsValid); | ||
} | ||
|
||
[Fact] | ||
public void Aggregate_EventBased_create_an_invalid() | ||
{ | ||
var name = Name.Empty(); | ||
var email = Email.Empty(); | ||
var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email); | ||
var factory = new EventBasedAggregateFactory(); | ||
var agg = factory.Create(new AddEntityCommand("", "")); | ||
Assert.False(agg.IsValid); | ||
} | ||
|
||
|
@@ -65,12 +64,14 @@ public void Aggregate_EventBased_valid_Entity_create() | |
{ | ||
var fixture = new Fixture() | ||
.Customize(new AutoNSubstituteCustomization{ ConfigureMembers = true }); | ||
fixture.Register<Name>(()=> Name.From(fixture.Create<String>())); | ||
fixture.Register<Email>(()=> Email.From("[email protected]")); | ||
fixture.Register<string>(()=> "[email protected]"); | ||
|
||
var name = fixture.Create<string>(); | ||
var email = fixture.Create<string>(); | ||
|
||
var factory = new EventBasedAggregateFactory(); | ||
var agg = factory.Create(new AddEntityCommand(name, email)); | ||
|
||
var name = fixture.Create<Name>(); | ||
var email = fixture.Create<Email>(); | ||
var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email); | ||
var change = agg.GetChange(); | ||
Assert.True(agg.IsValid); | ||
Assert.True(change.IsValid); | ||
|
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
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
29 changes: 29 additions & 0 deletions
29
tests/DFlow.Tests/Supporting/DomainObjects/EventBasedAggregateFactory.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,29 @@ | ||
// 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 DFlow.Domain.Aggregates; | ||
using DFlow.Domain.BusinessObjects; | ||
using DFlow.Tests.Supporting.DomainObjects.Commands; | ||
|
||
namespace DFlow.Tests.Supporting.DomainObjects | ||
{ | ||
public class EventBasedAggregateFactory: | ||
IAggregateFactory<EventStreamBusinessEntityAggregateRoot, AddEntityCommand>, | ||
IAggregateFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>> | ||
{ | ||
public EventStreamBusinessEntityAggregateRoot Create(AddEntityCommand command) | ||
{ | ||
return new EventStreamBusinessEntityAggregateRoot(command.Name, | ||
command.Mail, | ||
VersionId.New()); | ||
} | ||
|
||
public EventStreamBusinessEntityAggregateRoot Create(EventStream<EntityTestId> source) | ||
{ | ||
return new EventStreamBusinessEntityAggregateRoot(source); | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
tests/DFlow.Tests/Supporting/DomainObjects/ObjectBasedAggregateFactory.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,27 @@ | ||
// 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 DFlow.Domain.Aggregates; | ||
using DFlow.Domain.BusinessObjects; | ||
using DFlow.Tests.Supporting.DomainObjects.Commands; | ||
|
||
namespace DFlow.Tests.Supporting.DomainObjects | ||
{ | ||
public class ObjectBasedAggregateFactory: | ||
IAggregateFactory<BusinessEntityAggregateRoot, AddEntityCommand>, | ||
IAggregateFactory<BusinessEntityAggregateRoot, BusinessEntity> | ||
{ | ||
public BusinessEntityAggregateRoot Create(AddEntityCommand command) | ||
{ | ||
return new BusinessEntityAggregateRoot(BusinessEntity.New()); | ||
} | ||
|
||
public BusinessEntityAggregateRoot Create(BusinessEntity source) | ||
{ | ||
return new BusinessEntityAggregateRoot(source); | ||
} | ||
} | ||
} |
Oops, something went wrong.