public void ResultModify_WhenCommandApplied_ValidModifiedLineItemAdded()
        {
            var result = new McaResult();
            CreateMcaResultCommand cmdCreate = DefaultCreateMcaResultCommand();

            result.Apply(cmdCreate);
            AddMcaLineItemsCommand cmdLineItem = DefaultAddMcaLineItemsCommand(2, cmdCreate.ApplyToResult, result.PollingCentre, result.ResultSender);

            result.Apply(cmdLineItem);
            ConfirmMcaResultsCommand cmdConfirm = DefaultConfirmPresidentalResultsCommand(3, cmdLineItem.ApplyToResult, result.PollingCentre, result.ResultSender);

            result.Apply(cmdConfirm);
            ModifyMcaResultsCommand cmd = DefaultModifyMcaResultsCommand(4, cmdConfirm.ApplyToResult, result.PollingCentre, result.ResultSender);

            //act
            result.Apply(cmd);
            //assert
            Assert.That(result.LineItems.Count(), Is.EqualTo(2));
            Assert.That(result.Id, Is.EqualTo(cmd.ApplyToResult.Id));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Modified));
            McaResultLineItem lineItem = result.LineItems[1];

            Assert.That(lineItem.Candidate, Is.EqualTo(cmd.ResultDetail[0].Candidate));
            Assert.That(lineItem.ResultCount, Is.EqualTo(cmd.ResultDetail[0].Result));
        }
        public void ResultConfirm_WhenCommandApplied_ResultStatusConfirmed()
        {
            var result = new McaResult();
            CreateMcaResultCommand cmdCreate = DefaultCreateMcaResultCommand();

            result.Apply(cmdCreate);
            AddMcaLineItemsCommand cmdLineItem = DefaultAddMcaLineItemsCommand(2, cmdCreate.ApplyToResult, result.PollingCentre, result.ResultSender);

            result.Apply(cmdLineItem);
            ConfirmMcaResultsCommand cmd = DefaultConfirmPresidentalResultsCommand(3, cmdLineItem.ApplyToResult, result.PollingCentre, result.ResultSender);

            //act
            result.Apply(cmd);
            //assert
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Confirmed));
        }
        public void ResultAddLineItem_WhenCommandApplied_ValidLineItemAdded()
        {
            var result = new McaResult();
            CreateMcaResultCommand cmdCreate = DefaultCreateMcaResultCommand();

            result.Apply(cmdCreate);
            AddMcaLineItemsCommand cmd = DefaultAddMcaLineItemsCommand(2, cmdCreate.ApplyToResult, result.PollingCentre, result.ResultSender);

            //act
            result.Apply(cmd);
            //assert
            Assert.That(result.LineItems.Count(), Is.EqualTo(1));
            Assert.That(result.Id, Is.EqualTo(cmd.ApplyToResult.Id));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.New));
            McaResultLineItem lineItem = result.LineItems[0];

            Assert.That(lineItem.Candidate, Is.EqualTo(cmd.ResultDetail[0].Candidate));
            Assert.That(lineItem.ResultCount, Is.EqualTo(cmd.ResultDetail[0].Result));
        }
        public void ResultCreation_WhenCommandApplied_ValidNewResult()
        {
            var result = new McaResult();
            CreateMcaResultCommand cmd = DefaultCreateMcaResultCommand();

            //act
            result.Apply(cmd);
            //assert
            Assert.That(result.Id, Is.Not.EqualTo(Guid.Empty));
            Assert.That(result.Id, Is.EqualTo(cmd.ApplyToResult.Id));
            Assert.That(result.Status, Is.EqualTo(ResultStatus.New));
            Assert.That(result.ResultReference, Is.EqualTo(cmd.ResultReference));
            Assert.That(result.PollingCentre, Is.EqualTo(cmd.OriginatingPollingCentre));
            Assert.That(result.ResultSender, Is.EqualTo(cmd.CommandGeneratedByUser));
            Assert.That(result.LineItems.Count(), Is.EqualTo(0));
        }
        public McaResult Confirm(McaResult result, ResultInfo originatingInfo)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
            };
            ConfirmMcaResultsCommand confirmMcaResultsCommand = new ConfirmMcaResultsCommand
            {
                CommandId = Guid.NewGuid(),
                CommandGeneratedByUser   = commandInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = commandInfo.OriginatingPollingCentre,
                ApplyToResult            = result.GetResultRef(),
                CommandExecutionOrder    = result.LastResultCommandExecutedOrder + 1,
            };

            result.Apply(confirmMcaResultsCommand);
            return(result);
        }
        public McaResult Modify(McaResult result, ResultInfo originatingInfo,
                                List <ResultDetail> resultDetails)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
            };

            var command = new ModifyMcaResultsCommand
            {
                CommandId = Guid.NewGuid(),
                CommandGeneratedByUser   = commandInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = commandInfo.OriginatingPollingCentre,
                ApplyToResult            = result.GetResultRef(),
                CommandExecutionOrder    = result.LastResultCommandExecutedOrder + 1,
                ResultDetail             = resultDetails,
            };

            result.Apply(command);
            return(result);
        }
        public McaResult Create(ResultInfo originatingInfo, string documentReference)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
                ResultReference          = documentReference
            };
            CreateMcaResultCommand createMcaResultCommand = new CreateMcaResultCommand
            {
                CommandId = Guid.NewGuid(),
                CommandGeneratedByUser   = commandInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = commandInfo.OriginatingPollingCentre,
                ApplyToResult            = new ResultRef(Guid.NewGuid(), ResultType.MemberOfCountyAssembly),
                ResultReference          = commandInfo.ResultReference,
                ResultDate            = DateTime.Now,
                CommandExecutionOrder = 1
            };
            var result = new McaResult();

            result.Apply(createMcaResultCommand);
            return(result);
        }