Exemplo n.º 1
0
        public void Run()
        {
            var result = new MpResult(Solution.Length);

            MpFit.MpFit.Solve(ComputeResiduals, Data.Count, Solution.Length, Solution,
                              null, null, null, ref result);
        }
        public void ResultModify_WhenCommandApplied_ValidModifiedLineItemAdded()
        {
            var result = new MpResult();
            CreateMpResultCommand cmdCreate = DefaultCreateMpResultCommand();

            result.Apply(cmdCreate);
            AddMpLineItemsCommand cmdLineItem = DefaultAddMpLineItemsCommand(2, cmdCreate.ApplyToResult, result.PollingCentre, result.ResultSender);

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

            result.Apply(cmdConfirm);
            ModifyMpResultsCommand cmd = DefaultModifyMpResultsCommand(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));
            MpResultLineItem lineItem = result.LineItems[1];

            Assert.That(lineItem.Candidate, Is.EqualTo(cmd.ResultDetail[0].Candidate));
            Assert.That(lineItem.ResultCount, Is.EqualTo(cmd.ResultDetail[0].Result));
        }
Exemplo n.º 3
0
 public void Save(MpResult result)
 {
     using (var ctx = new VtsContext(_contextConnection.VtsConnectionString))
     {
         ctx.UpdateGraph(result, map => map.OwnedCollection(n => n.LineItems));
         ctx.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public MpResult GetByPollingCentre(PollingCentreRef pollingCentre)
        {
            using (var ctx = new VtsContext(_contextConnection.VtsConnectionString))
            {
                MpResult results = CtxSetup(ctx.MpResults)
                                   .FirstOrDefault(n => n.PollingCentre.Id == pollingCentre.Id);

                return(results);
            }
        }
Exemplo n.º 5
0
        public MpResult GetById(Guid id)
        {
            using (var ctx = new VtsContext(_contextConnection.VtsConnectionString))
            {
                MpResult results = CtxSetup(ctx.MpResults)
                                   .FirstOrDefault(n => n.Id == id);

                return(results);
            }
        }
        public void ResultConfirm_WhenCommandApplied_ResultStatusConfirmed()
        {
            var result = new MpResult();
            CreateMpResultCommand cmdCreate = DefaultCreateMpResultCommand();

            result.Apply(cmdCreate);
            AddMpLineItemsCommand cmdLineItem = DefaultAddMpLineItemsCommand(2, cmdCreate.ApplyToResult, result.PollingCentre, result.ResultSender);

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

            //act
            result.Apply(cmd);
            //assert
            Assert.That(result.Status, Is.EqualTo(ResultStatus.Confirmed));
        }
        public void ResultCreation_WhenCommandApplied_ValidNewResult()
        {
            var result = new MpResult();
            CreateMpResultCommand cmd = DefaultCreateMpResultCommand();

            //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 void ResultAddLineItem_WhenCommandApplied_ValidLineItemAdded()
        {
            var result = new MpResult();
            CreateMpResultCommand cmdCreate = DefaultCreateMpResultCommand();

            result.Apply(cmdCreate);
            AddMpLineItemsCommand cmd = DefaultAddMpLineItemsCommand(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));
            MpResultLineItem lineItem = result.LineItems[0];

            Assert.That(lineItem.Candidate, Is.EqualTo(cmd.ResultDetail[0].Candidate));
            Assert.That(lineItem.ResultCount, Is.EqualTo(cmd.ResultDetail[0].Result));
        }
Exemplo n.º 9
0
        public MpResult Confirm(MpResult result, ResultInfo originatingInfo)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
            };
            ConfirmMpResultsCommand confirmMpResultsCommand = new ConfirmMpResultsCommand
            {
                CommandId = Guid.NewGuid(),
                CommandGeneratedByUser   = commandInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = commandInfo.OriginatingPollingCentre,
                ApplyToResult            = result.GetResultRef(),
                CommandExecutionOrder    = result.LastResultCommandExecutedOrder + 1,
            };

            result.Apply(confirmMpResultsCommand);
            return(result);
        }
Exemplo n.º 10
0
        public MpResult Modify(MpResult result, ResultInfo originatingInfo,
                               List <ResultDetail> resultDetails)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
            };

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

            result.Apply(command);
            return(result);
        }
Exemplo n.º 11
0
        public MpResult Create(ResultInfo originatingInfo, string documentReference)
        {
            CommandInfo commandInfo = new CommandInfo
            {
                CommandGeneratedByUser   = originatingInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = originatingInfo.OriginatingPollingCentre,
                ResultReference          = documentReference
            };
            CreateMpResultCommand createMpResultCommand = new CreateMpResultCommand
            {
                CommandId = Guid.NewGuid(),
                CommandGeneratedByUser   = commandInfo.CommandGeneratedByUser,
                OriginatingPollingCentre = commandInfo.OriginatingPollingCentre,
                ApplyToResult            = new ResultRef(Guid.NewGuid(), ResultType.MemberOfParliament),
                ResultReference          = commandInfo.ResultReference,
                ResultDate            = DateTime.Now,
                CommandExecutionOrder = 1
            };
            var result = new MpResult();

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