public void Can_Save_Load_Bid()
        {
            Assert.AreEqual(1, items.FindAll().Count);

            Bid bid = new Bid(
                new MonetaryAmount(200, "GBP"),
                iMac,
                tobin);

            iMac.AddBid(bid);

            Assert.AreEqual(1, iMac.Bids.Count);
            Assert.AreEqual(1, items.FindAll().Count);

            NHibernateHelper.Session.Save(bid);
            NHibernateHelper.CommitTransaction();
            NHibernateHelper.CloseSession();

            //test that can load the bid "manually" and that
            //the .Item and .Bidder associations are set
            Bid loaded = NHibernateHelper.Session.Get<Bid>(bid.Id);
            Assert.IsNotNull(loaded, "No loaded bid found");
            Assert.IsTrue(iMac.Equals(loaded.Item),"Items not same");
            Assert.AreEqual(iMac, loaded.Item);

            Assert.IsTrue(tobin.Equals(loaded.Bidder), "Bidder not the same");
            Assert.AreEqual(tobin, loaded.Bidder);

            //test that we can reload the Item and that the Bids are restored also
            Item reloaded = items.GetById(iMac.Id);
            Assert.AreEqual(1, reloaded.Bids.Count);
            Assert.AreEqual(bid, reloaded.Bids[0]);
        }
Example #2
0
File: Item.cs Project: krwhite/sync
 /// <summary> Full constructor.</summary>
 public Item(string name, string description, /*User seller, */double initialPrice, double reservePrice,
     DateTime startDate, DateTime endDate, ISet categories, IList bids, Bid successfulBid)
 {
     this.name = name;
     //this.seller = seller;
     this.description = description;
         /*
     this.initialPrice = initialPrice;
     this.reservePrice = reservePrice;
     this.startDate = startDate;
     this.endDate = endDate;
     categorizedItems = categories;
     this.bids = bids;
     this.successfulBid = successfulBid;
     state = ItemState.Draft;*/
 }
Example #3
0
        /// <summary> Places a bid while checking business constraints.
        /// This method may throw a BusinessException if one of the requirements
        /// for the bid placement wasn't met, e.g. if the auction already ended.
        /// </summary>
        /// <param name="bidder">
        /// </param>
        /// <param name="bidAmount">
        /// </param>
        /// <param name="currentMaxBid"> the most valuable bid for this item
        /// </param>
        /// <param name="currentMinBid"> the least valuable bid for this item
        /// </param>
        /// <returns>
        /// </returns>
        public virtual Bid PlaceBid(User bidder, MonetaryAmount bidAmount, Bid currentMaxBid, Bid currentMinBid)
        {
            // Check highest bid (can also be a different Strategy (pattern))
            if (currentMaxBid != null && currentMaxBid.Amount.CompareTo(bidAmount) > 0)
            {
                throw new BusinessException("Bid too low.");
            }

            // Auction is active
            if (state != ItemState.Active)
            {
                throw new BusinessException("Auction is not active yet.");
            }

            // Auction still valid
            if (EndDate < DateTime.Now)
            {
                throw new BusinessException("Can't place new bid, auction already ended.");
            }

            // Create new Bid
            var newBid = new Bid(bidAmount, this, bidder);

            // Place bid for this Item
            AddBid(newBid);

            return(newBid);
        }
        /// <summary> Full constructor.</summary>
        public Item(string name, string description, /*User seller, */ double initialPrice, double reservePrice,
                    DateTime startDate, DateTime endDate, ISet categories, IList bids, Bid successfulBid)
        {
            this.name = name;
            //this.seller = seller;
            this.description = description;

            /*
             *      this.initialPrice = initialPrice;
             *      this.reservePrice = reservePrice;
             *      this.startDate = startDate;
             *      this.endDate = endDate;
             *      categorizedItems = categories;
             *      this.bids = bids;
             *      this.successfulBid = successfulBid;
             *      state = ItemState.Draft;*/
        }
Example #5
0
File: Item.cs Project: krwhite/sync
        // ********************** Business Methods ********************** //
        /// <summary> Places a bid while checking business constraints.
        /// This method may throw a BusinessException if one of the requirements
        /// for the bid placement wasn't met, e.g. if the auction already ended.
        /// </summary>
        public virtual Bid PlaceBid( /*User bidder, */ double bidAmount, Bid currentMaxBid, Bid currentMinBid)
        {
            // Check highest bid (can also be a different Strategy (pattern))
            if (currentMaxBid != null && currentMaxBid.Amount.CompareTo(bidAmount) > 0)
            {
                throw new BusinessException("Bid too low.");
            }
            /*
            // Auction is active
            if(state != ItemState.Active)
                throw new BusinessException("Auction is not active yet.");

            // Auction still valid
            if(EndDate < DateTime.Now)
                throw new BusinessException("Can't place new bid, auction already ended.");
            */
            // Create new Bid
            var newBid = new Bid(bidAmount, this /*, bidder*/);

            // Place bid for this Item
            AddBid(newBid);

            return newBid;
        }
Example #6
0
File: Item.cs Project: krwhite/sync
 /*public virtual void AddCategorizedItem(CategorizedItem catItem)
 {
     if(catItem == null)
         throw new ArgumentException("Can't add a null CategorizedItem.");
     CategorizedItems.Add(catItem);
 }*/
 public virtual void AddBid(Bid bid)
 {
     if (bid == null)
         throw new ArgumentException("Can't add a null Bid.");
     //			Bids.Add(bid);
 }