public void MakeAnElection(MakeAnElection command, IBenefitsReadModel benefitsService)
        {
            //The method that handles the command is the ONLY place to do any validation
            //If this method thinks all is well, then applying the change MUST succeed.
            //The Apply(...) method can not fail now - the command has been deemed to be
            //valid and the state transition can now go ahead.

            if (ElectionAmountBreachsLimitForPlanYear(command.ElectionAmount.Dollars(), benefitsService, command.PlanYearBenefitId))
                throw new DomainException(
                    string.Format("The new election amount {0} exceeds the annual limit for the plan year benefit.",
                                  command.ElectionAmount.Dollars()));

            ApplyEvent(new ElectionMadeEvent
                {
                    AdministratorCode = command.AdministratorCode,
                    CompanyCode = command.CompanyCode,
                    ParticipantId = command.ParticipantId,
                    PlanYearBenefitId = command.PlanYearBenefitId,
                    ElectionAmount = command.ElectionAmount,
                    ElectionReason = command.ElectionReason,
                    PerPayPeriodAmount = 0.00m,
                    Id = command.Id,
                },
                @event => _state.Apply(@event));
        }
        public void WhenIIssueACreateElectionCommand()
        {
            //setup the "bus" components
            m_commandDispatcher = new CommandDispatcher();
            m_eventPublisher = new EventDispatcher();

            //register the command handler
            var repository = MockRepository.GenerateStub<IRepository<Election>>();
            m_commandDispatcher.Register(new MakeAnElectionCommandHandler(repository, null));

            //register the event handler
            m_eventPublisher.RegisterHandler<ElectionMadeEvent>(@event => m_electionCreatedEvent = @event);

            //wire-up the domain event to the event publisher
            DomainEvents.Register<ElectionMadeEvent>(@event => m_eventPublisher.Publish(@event));

            //create and send the command
            var command = new MakeAnElection
                              {
                                  AdministratorCode = "AdmCode",
                                  CompanyCode = "CoCode",
                                  ParticipantId = "12345",
                                  ElectionAmount = 1000,
                                  ElectionReason = "election reason",
                              };

            m_commandDispatcher.Dispatch<MakeAnElection>(command);
            
            Assert.Pass();
        }
 public ActionResult NewHsa(MakeAnElection command, FormCollection collection)
 {
     return View();
 }