Exemple #1
0
        public void Test_highest_bidding_offer()
        {
            var offerlist = MockOffers.Offers;

            var highestBid = OfferUtility.GetHighestBid(offerlist);

            Assert.Equal(200, highestBid);
        }
        public async Task <IActionResult> AllAuctions(DateTime?date = null)
        {
            var stapleVM       = new StapleViewModel();
            var highestBidList = new List <double>();
            var estimateList   = new List <double>();

            var auctionItems = await _auctionFacade.GetAllAuctionsAsync();

            if (date.HasValue)
            {
                auctionItems = auctionItems.Where(a => a.StartDate.Month == date.Value.Month).ToArray();
            }

            if (auctionItems.Length == 0)
            {
                stapleVM.WinningBidAvg = 0;
                stapleVM.EstimateAvg   = 0;
                stapleVM.Difference    = 0;

                return(PartialView("_AuctionList", stapleVM));
            }

            foreach (var auction in auctionItems)
            {
                auction.OfferList.AddRange(await _auctionFacade.GetAllOffersAsync((int)auction.Id));
                if (auction.OfferList.Count > 0)
                {
                    estimateList.Add((double)auction.Estimate);
                    highestBidList.Add(OfferUtility.GetHighestBid(auction.OfferList));
                }
            }

            stapleVM.WinningBidAvg = highestBidList.Average();
            stapleVM.EstimateAvg   = estimateList.Average();
            stapleVM.Difference    = OfferUtility.GetAverageDifference(highestBidList, estimateList);

            return(PartialView("_AuctionList", stapleVM));
        }