public BillOfExchangeCheckFixture CreateBillOfExchange(int drawerId, int beneficiaryId) { BillOfExchange = new BillOfExchange(); BillOfExchange.BeneficiaryId = beneficiaryId; BillOfExchange.DrawerId = drawerId; return(this); }
public BillOfExchangeWithCurrentOwnerDto GetBillOfExchangeWithCurrentOwner(int billId) { BillOfExchange bill = billOfExchangeRepository.GetByIds(new[] { billId }).SingleOrDefault(); if (bill is null) { throw new NotFoundException($"Bill with id:{billId} not found"); } ValidateBill(bill); var billWithOwner = mapper.Map <BillOfExchangeWithCurrentOwnerDto>(bill); Party party = partyRepository.GetByIds(new List <int>() { GetCurrentOwner(billWithOwner) }) .SingleOrDefault(); if (party != null) { billWithOwner.OwnerId = party.Id; billWithOwner.OwnerName = party.Name; } return(billWithOwner); }
public EndorsementCheckResult CheckList(BillOfExchange billOfExchange, IEnumerable <Endorsement> endorsemetList) { if (endorsemetList.Any(e => e.BillId != billOfExchange.Id)) { throw new ArgumentException($"There is record in {nameof(endorsemetList)} which is not connected to {nameof(billOfExchange)}"); } if (!endorsemetList.Any()) { return(new EndorsementCheckResult(true)); } var first = endorsemetList.Where(e => e.PreviousEndorsementId == null).ToList(); if (first.Count == 0) { return(new EndorsementCheckResult(false, "There is no first endorsement")); } if (first.Count > 1) { return(new EndorsementCheckResult(false, "There is too many starting endorsement", first)); } Endorsement current = first.First(); if (current.NewBeneficiaryId == billOfExchange.BeneficiaryId) { return(new EndorsementCheckResult(false, $"Endorsement with id {current.Id} have same BeneficiaryId {current.NewBeneficiaryId} as billOfExchange.", current)); } ISet <int> usedIds = new HashSet <int>(); usedIds.Add(current.Id); do { Endorsement next = endorsemetList.FirstOrDefault(e => current.Id == e.PreviousEndorsementId); if (next is null) { break; } if (next.NewBeneficiaryId == current.NewBeneficiaryId) { return(new EndorsementCheckResult(false, $"There is same BeneficiaryId {next.NewBeneficiaryId} in two endorsement ids {current.Id} and {next.Id}", current, next)); } if (usedIds.Contains(next.Id)) { return(new EndorsementCheckResult(false, $"Endorsement with id {next.Id} is used.", next)); } usedIds.Add(next.Id); current = next; } while (true); if (usedIds.Count != endorsemetList.Count()) { return(new EndorsementCheckResult(false, "Tehere is endorsement in endrosementList which is not in the sequence.", endorsemetList.Where(e => !usedIds.Contains(e.Id)).ToArray())); } return(new EndorsementCheckResult(true)); }
private static void ValidateEndorsements(int billId, IReadOnlyList <EndorsementDto> endorsements, BillOfExchange bill) { int endorsementCount = endorsements.Count(); for (var a = 0; a < endorsementCount; a++) { EndorsementDto endorsementDto = endorsements[a]; if (a == 0 && endorsementDto.NewBeneficiaryId == bill.BeneficiaryId) { throw new BillIssuedToItselfException( $"First endorsement for bill id: {billId} has same new beneficiary id as bill's beneficiary id: {bill.BeneficiaryId}."); } if ((a + 1 < endorsementCount) && (endorsementDto.NewBeneficiaryId == endorsements[a + 1].NewBeneficiaryId)) { throw new BillIssuedToItselfException( $"There are two endorsements for bill id: {billId} that has same new beneficiary id: {bill.BeneficiaryId}."); } if (endorsementDto.PreviousEndorsementId != null && endorsementDto.PreviousEndorsementId > endorsementDto.Id) { throw new CantReferenceOldEndorsementsException( $"Endorsement for bill id: {billId} references older endorsement."); } } if (endorsements.Count(a => a.PreviousEndorsementId == null) > 1) { throw new MoreThanOnePreviousEndorsementIsNotSetException( $"Endorsements for bill id: {billId} has more than one cases where previous endorsement is not set."); } }
public IEnumerable <EndorsementDto> GetEndorsementsForBill(int billId) { List <EndorsementDto> endorsements = (from party in partyRepository.Get(int.MaxValue, 0) join endorsement in endorsementRepository.Get(int.MaxValue, 0) on party.Id equals endorsement .NewBeneficiaryId where endorsement.BillId == billId select new EndorsementDto { NewBeneficiaryId = party.Id, NewBeneficiary = party.Name, Id = endorsement.Id, BillId = endorsement.BillId, PreviousEndorsementId = endorsement.PreviousEndorsementId }).ToList(); if (!endorsements.Any()) { return(new List <EndorsementDto>()); } BillOfExchange bill = billOfExchangeRepository.GetByIds(new List <int> { billId }).Single(); ValidateEndorsements(billId, endorsements, bill); return(endorsements); }
public void IfNoEndorsementForBillExistsOnlyOwnerShouldBeBillBeneficiary() { var billOfExchange = new BillOfExchange { BeneficiaryId = BillBeneficiaryId, DrawerId = 2 }; billOfExchangeRepositoryWithCount.Setup(x => x.GetByBeneficiaryIds(It.IsAny <List <int> >())) .Returns(new List <IEnumerable <BillOfExchange> > { new List <BillOfExchange> { billOfExchange } }); endorsementRepository.Setup(x => x.GetByBillIds(It.IsAny <List <int> >())) .Returns(new List <IEnumerable <Endorsement> >()); endorsementRepository.Setup(x => x.GetByNewBeneficiaryIds(It.IsAny <List <int> >())) .Returns(new List <IEnumerable <Endorsement> >()); var billOfExchangeSvc = new BillOfExchangeService(billOfExchangeRepositoryWithCount.Object, mapper, partyRepositoryWithCount.Object, endorsementRepository.Object); IEnumerable <BillOfExchangeDto> billOfExchanges = billOfExchangeSvc.GetBillsByOwner(It.IsAny <int>()).ToList(); billOfExchanges.ShouldNotBeEmpty(); billOfExchanges.FirstOrDefault().BeneficiaryId = BillBeneficiaryId; }
private static void ValidateBill(BillOfExchange bill) { if (bill.BeneficiaryId == bill.DrawerId) { throw new BillIssuedToItselfException( $"Bill id: {bill.Id} has same beneficiary and drawer id."); } }
public BillOfExchangeCheckResult BillOfExchangeCheck(BillOfExchange billOfExchange) { if (billOfExchange.BeneficiaryId == billOfExchange.DrawerId) { return(new BillOfExchangeCheckResult(false, $"BillOfExchange with id {billOfExchange.Id} have same BeneficiaryId and DrawerId.")); } return(new BillOfExchangeCheckResult(true, String.Empty)); }
public CheckListFixture() { BillOfExchange = new BillOfExchange(); BillOfExchange.Id = 1; BillOfExchange.BeneficiaryId = BillBeneficiaryId; BillOfExchange.DrawerId = BillDrawerId; EndorsementList = new List <Endorsement>(); WrongEndorsementList = new List <Endorsement>(); }
public void BillOfExchangeRepository_GetByBeneficiaryIds() { BillOfExchangeRepository sut = new BillOfExchangeRepository(); IReadOnlyList <IEnumerable <BillOfExchange> > result = sut.GetByBeneficiaryIds(new int[] { 13 }); BillOfExchange bill1 = result.Single().First(); BillOfExchange bill2 = result.Single().Last(); Assert.AreEqual(2, bill1.Id); Assert.AreEqual(4, bill2.Id); }
/// <summary> /// Pega um boleto no SAP /// </summary> /// <param name="pBoeKey">Código do Boleto</param> /// <param name="pCompanyDb">Banco de Dados</param> /// <returns>Um item preenchido</returns> /// <exception cref="ArgumentNullException">Null passado com código</exception> /// <exception cref="Exception">Não encontro o registro</exception> public static BillOfExchange GetBoe(int pBoeKey, string pCompanyDb) { var boe = new BillOfExchange(pCompanyDb); if (!boe.GetByKey(pBoeKey)) { throw new Exception( string.Format(DontFindText1Key, "Boleto", pBoeKey)); } return(boe); }
public BillOfExchangeDetailDto GetBillOfExchange(int billId) { BillOfExchange bill = BillOfExchangeRepository.GetByIds(new List <int> { billId }).First(); BillOfExchangeCheckResult result = BillOfExchangeChecker.BillOfExchangeCheck(bill); if (!result.IsCorrect) { throw new Exception(result.Message); } Dictionary <int, string> names = GetPartiesDictionary(GetPartiesIds(new List <BillOfExchange> { bill })); return(new BillOfExchangeDetailDto(bill.Id, bill.DrawerId, names[bill.DrawerId], bill.BeneficiaryId, names[bill.BeneficiaryId], bill.Amount)); }
public List <EndorsmentListDto> GetByBillOfExhange(int billOfExhangeId) { IEnumerable <Endorsement> list = EndorsementRepository.GetByBillIds(new List <int> { billOfExhangeId }).FirstOrDefault()?.ToList() ?? new List <Endorsement>(); BillOfExchange billOfExchange = BillOfExchangeRepository.GetByIds(new List <int> { billOfExhangeId }).First(); var partyNamesDictionary = PartyRepository.GetByIds(list.Select(l => l.NewBeneficiaryId).Distinct().ToList()).ToDictionary(p => p.Id, p => p.Name); EndorsementCheckResult result = EndorsementChecker.CheckList(billOfExchange, list); if (!result.IsCorrect) { throw new Exception(result.Message); } return(list.Select(e => new EndorsmentListDto(e.Id, e.NewBeneficiaryId, partyNamesDictionary[e.NewBeneficiaryId])).ToList()); }