/// <summary> /// Registers the bid. /// </summary> /// <param name="person">The person.</param> /// <param name="bid">The bid.</param> /// <param name="auction">The auction.</param> /// <exception cref="System.Exception">INVALID BID!</exception> public void RegisterBid(Person person, Bid bid, Auction auction) { IPersonBidderTable personBidderTable = this.tablesProvider.GetPersonBidderTable(); IBidTable bidTable = this.tablesProvider.GetBidTable(); try { PersonBidder personBidder = personBidderTable.FetchPersonBidderByIdPerson(person.IdPerson); bid.PersonBidder = personBidder ?? throw new Exception("no person bidder!"); personBidder.Person = person; Bid highest_bid = this.GetHighestBid(auction); if (highest_bid != null) { highest_bid.PersonBidder = personBidderTable.FetchPersonByIdBid(highest_bid.IdBid); highest_bid.Currency = auction.Currency; highest_bid.Auction = auction; } bool isOkToPostBid = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highest_bid); if (!isOkToPostBid) { throw new Exception("INVALID BID!"); } bidTable.InsertBid(personBidder.IdBidder, auction.IdAuction, auction.Currency.IdCurrency, bid); Log.Info("bid registered!"); } catch (Exception e) { throw e; } }
public void CreatePersonBidder_ShouldThrow() { var personBidder = new PersonBidder(); personBidder.Person = null; Assert.ThrowsAny <Exception>(() => personBidder.ValidateObject()); }
public PersonBidder GetPersonBidder() { Person person = new Person(); var personBidder = new PersonBidder(); personBidder.Person = person; return(personBidder); }
public void CreatePersonBidder_ShouldThrowDueBadId(int id) { Person person = new Person(); var personBidder = new PersonBidder(); personBidder.Person = person; personBidder.IdBidder = id; Assert.ThrowsAny <Exception>(() => personBidder.ValidateObject()); }
public void CreatePersonBidder_ShouldInstantiatePersonBidder() { Person person = new Person(); var personBidder = new PersonBidder(); personBidder.Person = person; personBidder.ValidateObject(); Assert.NotNull(personBidder); }
public void DoCheckNullPersonBidderAndWrongBid_ShouldNotPassCheck() { PersonBidder personBidder = null; var bid = InstanceHelper.GetBid(); var auction = InstanceHelper.GetAuction(); var highestiBid = InstanceHelper.GetBid(); var result = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highestiBid); Assert.False(result); }
/// <summary> /// Registers the person. /// </summary> /// <param name="person">The person.</param> /// <returns> /// true if it succeeds /// </returns> /// <exception cref="System.Exception">Person is already registered!</exception> public Person RegisterPerson(Person person) { PersonOfferor offeror; PersonBidder bidder; IPersonTable personTable = this.tablesProvider.GetPersonTable(); IPersonBidderTable personBidderTable = this.tablesProvider.GetPersonBidderTable(); IPersonOfferorTable personOfferorTable = this.tablesProvider.GetPersonOfferorTable(); try { if (person.IdPerson != 0) { throw new Exception("Person is already registered!"); } person.ValidateObject(); Person exists = personTable.FetchPersonByPhone(person.Phone); if (exists != null) { person = exists; //// to update the id. return(person); } } catch (Exception e) { Log.Info("RegisterPerson: " + e.Message); throw e; } //// at this point person doesn't exist into db. //// the actual insert personTable.InsertPerson(person); person = personTable.FetchPersonByPhone(person.Phone); //// in order to update Id offeror = new PersonOfferor() { Person = person }; bidder = new PersonBidder() { Person = person }; personOfferorTable.InsertPersonOfferor(person.IdPerson, offeror); personBidderTable.InsertPersonBidder(person.IdPerson, bidder); Log.Info("RegisterPerson: " + person.Name + " person id =" + person.IdPerson + " inserted with success."); return(person); }
/// <summary> /// Initializes the <see cref="CanBidBePostedToActionCheck" /> class. /// </summary> /// <param name="personBidder">The person bidder.</param> /// <param name="bid">The bid.</param> /// <param name="auction">The auction.</param> /// <param name="highest_bid">The highest bid.</param> /// <returns> /// true if the bid can be posted to auction /// </returns> public static bool DoCheck(PersonBidder personBidder, Bid bid, Auction auction, Bid highest_bid) { AuctionService auctionService = new AuctionService(auction); //// is active (started & not ended)? if (!auctionService.IsActive) { return(false); } //// they are in the same currency? if (!bid.Currency.Equals(auction.Currency)) { return(false); } double highest_value; //// there is no bid & this bid value is bigger than auction start value. if (highest_bid == null) { highest_value = auction.StartValue; } else { // null Person Bidder if (highest_bid.PersonBidder == null) { return(false); } // bid his bid? if (highest_bid.PersonBidder.IdBidder == bid.PersonBidder.IdBidder) { return(false); } highest_value = highest_bid.Value; } double incoming_value = bid.Value; //// Max current price + 50% * current price double max_new_bid_value = highest_value + (highest_value / 2); //// Price should be bigger than existent higher one, but not bigger with 50% of the existent bool price_ok = incoming_value > highest_value && incoming_value < max_new_bid_value; return(price_ok); }
public void InsertPersonBidder(int idPerson, PersonBidder personBidder) { personBidder.IdBidder = index++; list.Add(personBidder); }