Ejemplo n.º 1
0
        /// <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 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);
        }
        public void DoCheckHighestBid_ShouldNotPassCheck()
        {
            var personBidder = InstanceHelper.GetPersonBidder();

            var bid         = InstanceHelper.GetBid();
            var auction     = InstanceHelper.GetAuction();
            var highestiBid = new Bid();

            var result = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highestiBid);

            Assert.False(result);
        }
        public void DoCheckAuction_ShouldNotPassCheck()
        {
            var personBidder = InstanceHelper.GetPersonBidder();

            var bid     = InstanceHelper.GetBid();
            var auction = InstanceHelper.GetAuction();

            auction.EndDate = DateTime.Now;
            Bid highestiBid = InstanceHelper.GetBid();

            var result = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highestiBid);

            Assert.False(result);
        }
        public void DoCheckPriceTooHigh_ShouldNotPassCheck()
        {
            var personBidder = InstanceHelper.GetPersonBidder();

            var bid         = InstanceHelper.GetBid();
            var auction     = InstanceHelper.GetAuction();
            var highestiBid = InstanceHelper.GetBid();

            highestiBid.PersonBidder.IdBidder = 2;
            highestiBid.Value = 1;

            var result = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highestiBid);

            Assert.False(result);
        }
        public void DoCheckCurrency_ShouldNotPassCheck()
        {
            var personBidder = InstanceHelper.GetPersonBidder();

            var bid         = InstanceHelper.GetBid();
            var auction     = InstanceHelper.GetAuction();
            Bid highestiBid = InstanceHelper.GetBid();

            bid.Currency = new Currency
            {
                IdCurrency = 2,
                Name       = "EUR"
            };

            var result = CanBidBePostedToActionCheck.DoCheck(personBidder, bid, auction, highestiBid);

            Assert.False(result);
        }