Ejemplo n.º 1
0
        public void Excecute(UserRef user, PollingCentreRef pollingCentre, List <ResultDetail> results)
        {
            ResultInfo resultInfo = new ResultInfo
            {
                OriginatingPollingCentre = pollingCentre,
                CommandGeneratedByUser   = user
            };

            var res = _referendumResultRepository.GetByPollingCentre(pollingCentre);

            if (res == null)
            {
                var    resultReference  = new ResultReference();
                string reference        = resultReference.Generate(pollingCentre.Name, user.Username);
                var    newResult        = _referendumResultWorkflow.Create(resultInfo, reference);
                var    resultWithDetail = _referendumResultWorkflow.AddReferendumResultLineItems(newResult, resultInfo, results);
                var    confirmResult    = _referendumResultWorkflow.Confirm(resultWithDetail, resultInfo);
                _referendumResultRepository.Save(confirmResult);
            }
            if (res != null)
            {
                var modifiedResult = _referendumResultWorkflow.Modify(res, resultInfo, results);
                _referendumResultRepository.Save(modifiedResult);
            }
        }
        public void ResultProcessing_WhenReceived_ValidResultSaved()
        {
            //Arrange
            UserRef          user          = new UserRef(Guid.NewGuid(), "Brian Mwasi", UserType.Clerk);
            PollingCentreRef pollingCentre = new PollingCentreRef(Guid.NewGuid(), "Jamuhuri Primary");
            ResultDetail     resultDetail  = new ResultDetail {
                Candidate = new CandidateRef(Guid.NewGuid(), "Sonko", CandidateType.PartyBacked), Result = 1000
            };
            ResultDetail resultDetail1 = new ResultDetail {
                Candidate = new CandidateRef(Guid.NewGuid(), "Waititu", CandidateType.PartyBacked), Result = 2000
            };
            List <ResultDetail> resultDetails = new List <ResultDetail>();

            resultDetails.Add(resultDetail);
            resultDetails.Add(resultDetail1);
            ISenatorialResultService    senatorialResultService    = _ioc.Resolve <ISenatorialResultService>();
            ISenatorialResultRepository senatorialResultRepository = _ioc.Resolve <ISenatorialResultRepository>();

            //Act
            senatorialResultService.Excecute(user, pollingCentre, resultDetails);
            //Assert
            var senatorialResult = senatorialResultRepository.GetAll().OrderByDescending(n => n.ResultSendDate).First();

            Assert.That(senatorialResult.Id, Is.Not.EqualTo(Guid.Empty));
            Assert.IsNotNull(senatorialResult.ResultReference);
            Assert.That(senatorialResult.ResultSender, Is.EqualTo(user));
            Assert.That(senatorialResult.PollingCentre, Is.EqualTo(pollingCentre));
            Assert.That(senatorialResult.Status, Is.EqualTo(ResultStatus.Confirmed));
            Assert.That(senatorialResult.ResultSender, Is.EqualTo(user));
            Assert.That(senatorialResult.LineItems.OrderBy(n => n.Candidate.FullName).First().Candidate, Is.EqualTo(resultDetail.Candidate));
            Assert.That(senatorialResult.LineItems.OrderBy(n => n.Candidate.FullName).Last().Candidate, Is.EqualTo(resultDetail1.Candidate));
            Assert.That(senatorialResult.LineItems.OrderBy(n => n.Candidate.FullName).First().ResultCount, Is.EqualTo(resultDetail.Result));
            Assert.That(senatorialResult.LineItems.OrderBy(n => n.Candidate.FullName).Last().ResultCount, Is.EqualTo(resultDetail1.Result));
        }
        public McaResult GetByPollingCentre(PollingCentreRef pollingCentre)
        {
            using (var ctx = new VtsContext(_contextConnection.VtsConnectionString))
            {
                McaResult results = CtxSetup(ctx.McaResults)
                                    .FirstOrDefault(n => n.PollingCentre.Id == pollingCentre.Id);

                return(results);
            }
        }
Ejemplo n.º 4
0
        private ModifyPresidentialResultsCommand DefaultModifyPresidentialResultsCommand(int executionOrder, ResultRef result, PollingCentreRef pollingCentre, UserRef user)
        {
            var fixture = new Fixture();
            ModifyPresidentialResultsCommand cmd = fixture
                                                   .Build <ModifyPresidentialResultsCommand>()
                                                   .With(n => n.ApplyToResult, result)
                                                   .With(n => n.CommandGeneratedByUser, user)
                                                   .With(n => n.OriginatingPollingCentre, pollingCentre)
                                                   .Create();

            cmd.CommandId     = Guid.NewGuid();
            cmd.ApplyToResult = result;
            CandidateRef candidate = new CandidateRef(Guid.NewGuid(), "Pombe Magufuli", CandidateType.PartyBacked);
            var          res       = new ResultDetail {
                Candidate = candidate, Result = 1000
            };
            var resList = new List <ResultDetail>();

            resList.Add(res);
            cmd.ResultDetail             = resList;
            cmd.OriginatingPollingCentre = pollingCentre;
            cmd.CommandGeneratedByUser   = user;
            cmd.CommandExecutionOrder    = executionOrder;
            return(cmd);
        }
Ejemplo n.º 5
0
 private ConfirmPresidentialResultsCommand DefaultConfirmPresidentalResultsCommand(int executionOrder, ResultRef result, PollingCentreRef pollingCentre, UserRef user)
 {
     return(new ConfirmPresidentialResultsCommand
     {
         CommandId = Guid.NewGuid(),
         ApplyToResult = result,
         CommandGeneratedByUser = user,
         CommandExecutionOrder = executionOrder,
         OriginatingPollingCentre = pollingCentre
     });
 }
Ejemplo n.º 6
0
        private AddWomenRepLineItemsCommand DefaultAddWomenRepLineItemsCommand(int executionOrder, ResultRef result, PollingCentreRef pollingCentre, UserRef user)
        {
            var fixture = new Fixture();
            AddWomenRepLineItemsCommand cmd = fixture
                                              .Build <AddWomenRepLineItemsCommand>()
                                              .With(n => n.ApplyToResult, result)
                                              .Create();

            cmd.CommandId     = Guid.NewGuid();
            cmd.ApplyToResult = result;
            CandidateRef candidate = new CandidateRef(Guid.NewGuid(), "Rachel Shebesh", CandidateType.PartyBacked);
            var          res       = new ResultDetail {
                Candidate = candidate, Result = 1000
            };
            var resList = new List <ResultDetail>();

            resList.Add(res);
            cmd.ResultDetail             = resList;
            cmd.OriginatingPollingCentre = pollingCentre;
            cmd.CommandGeneratedByUser   = user;
            cmd.CommandExecutionOrder    = executionOrder;
            return(cmd);
        }