public void Simple_Status_Candidate()
        {
            IRaceRepository           raceRepository           = Substitute.For <IRaceRepository>();
            IPoliticalPartyRepository politicalPartyRepository = Substitute.For <IPoliticalPartyRepository>();
            var f              = new Fixture();
            var race           = f.Create <Race>();
            var politicalParty = f.Create <PoliticalParty>();
            var candidate      = Create();

            raceRepository.GetById(Arg.Any <Guid>()).Returns(race);
            politicalPartyRepository.GetById(Arg.Any <Guid>()).Returns(politicalParty);
            var candidateRepository = new CandidateRepository(ContextConnection(), politicalPartyRepository, raceRepository);

            candidateRepository.Save(candidate);
            candidateRepository.SetInactive(candidate);
            var inactive = candidateRepository.GetById(candidate.Id);

            Assert.That(inactive.Status == EntityStatus.Inactive);

            candidateRepository.SetActive(candidate);
            var active = candidateRepository.GetById(candidate.Id);

            Assert.That(active.Status == EntityStatus.Active);

            candidateRepository.SetAsDeleted(candidate);
            var deleted = candidateRepository.GetById(candidate.Id);

            Assert.That(deleted.Status == EntityStatus.Deleted);
        }
 public HttpResponseMessage Get([Bind(Include = "Id")] long Id)
 {
     try
     {
         if (ModelState.IsValid)
         {
             CandidateRepository     rep  = new CandidateRepository();
             IEnumerable <Candidate> list = Mapper.ToList <Candidate>(rep.GetById(Id));
             if (list != null && list.Count() > 0)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, list.FirstOrDefault()));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NoContent));
             }
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
        public void SimpeDeHydrate_Candidate()
        {
            IRaceRepository           raceRepository           = Substitute.For <IRaceRepository>();
            IPoliticalPartyRepository politicalPartyRepository = Substitute.For <IPoliticalPartyRepository>();
            var f              = new Fixture();
            var race           = f.Create <Race>();
            var politicalParty = f.Create <PoliticalParty>();
            var candidate      = Create();

            raceRepository.GetById(Arg.Any <Guid>()).Returns(race);
            politicalPartyRepository.GetById(Arg.Any <Guid>()).Returns(politicalParty);
            var candidateRepository = new CandidateRepository(ContextConnection(), politicalPartyRepository, raceRepository);
            var id    = candidateRepository.Save(candidate);
            var owner = candidateRepository.GetById(id);

            Assert.IsNotNull(owner);
            Assert.AreEqual(owner.Id, candidate.Id);
        }
Exemple #4
0
        private List <ISupplierBacs> BuildSupplierPayments(IEnumerable <IInvoiceTransaction> invoiceTransactions)
        {
            var results = new List <ISupplierBacs>();

            var transactionsByCandidateAndInvoiceId = invoiceTransactions.GroupBy(transaction => new
            {
                transaction.InvoiceId,
                transaction.SupplierId
            });

            foreach (var transactionGroup in transactionsByCandidateAndInvoiceId)
            {
                var candidateRepository = new CandidateRepository();
                var candidate           = candidateRepository.GetById(transactionGroup.Key.SupplierId);

                if (candidate == null)
                {
                    throw new InvalidOperationException(string.Format(LOAD_CANDIDATE_ERROR,
                                                                      transactionGroup.Key.SupplierId));
                }

                var result = new SupplierBacs();

                var bank = candidate.BankDetails;

                result.BankDetails.AccountName   = bank.AccountName;
                result.BankDetails.AccountNumber = bank.AccountNumber;
                result.BankDetails.SortCode      = bank.SortCode;
                result.PaymentAmount             = transactionGroup.Sum(invoiceTransaction => invoiceTransaction.Gross);
                result.InvoiceReference          = string.IsNullOrEmpty(transactionGroup.First().InvoiceReference)
                    ? NOT_AVAILABLE
                    : transactionGroup.First().InvoiceReference;
                result.PaymentReference = string.Format(BACS_RESULT_REFERENCE_FORMAT,
                                                        transactionGroup.First().InvoiceDate.GetValueOrDefault().ToString(BACS_RESULT_REFERENCE_DATE_FORMAT));

                results.Add(result);
            }

            return(results);
        }
        public List <PaymentDetail> Build(IEnumerable <InvoiceTransaction> invoiceTransactions)
        {
            var results = new List <PaymentDetail>();

            var transactionsByCandidateAndInvoiceId = invoiceTransactions.GroupBy(transaction => new
            {
                transaction.InvoiceId,
                transaction.SupplierId
            });

            foreach (var transactionGroup in transactionsByCandidateAndInvoiceId)
            {
                var candidateRepository = new CandidateRepository();
                var candidate           = candidateRepository.GetById(transactionGroup.Key.SupplierId);

                if (candidate == null)
                {
                    throw new InvalidOperationException(string.Format("Could not load candidate with Id {0}",
                                                                      transactionGroup.Key.SupplierId));
                }

                var result = new PaymentDetail();

                var bank = candidate.BankDetails;

                result.AccountName      = bank.AccountName;
                result.AccountNumber    = bank.AccountNumber;
                result.SortCode         = bank.SortCode;
                result.Amount           = transactionGroup.Sum(invoiceTransaction => invoiceTransaction.Gross);
                result.InvoiceReference = string.IsNullOrEmpty(transactionGroup.First().InvoiceRef)
                    ? NOT_AVAILABLE
                    : transactionGroup.First().InvoiceRef;
                result.PaymentReference = string.Format("SONOVATE{0}",
                                                        transactionGroup.First().InvoiceDate.GetValueOrDefault().ToString("ddMMyyyy"));

                results.Add(result);
            }

            return(results);
        }
Exemple #6
0
 public async Task <Candidate> GetById(string id)
 {
     _loggerManager.LogInfo($"Getting single candidate with id {id} from repository");
     return(await _candidateRepository.GetById(Guid.Parse(id)));
 }
        public Candidate GetById(int id)
        {
            var repo = new CandidateRepository(_connectionString);

            return(repo.GetById(id));
        }