Пример #1
0
        public IEnumerable<WinningBid> GenerateNextSequenceOfBidsAfter(Offer offer, WinningBid currentWinningBid)
        {
            var bids = new List<WinningBid>();

            if (currentWinningBid.MaximumBid.IsGreaterThanOrEqualTo(offer.MaximumBid))
            {
                var bidFromOffer = new WinningBid(offer.Bidder, offer.MaximumBid, offer.MaximumBid, offer.TimeOfOffer);
                bids.Add(bidFromOffer);

                bids.Add(CalculateNextBid(bidFromOffer, new Offer(currentWinningBid.Bidder, currentWinningBid.MaximumBid, currentWinningBid.TimeOfBid)));               
            }
            else
            {
                if (currentWinningBid.HasNotReachedMaximumBid())
                {
                    var currentBiddersLastBid = new WinningBid(currentWinningBid.Bidder, currentWinningBid.MaximumBid, currentWinningBid.MaximumBid, currentWinningBid.TimeOfBid);
                    bids.Add(currentBiddersLastBid);

                    bids.Add(CalculateNextBid(currentBiddersLastBid, offer));                   
                }
                else
                    bids.Add(new WinningBid(offer.Bidder, currentWinningBid.CurrentAuctionPrice.BidIncrement(), offer.MaximumBid, offer.TimeOfOffer));
            }

            return bids;
        }
        public static void AssertWinner(this CompletedAuction completedAuction, AuctionBid winningBid, int price)
        {
            WinningBid mainWinner = completedAuction.WinningBids.SingleOrDefault(x => ReferenceEquals(winningBid, x.Bid));

            Assert.IsNotNull(mainWinner, $"{winningBid.CharacterName} should be a winner.");
            Assert.AreEqual(price, mainWinner.Price, $"{winningBid.CharacterName} should pay {price}.");
        }
Пример #3
0
        private WinningBid CalculateNextBid(WinningBid winningbid, Offer offer)
        {
            WinningBid bid;

            if (winningbid.CanBeExceededBy(offer.MaximumBid))
                bid = new WinningBid(offer.Bidder, offer.MaximumBid, winningbid.CurrentAuctionPrice.BidIncrement(), offer.TimeOfOffer);
            else
                bid = new WinningBid(offer.Bidder, offer.MaximumBid, offer.MaximumBid, offer.TimeOfOffer);

            return bid;
        }
Пример #4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            WinningBid = await _context.WinningBids.FindAsync(id);

            if (WinningBid != null)
            {
                _context.WinningBids.Remove(WinningBid);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #5
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            WinningBid = await _context.WinningBids
                         .Include(w => w.Bidder)
                         .Include(w => w.DonationSpecialist)
                         .Include(w => w.Item).FirstOrDefaultAsync(m => m.ItemID == id);

            if (WinningBid == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            WinningBid = await _context.WinningBids
                         .Include(w => w.Bidder)
                         .Include(w => w.DonationSpecialist)
                         .Include(w => w.Item).FirstOrDefaultAsync(m => m.ItemID == id);

            if (WinningBid == null)
            {
                return(NotFound());
            }
            ViewData["BidderID"]             = new SelectList(_context.Bidders, "ID", "FullName");
            ViewData["DonationSpecialistID"] = new SelectList(_context.DonationSpecialists, "ID", "FullName");
            ViewData["ItemID"] = new SelectList(_context.Items, "ItemID", "ShortName");

            Status = new SelectList(Enum.GetNames(typeof(Models.BidStatus)), WinningBid.BidStatus);

            return(Page());
        }
Пример #7
0
        public void CalculateWinners_TwoItems_SecondPlaceTie()
        {
            //Arrange

            Auction auction = raid.NewAuction(2);

            AuctionBid mainBid = auction.AddBid("first", 15, main);

            auction.AddBid("second1", 5, main);
            auction.AddBid("second2", 5, main);
            auction.AddBid("alt", 2, alt);

            //Act
            CompletedAuction completedAuction = target.CalculateWinners(auction);

            //Assert
            completedAuction.AssertNumberOfWinners(2);
            completedAuction.AssertWinner(mainBid, 5);

            WinningBid winner2 = completedAuction.WinningBids[1];

            Assert.IsTrue(winner2.Bid.CharacterName.StartsWith("second"), "Winner2 should be a second");
            Assert.AreEqual(5, winner2.Price, "second should pay 5");
        }