Skip to content

Commit

Permalink
Added missing commands and logic to auto register each command its co…
Browse files Browse the repository at this point in the history
…mmand handler
  • Loading branch information
Mark Nijhof authored and Mark Nijhof committed Oct 15, 2009
1 parent 8263844 commit e61b853
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ _ReSharper.*
*~ *~
*.swp *.swp
/Build /Build
NDependOut NDependOut
.svn
*.chm
12 changes: 0 additions & 12 deletions Fohjin.DDD/.gitignore

This file was deleted.

Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,3 @@
using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Configuration; using Fohjin.DDD.Configuration;
using StructureMap; using StructureMap;


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Fohjin.DDD.Commands;

namespace Fohjin.DDD.CommandHandlers
{
public class AccountNameGotChangedCommandHandler : ICommandHandler<AccountNameGotChangedCommand>
{
public void Execute(AccountNameGotChangedCommand command)
{
throw new NotImplementedException();
}
}
}
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Fohjin.DDD.Commands;

namespace Fohjin.DDD.CommandHandlers
{
public class ClientChangedTheirNameCommandHandler : ICommandHandler<ClientChangedTheirNameCommand>
{
public void Execute(ClientChangedTheirNameCommand command)
{
throw new NotImplementedException();
}
}
}
13 changes: 13 additions & 0 deletions Fohjin.DDD/Fohjin.DDD.CommandHandlers/ClientCreatedCommand.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Fohjin.DDD.Commands;

namespace Fohjin.DDD.CommandHandlers
{
public class ClientCreatedCommandHandler : ICommandHandler<ClientCreatedCommand>
{
public void Execute(ClientCreatedCommand command)
{
throw new NotImplementedException();
}
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


namespace Fohjin.DDD.CommandHandlers namespace Fohjin.DDD.CommandHandlers
{ {
public class CloseAnAccountCommandHandler : ICommandHandler<CloseAccountCommand> public class CloseAccountCommandHandler : ICommandHandler<CloseAccountCommand>
{ {
private readonly IRepository<ActiveAccount> _repository; private readonly IRepository<ActiveAccount> _repository;


public CloseAnAccountCommandHandler(IRepository<ActiveAccount> repository) public CloseAccountCommandHandler(IRepository<ActiveAccount> repository)
{ {
_repository = repository; _repository = repository;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AccountNameGotChangedCommandHandler.cs" />
<Compile Include="AddNewAccountToClientCommandHandler.cs" /> <Compile Include="AddNewAccountToClientCommandHandler.cs" />
<Compile Include="ClientChangedTheirNameCommandHandler.cs" />
<Compile Include="ClientCreatedCommand.cs" />
<Compile Include="ClientHasMovedCommandHandler.cs" /> <Compile Include="ClientHasMovedCommandHandler.cs" />
<Compile Include="ClientPhoneNumberIsChangedCommandHandler.cs" /> <Compile Include="ClientPhoneNumberIsChangedCommandHandler.cs" />
<Compile Include="CloseAnAccountCommandHandler.cs" /> <Compile Include="CloseAnAccountCommandHandler.cs" />
<Compile Include="CommandHandlerRegister.cs" />
<Compile Include="ICommandHandler.cs" /> <Compile Include="ICommandHandler.cs" />
<Compile Include="CashDepositeCommandHandler.cs" /> <Compile Include="CashDepositeCommandHandler.cs" />
<Compile Include="CashWithdrawlCommandHandler.cs" /> <Compile Include="CashWithdrawlCommandHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TransferMoneyToAnOtherAccountCommandHandler.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Fohjin.DDD.Bus\Fohjin.DDD.Bus.csproj"> <ProjectReference Include="..\Fohjin.DDD.Bus\Fohjin.DDD.Bus.csproj">
Expand Down
5 changes: 1 addition & 4 deletions Fohjin.DDD/Fohjin.DDD.CommandHandlers/ICommandHandler.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@


namespace Fohjin.DDD.CommandHandlers namespace Fohjin.DDD.CommandHandlers
{ {
public interface ICommandHandler public interface ICommandHandler {}
{

}
public interface ICommandHandler<TCommand> : ICommandHandler where TCommand : class, ICommand public interface ICommandHandler<TCommand> : ICommandHandler where TCommand : class, ICommand
{ {
void Execute(TCommand command); void Execute(TCommand command);
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using Fohjin.DDD.Commands;

namespace Fohjin.DDD.CommandHandlers
{
public class TransferMoneyToAnOtherAccountCommandHandler : ICommandHandler<TransferMoneyToAnOtherAccountCommand>
{
public void Execute(TransferMoneyToAnOtherAccountCommand command)
{
throw new NotImplementedException();
}
}
}
Original file line number Original file line Diff line number Diff line change
@@ -1,9 +1,10 @@
using System; using System;
using System.Linq; using System.Linq;
using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Commands; using Fohjin.DDD.Commands;
using StructureMap.Configuration.DSL; using StructureMap.Configuration.DSL;


namespace Fohjin.DDD.CommandHandlers namespace Fohjin.DDD.Configuration
{ {
public class CommandHandlerRegister : Registry public class CommandHandlerRegister : Registry
{ {
Expand All @@ -22,15 +23,6 @@ public CommandHandlerRegister()
ForRequestedType(typeof (ICommandHandler<>).MakeGenericType(type)) ForRequestedType(typeof (ICommandHandler<>).MakeGenericType(type))
.TheDefaultIsConcreteType(handlerType); .TheDefaultIsConcreteType(handlerType);
} }


//ForRequestedType<ICommandHandler<ClientHasMovedCommand>>().TheDefaultIsConcreteType<ClientHasMovedCommandHandler>();
//ForRequestedType<ICommandHandler<ClientPhoneNumberIsChangedCommand>>().TheDefaultIsConcreteType<ClientPhoneNumberIsChangedCommandHandler>();

//ForRequestedType<ICommandHandler<AddNewAccountToClientCommand>>().TheDefaultIsConcreteType<AddNewAccountToClientCommandHandler>();
//ForRequestedType<ICommandHandler<CashDepositeCommand>>().TheDefaultIsConcreteType<CashDepositeCommandHandler>();
//ForRequestedType<ICommandHandler<CashWithdrawlCommand>>().TheDefaultIsConcreteType<CashWithdrawlCommandHandler>();
//ForRequestedType<ICommandHandler<CloseAccountCommand>>().TheDefaultIsConcreteType<CloseAnAccountCommandHandler>();
} }
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CommandHandlerRegister.cs" />
<Compile Include="ReportingDatabaseBootStrapper.cs" /> <Compile Include="ReportingDatabaseBootStrapper.cs" />
<Compile Include="DomainDatabaseBootStrapper.cs" /> <Compile Include="DomainDatabaseBootStrapper.cs" />
<Compile Include="DomainRegistry.cs" /> <Compile Include="DomainRegistry.cs" />
Expand All @@ -68,6 +69,14 @@
<Project>{14C6E3E5-D4D0-4811-BBBC-89A5FF7BF41F}</Project> <Project>{14C6E3E5-D4D0-4811-BBBC-89A5FF7BF41F}</Project>
<Name>Fohjin.DDD.Bus</Name> <Name>Fohjin.DDD.Bus</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Fohjin.DDD.CommandHandlers\Fohjin.DDD.CommandHandlers.csproj">
<Project>{7757DA0F-CD51-4753-95C8-8632177AA60E}</Project>
<Name>Fohjin.DDD.CommandHandlers</Name>
</ProjectReference>
<ProjectReference Include="..\Fohjin.DDD.Commands\Fohjin.DDD.Commands.csproj">
<Project>{58D61FA0-D67F-4D72-81EA-2D709356AF95}</Project>
<Name>Fohjin.DDD.Commands</Name>
</ProjectReference>
<ProjectReference Include="..\Fohjin.DDD.Domain\Fohjin.DDD.Domain.csproj"> <ProjectReference Include="..\Fohjin.DDD.Domain\Fohjin.DDD.Domain.csproj">
<Project>{0FB24C8F-FA8C-409E-A71C-8580F7D78474}</Project> <Project>{0FB24C8F-FA8C-409E-A71C-8580F7D78474}</Project>
<Name>Fohjin.DDD.Domain</Name> <Name>Fohjin.DDD.Domain</Name>
Expand Down
32 changes: 32 additions & 0 deletions Fohjin.DDD/Test.Fohjin.DDD/Domain/AggregateRootTestFixture.cs
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Domain; using Fohjin.DDD.Domain;
using Fohjin.DDD.Events; using Fohjin.DDD.Events;
using NUnit.Framework; using NUnit.Framework;
Expand Down Expand Up @@ -36,6 +37,37 @@ public void Setup()
} }
} }


[TestFixture]
public abstract class AggregateRootUsingCommandHandlerTestFixture<TAggregateRoot, TCommandHandler>
where TAggregateRoot : IEventProvider, new()
where TCommandHandler : ICommandHandler, new()
{
protected TAggregateRoot aggregateRoot;
protected Exception caught;
protected IEnumerable<IDomainEvent> events;

protected abstract IEnumerable<IDomainEvent> Given();
protected abstract void When();

[SetUp]
public void Setup()
{
caught = null;
aggregateRoot = new TAggregateRoot();
aggregateRoot.LoadFromHistory(Given());

try
{
When();
events = aggregateRoot.GetChanges();
}
catch (Exception e)
{
caught = e;
}
}
}

public class ThenAttribute : TestAttribute { } public class ThenAttribute : TestAttribute { }
public class SpecificationAttribute : TestFixtureAttribute { } public class SpecificationAttribute : TestFixtureAttribute { }


Expand Down
4 changes: 4 additions & 0 deletions Fohjin.DDD/Test.Fohjin.DDD/Test.Fohjin.DDD.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
<Compile Include="Reporting\Infrastructure\TestDtoCase1.cs" /> <Compile Include="Reporting\Infrastructure\TestDtoCase1.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Fohjin.DDD.CommandHandlers\Fohjin.DDD.CommandHandlers.csproj">
<Project>{7757DA0F-CD51-4753-95C8-8632177AA60E}</Project>
<Name>Fohjin.DDD.CommandHandlers</Name>
</ProjectReference>
<ProjectReference Include="..\Fohjin.DDD.Configuration\Fohjin.DDD.Configuration.csproj"> <ProjectReference Include="..\Fohjin.DDD.Configuration\Fohjin.DDD.Configuration.csproj">
<Project>{CF50373D-3EB9-492D-A88F-70D7D6756DFF}</Project> <Project>{CF50373D-3EB9-492D-A88F-70D7D6756DFF}</Project>
<Name>Fohjin.DDD.Configuration</Name> <Name>Fohjin.DDD.Configuration</Name>
Expand Down

0 comments on commit e61b853

Please sign in to comment.