Permalink
Browse files

Added missing commands and logic to auto register each command its co…

…mmand handler
  • Loading branch information...
1 parent 8263844 commit e61b85367ae82b09f539458f423074cb617b0112 Mark Nijhof committed Oct 15, 2009
View
@@ -9,4 +9,6 @@ _ReSharper.*
*~
*.swp
/Build
-NDependOut
+NDependOut
+.svn
+*.chm
View
@@ -1,12 +0,0 @@
-obj
-bin
-_ReSharper.*
-*.csproj.user
-*.resharper.user
-*.resharper
-*.suo
-*.cache
-*~
-*.swp
-/Build
-NDependOut
@@ -1,4 +1,3 @@
-using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Configuration;
using StructureMap;
@@ -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();
+ }
+ }
+}
@@ -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();
+ }
+ }
+}
@@ -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();
+ }
+ }
+}
@@ -4,11 +4,11 @@
namespace Fohjin.DDD.CommandHandlers
{
- public class CloseAnAccountCommandHandler : ICommandHandler<CloseAccountCommand>
+ public class CloseAccountCommandHandler : ICommandHandler<CloseAccountCommand>
{
private readonly IRepository<ActiveAccount> _repository;
- public CloseAnAccountCommandHandler(IRepository<ActiveAccount> repository)
+ public CloseAccountCommandHandler(IRepository<ActiveAccount> repository)
{
_repository = repository;
}
@@ -49,15 +49,18 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="AccountNameGotChangedCommandHandler.cs" />
<Compile Include="AddNewAccountToClientCommandHandler.cs" />
+ <Compile Include="ClientChangedTheirNameCommandHandler.cs" />
+ <Compile Include="ClientCreatedCommand.cs" />
<Compile Include="ClientHasMovedCommandHandler.cs" />
<Compile Include="ClientPhoneNumberIsChangedCommandHandler.cs" />
<Compile Include="CloseAnAccountCommandHandler.cs" />
- <Compile Include="CommandHandlerRegister.cs" />
<Compile Include="ICommandHandler.cs" />
<Compile Include="CashDepositeCommandHandler.cs" />
<Compile Include="CashWithdrawlCommandHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="TransferMoneyToAnOtherAccountCommandHandler.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fohjin.DDD.Bus\Fohjin.DDD.Bus.csproj">
@@ -2,10 +2,7 @@
namespace Fohjin.DDD.CommandHandlers
{
- public interface ICommandHandler
- {
-
- }
+ public interface ICommandHandler {}
public interface ICommandHandler<TCommand> : ICommandHandler where TCommand : class, ICommand
{
void Execute(TCommand command);
@@ -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();
+ }
+ }
+}
@@ -1,9 +1,10 @@
using System;
using System.Linq;
+using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Commands;
using StructureMap.Configuration.DSL;
-namespace Fohjin.DDD.CommandHandlers
+namespace Fohjin.DDD.Configuration
{
public class CommandHandlerRegister : Registry
{
@@ -22,15 +23,6 @@ public CommandHandlerRegister()
ForRequestedType(typeof (ICommandHandler<>).MakeGenericType(type))
.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>();
}
}
}
@@ -53,6 +53,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="CommandHandlerRegister.cs" />
<Compile Include="ReportingDatabaseBootStrapper.cs" />
<Compile Include="DomainDatabaseBootStrapper.cs" />
<Compile Include="DomainRegistry.cs" />
@@ -68,6 +69,14 @@
<Project>{14C6E3E5-D4D0-4811-BBBC-89A5FF7BF41F}</Project>
<Name>Fohjin.DDD.Bus</Name>
</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">
<Project>{0FB24C8F-FA8C-409E-A71C-8580F7D78474}</Project>
<Name>Fohjin.DDD.Domain</Name>
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Fohjin.DDD.CommandHandlers;
using Fohjin.DDD.Domain;
using Fohjin.DDD.Events;
using NUnit.Framework;
@@ -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 SpecificationAttribute : TestFixtureAttribute { }
@@ -69,6 +69,10 @@
<Compile Include="Reporting\Infrastructure\TestDtoCase1.cs" />
</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">
<Project>{CF50373D-3EB9-492D-A88F-70D7D6756DFF}</Project>
<Name>Fohjin.DDD.Configuration</Name>

0 comments on commit e61b853

Please sign in to comment.