Esempio n. 1
0
        public void CalculateWinners_TwoItems_ManyRaiderBids()
        {
            //Arrange
            RankConfiguration raider = new RankConfiguration("Raider", null, 1);

            configuration.Ranks = new[] { raider };

            Auction auction = raid.NewAuction(2);

            AuctionBid bid1 = auction.AddBid("Blace", 103, raider);
            AuctionBid bid2 = auction.AddBid("Khovet", 75, raider);

            auction.AddBid("Glororhan", 69, raider);
            auction.AddBid("Mowron", 69, raider);
            auction.AddBid("kalvin", 67, raider);
            auction.AddBid("GALVANIZED", 55, raider);

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

            //Assert
            completedAuction.AssertNumberOfWinners(2);
            completedAuction.AssertWinner(bid1, 70);
            completedAuction.AssertWinner(bid2, 70);
        }
        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}.");
        }
        public IActionResult UpdateBid(AuctionBid auctionBid, int id)
        {
            auctionBid.AuctionBidId = id;
            AuctionBid auctionBid2 = repository.UpdateAuctionBid(auctionBid);

            return(RedirectToAction("Index", "Auction"));
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FwdDate,BankName,FwdRate,AmountBid,CouponAmount,Pips,BatchRef")] AuctionBid auctionBid)
        {
            if (id != auctionBid.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(auctionBid);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuctionBidExists(auctionBid.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(auctionBid));
        }
        public static AuctionBid AddBid(this Auction auction, string name, int amount, RankConfiguration rank)
        {
            AuctionBid bid = new AuctionBid(auction, name, random.Next(), amount, rank, GetAuthor(42));

            auction.Bids.AddOrUpdate(bid);
            return(bid);
        }
Esempio n. 6
0
        public void CalculateWinners_TwoItemsAndCustomRanks_ManyBids()
        {
            //Arrange
            RankConfiguration raiderConfig = new RankConfiguration("Raider", null, 1);
            RankConfiguration boxConfig    = new RankConfiguration("Box", 50, 3);
            RankConfiguration altConfig    = new RankConfiguration("Alt", 10, 1);
            RankConfiguration memberConfig = new RankConfiguration("Member", 10, 1);

            configuration.Ranks = new[] { raiderConfig, boxConfig, altConfig, memberConfig };

            Auction auction = raid.NewAuction(2);

            AuctionBid bid1 = auction.AddBid("Galvanized", 26, raiderConfig);
            AuctionBid bid2 = auction.AddBid("Barogue", 14, altConfig);

            auction.AddBid("Autobahn", 10, raiderConfig);
            auction.AddBid("Khaldraks", 10, memberConfig);
            auction.AddBid("Windforce", 5, altConfig);
            auction.AddBid("Glororhan", 5, raiderConfig);

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

            //Assert
            completedAuction.AssertNumberOfWinners(2);
            completedAuction.AssertWinner(bid1, 11);
            completedAuction.AssertWinner(bid2, 11);
        }
Esempio n. 7
0
            public void Bid(User bidder, int bidAmount)
            {
                foreach (AuctionBid bid in bidder.Bids)
                {
                    if (bid.AuctionItem.RandomId == this.RandomId)
                    {
                        bid.PlaceBid(bidAmount);
                        auctionRoomPlacedIn.UpdateAuctionRoom();
                        return;
                    }
                }

                AuctionBid newBid = new AuctionBid();

                newBid.AuctionItem = this;
                newBid.BidUser     = bidder;
                if (HighestBidder == bidder.Id)
                {
                    newBid.BidAmount = HighestBid;
                }
                else
                {
                    newBid.BidAmount = 0;
                }
                newBid.PlaceBid(bidAmount);
                bidder.AddBid(newBid);
                bidders.Add(newBid);
                auctionRoomPlacedIn.UpdateAuctionRoom();
            }
Esempio n. 8
0
        public void CompareToMultiples()
        {
            //Arrange
            RaidInfo          raid    = new RaidInfo();
            Auction           auction = new Auction(23423, 2, "Nuke", 2, raid, GetMessage(44));
            RankConfiguration main    = new RankConfiguration("main", null, 1);
            RankConfiguration box     = new RankConfiguration("box", 100, 1);
            RankConfiguration alt     = new RankConfiguration("alt", 25, 1);

            AuctionBid mainBid = new AuctionBid(auction, "main", 1, 104, main, GetAuthor(1));
            AuctionBid boxBid1 = new AuctionBid(auction, "box1", 1, 300, box, GetAuthor(2));
            AuctionBid BoxBid2 = new AuctionBid(auction, "box2", 1, 250, box, GetAuthor(3));
            AuctionBid altBid  = new AuctionBid(auction, "alt", 1, 54, alt, GetAuthor(4));

            List <AuctionBid> list = new List <AuctionBid> {
                altBid, boxBid1, mainBid, BoxBid2
            };

            //Act
            list.Sort();

            //Assert
            Assert.AreEqual(mainBid, list[0]);
            Assert.AreEqual(boxBid1, list[1]);
            Assert.AreEqual(BoxBid2, list[2]);
            Assert.AreEqual(altBid, list[3]);
        }
Esempio n. 9
0
        // GET: Bids
        public ActionResult Index()
        {
            List <AuctionBid> bids = new List <AuctionBid>();
            var list = from b in db.Bids
                       join a in db.Auctions on b.AuctionId equals a.Id
                       select new
            {
                a.Id,
                a.Title,
                a.Description,
                a.ImageUrl,
                b.Timestamp,
                b.Username,
                b.Amount
            };

            foreach (var v in list)
            {
                AuctionBid bid = new AuctionBid();
                bid.Id          = v.Id;
                bid.Title       = v.Title;
                bid.Timestamp   = v.Timestamp;
                bid.Description = v.Description;
                bid.ImageUrl    = v.ImageUrl;
                bid.Username    = v.Username;
                bid.Amount      = v.Amount;

                bids.Add(bid);
            }
            Console.WriteLine(bids.Count);

            return(View(bids));
        }
        private void HandlePushLoadAvailabilityRequest(PushLoadAvailabilityRequest message)
        {
            Bid bid;

            if (_hostState.CurrentAction == HostCurrentAction.None &&
                !_hostState.EvacuationMode &&
                LoadManager.CanITakeLoad(message.NewContainerLoadInfo))
            {
                var load = LoadManager.GetHostLoadInfoAfterContainer(message.NewContainerLoadInfo);

                var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization);
                if (newState == UtilizationStates.OverUtilization)
                {
                    bid = new AuctionBid(MachineId, false, load, message.AuctionId,
                                         message.NewContainerLoadInfo.ContainerId, BidReasons.FullLoad, 0);
                }
                else
                {
                    int pulls = CalculatePullsCount(message.NewContainerLoadInfo.ImageId);
                    bid = new AuctionBid(MachineId, true, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId,
                                         BidReasons.ValidBid, pulls);
                    _hostState.CurrentAction = HostCurrentAction.Bidding;
                    _hostState.AuctionId     = message.AuctionId;
                }
            }
            else
            {
                bid = new AuctionBid(MachineId, false, null, message.AuctionId, message.NewContainerLoadInfo.ContainerId,
                                     BidReasons.CantBid, 0);
            }
            LoadAvailabilityResponce availabilityResponce =
                new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid);

            CommunicationModule.SendMessage(availabilityResponce);
        }
Esempio n. 11
0
        public async Task SaveAuctionBidAsync(BidModel model)
        {
            AuctionBid bid = new AuctionBid {
                UserId        = model.UserId,
                AuctionItemId = model.AuctionItemId,
                Bid           = model.Bid,
                Timestamp     = DateTimeOffset.Now,
            };

            var itemFileName = Path.Combine(_itemsBasePath, bid.AuctionItemId + ItemsFileSuffix);
            var bidFileName  = Path.Combine(_bidsBasePath, bid.AuctionItemId + BidsFileSuffix);

            using (var releaser = await _asyncLock.LockAsync(bid.AuctionItemId)) {
                var item = await _auctionFileRepository.GetAuctionItemAsync(itemFileName);

                if (model.Bid > item.HighBid)
                {
                    item.HighBid  = model.Bid;
                    model.HighBid = true;
                    model.Bid    += item.Increment;
                    await _auctionFileRepository.SaveAuctionItemAsync(item, itemFileName);
                }
                else
                {
                    model.Bid = item.HighBid + item.Increment;
                }

                await _auctionFileRepository.SaveAuctionBidAsync(bid, bidFileName);
            }
        }
Esempio n. 12
0
        public async Task <AuctionBid> InsertAuctionBid(AuctionBid auctionBid)
        {
            await _context.AuctionBids.AddAsync(auctionBid);

            await _context.SaveChangesAsync();

            return(auctionBid);
        }
        public IActionResult CreateBid(int auctionId)
        {
            AuctionBid newAuctionBid = new AuctionBid();

            newAuctionBid.AuctionId = auctionId;
            ViewBag.HighestBid      = repository.GetHighestBid(auctionId);
            return(View(newAuctionBid));
        }
Esempio n. 14
0
        public void AuctionEnd(int localID)
        {
            IParcelManagementModule parcelManagement = m_scene.RequestModuleInterface <IParcelManagementModule>();

            if (parcelManagement != null)
            {
                ILandObject landObject = parcelManagement.GetLandObject(localID);
                if (landObject == null)
                {
                    return;
                }

                AuctionInfo info = GetAuctionInfo(localID);
                if (info == null)
                {
                    return; // cannot find this auction??
                }
                AuctionBid highestBid = new AuctionBid()
                {
                    Amount = 0
                };
                foreach (AuctionBid bid in info.AuctionBids)
                {
                    if (highestBid.Amount < bid.Amount)
                    {
                        highestBid = bid;
                    }
                }

                IOfflineMessagesConnector offlineMessages =
                    Framework.Utilities.DataManager.RequestPlugin <IOfflineMessagesConnector>();
                if (offlineMessages != null)
                {
                    offlineMessages.AddOfflineMessage(new GridInstantMessage()
                    {
                        BinaryBucket  = new byte[0],
                        Dialog        = (byte)InstantMessageDialog.MessageBox,
                        FromAgentID   = UUID.Zero,
                        FromAgentName = "System",
                        FromGroup     = false,
                        SessionID     = UUID.Random(),
                        Message       =
                            "You won the auction for the parcel " +
                            landObject.LandData.Name + ", paying " +
                            highestBid.Amount + " for it",
                        Offline        = 0,
                        ParentEstateID = 0,
                        Position       = Vector3.Zero,
                        RegionID       = m_scene.RegionInfo.RegionID,
                        Timestamp      = (uint)Util.UnixTimeSinceEpoch(),
                        ToAgentID      = highestBid.AuctionBidder
                    });
                }
                landObject.UpdateLandSold(highestBid.AuctionBidder, UUID.Zero, false, landObject.LandData.AuctionID,
                                          highestBid.Amount, landObject.LandData.Area);
            }
        }
Esempio n. 15
0
        public void DeleteAuctionBid(int auctionBidId)
        {
            AuctionBid targetAuctionBid = context.AuctionBids.Find(auctionBidId);

            if (targetAuctionBid != null)
            {
                context.AuctionBids.Remove(targetAuctionBid);
            }
        }
        /// <summary>
        /// Determines if the new bid value is a bid abuse or a valid bid.
        /// </summary>
        /// <param name="bid">Current bid.</param>
        /// <param name="newBid">New bid value.</param>
        /// <returns>Continuation with the abuse result.</returns>
        public async Task<bool> IsBidAbuseAsync(AuctionBid bid, double newBid)
        {
            if (newBid > 1000 * bid.CurrentBid)
            {
                return true;
            }

            return false;
        }
Esempio n. 17
0
        //Context.User = NULL!!!!!
        //don't know why...
        public void SendBid(int userID, int auctionID, int amount)
        {
            if (amount > 0)
            {
                User user = db.Users.FirstOrDefault(u => u.ID == userID);
                if (user == null)
                    return;

                Auction auction = db.Auctions.Find(auctionID);
                if (auction == null || auction.StatusID != 2 || auction.Deadline < DateTime.Now)
                    return;

                int highestBid = 0;
                if (auction.AuctionBids.Count > 0)
                    highestBid = auction.AuctionBids.Max(b => b.Amount);
                if (!(amount > highestBid && amount > auction.StartPrice))
                    return;

                try
                {
                    AuctionBid bid = new AuctionBid()
                    {
                        Amount = amount,
                        AuctionID = auctionID,
                        DateCreated = DateTime.Now,
                        UserID = userID
                    };
                    db.AuctionBids.Add(bid);

                    //auction.CurrentPrice += amount;
                    auction.CurrentPrice = amount;
                    db.SaveChanges();

                    ICurrencyService CurrencyService = DependencyResolver.Current.GetService<ICurrencyService>();
                    double dollarRate = CurrencyService.GetCurrencyRate();

                    string priceFormat = XCarsConfiguration.PriceFormat;

                    string PriceUSDStr = (auction.CurrencyID == 1) ? (auction.CurrentPrice.ToString(priceFormat) + " " + CurrencyService.GetByID(1).Symbol) : (((int)(auction.CurrentPrice / dollarRate)).ToString(priceFormat) + " " + CurrencyService.GetByID(1).Symbol);
                    string PriceUAHStr = (auction.CurrencyID == 2) ? (auction.CurrentPrice.ToString(priceFormat) + " " + CurrencyService.GetByID(2).Symbol) : (((int)(auction.CurrentPrice * dollarRate)).ToString(priceFormat) + " " + CurrencyService.GetByID(2).Symbol);

                    string name = user.FirstName + " " + user.LastName;
                    if (string.IsNullOrWhiteSpace(name))
                        name = Resource.NoName;
                    string city = user.City?.Name ?? Resource.NoCity;

                    List<AuctionConnection> currentAuctionConnections = db.AuctionConnections.Where(c => c.AuctionID == auctionID).ToList();
                    foreach (var item in currentAuctionConnections)
                    {
                        Clients.Client(item.Connection).broadcastBid(name, city, /*photoSrc,*/ amount.ToString(XCarsConfiguration.PriceFormat), bid.DateCreated.ToString("dd.MM.yyyy HH:mm"), PriceUSDStr, PriceUAHStr);
                    }
                }
                catch (Exception ex)
                { }
                //Clients.All.broadcastMessage();
            }
        }
Esempio n. 18
0
        public void UpdateAuctionBid(AuctionBid auctionBid)
        {
            AuctionBid targetAuctionBid = context.AuctionBids.Find(auctionBid.AuctionBidID);

            if (targetAuctionBid != null)
            {
                targetAuctionBid.BidAmount = auctionBid.BidAmount;
                targetAuctionBid.BidDate   = auctionBid.BidDate;
            }
        }
        public IActionResult UpdateBid(int id)
        {
            AuctionBid auctionBid = repository.GetAuctionBid(id);

            if (auctionBid != null)
            {
                return(View());
            }
            return(RedirectToAction("Index", "Auction"));
        }
Esempio n. 20
0
        public async Task <IActionResult> Create([Bind("ID,FwdDate,BankName,FwdRate,AmountBid,CouponAmount,Pips,BatchRef")] AuctionBid auctionBid)
        {
            if (ModelState.IsValid)
            {
                _context.Add(auctionBid);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(auctionBid));
        }
Esempio n. 21
0
        public async Task SaveAuctionBidAsync(AuctionBid bid, string fileName)
        {
            var text   = Json.Serialize(bid);
            var bytes  = Encoding.UTF8.GetBytes(text);
            var stream = new MemoryStream(bytes, 0, bytes.Length);

            stream.Position = 0;

            var blob = _container.GetBlockBlobReference(fileName.ReplaceWithUnixPathSeparator());
            await blob.UploadFromStreamAsync(stream);
        }
Esempio n. 22
0
        public async Task SaveAuctionBidAsync(AuctionBid bid, string fileName)
        {
            var text = Json.Serialize(bid);

            byte[] encodedText = Encoding.UTF8.GetBytes(text);

            using (var stream = new FileStream(fileName, FileMode.Append,
                                               FileAccess.Write, FileShare.None, bufferSize: 1048576, useAsync: true)) {
                await stream.WriteAsync(encodedText, 0, encodedText.Length);
            }
        }
Esempio n. 23
0
        public void Update(long id, AuctionBid auctionBid)
        {
            var AuctionBid = _context.AuctionBids.Find(id);

            if (AuctionBid != null)
            {
                AuctionBid.BidPrice = auctionBid.BidPrice;

                _context.AuctionBids.Update(AuctionBid);
                _context.SaveChanges();
            }
        }
Esempio n. 24
0
        public void CalculateWinners_OneItem_OneBid()
        {
            //Arrange
            Auction    auction = raid.NewAuction(1);
            AuctionBid mainBid = auction.AddBid("main", 50, main);

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

            //Assert
            completedAuction.AssertNumberOfWinners(1);
            completedAuction.AssertWinner(mainBid, 1);
        }
        public async Task <(bool, DateTime?)> AddBid(BidModel bid, string userName)
        {
            var auc = await _context.Auction.Include(x => x.AuctionBid).SingleOrDefaultAsync(x => x.Id == bid.AuctionId);

            (bool, DateTime?)validationResult = ValidateBid(bid, auc);

            AuctionBid item = new AuctionBid()
            {
                AuctionId     = bid.AuctionId,
                Bid           = bid.Bid,
                BidderId      = bid.BidderId,
                ClientTime    = bid.ClientTime,
                PreviousBidId = bid.PreviousBidId,
                ServerTime    = bid.ServerTime,
                TimeStamp     = bid.TimeStamp,
                TimeStampTime = bid.TimestampTime,
                Valid         = validationResult.Item1
            };

            AuctionBid prevBid = auc.AuctionBid.Where(x => x.Valid).LastOrDefault();

            if (prevBid != null)
            {
                prevBid = _context.AuctionBid.Find(bid.PreviousBidId);

                if (prevBid != null)
                {
                    prevBid.NextBid = item;
                }
            }

            await _context.AuctionBid.AddAsync(item);

            await _context.SaveChangesAsync();

            //TODO Set timestamp

            if (item.Valid)
            {
                await Log(bid.BidderId, bid.AuctionId, $"Нова цена от {bid.Bid} лв." + (prevBid != null ? $"Предишна цена {prevBid.Bid} лв." : ""));
            }
            else
            {
                await Log(bid.BidderId, bid.AuctionId, $"Невалидна цена от {bid.Bid} лв." + prevBid != null?$"Предишна цена {prevBid.Bid} лв." : "");
            }

            return(validationResult);
        }
Esempio n. 26
0
        public void CalculateWinners_TwoItems_BoxesOverMain()
        {
            //Arrange
            Auction    auction = raid.NewAuction(2);
            AuctionBid mainBid = auction.AddBid("main", 35, main);
            AuctionBid boxBid1 = auction.AddBid("box1", 51, box);
            AuctionBid boxBid2 = auction.AddBid("box2", 80, box);

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

            //Assert
            completedAuction.AssertNumberOfWinners(2);
            completedAuction.AssertWinner(boxBid1, 108);
            completedAuction.AssertWinner(boxBid2, 108);
        }
Esempio n. 27
0
        public void Compare(int?bid1, int?cap1, int?bid2, int?cap2, ExpectedWinner expected)
        {
            //Arrange
            RaidInfo          raid    = new RaidInfo();
            Auction           auction = new Auction(23423, 1, "Nuke", 2, raid, GetMessage(42));
            RankConfiguration rank1   = new RankConfiguration("rank1", cap1, 1);
            RankConfiguration rank2   = new RankConfiguration("rank2", cap2, 1);
            AuctionBid        a1      = bid1 != null ? new AuctionBid(auction, "1", 1, bid1.Value, rank1, GetAuthor(45)) : null;
            AuctionBid        a2      = bid2 != null ? new AuctionBid(auction, "2", 2, bid2.Value, rank2, GetAuthor(41)) : null;

            //Act
            int            comparison = a1?.CompareTo(a2) ?? 0;
            ExpectedWinner actual     = comparison < 0 ? ExpectedWinner.First : comparison > 0 ? ExpectedWinner.Second : ExpectedWinner.Tie;

            //Assert
            Assert.AreEqual(expected, actual);
        }
        private void HandlePullLoadAvailabilityRequest(PullLoadAvailabilityRequest message)
        {
            Bid bid;

            if (_hostState.CurrentAction == HostCurrentAction.None && !_hostState.EvacuationMode)
            {
                ContainerLoadInfo selectedContainerload = GetToBeRemovedContainerLoadInfo();
                if (selectedContainerload != null)
                {
                    var oldstate = LoadManager.GetPredictedHostLoadInfo().CalculateTotalUtilizationState(MinUtilization, MaxUtilization);
                    var load     = LoadManager.GetHostLoadInfoAWithoutContainer(selectedContainerload);
                    var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization);

                    //Comment this condition
                    if (oldstate == UtilizationStates.Normal && newState == UtilizationStates.UnderUtilization)
                    {
                        bid = new AuctionBid(MachineId, false, load, message.AuctionId, -1, BidReasons.MinimumLoad, 0);
                    }
                    else
                    {
                        //try to find how many pulls the target will need !!!
                        var pullsCountRequest = new PullsCountRequest(message.RequestOwner, this.MachineId, selectedContainerload.ImageId);
                        var t = CommunicationModule.RequestData(pullsCountRequest);
                        t.Wait();
                        var pullsCountResponce = t.Result as PullsCountResponce;
                        bid = new AuctionBid(MachineId, true, load, message.AuctionId, selectedContainerload.ContainerId, BidReasons.ValidBid, pullsCountResponce.PullsCount);
                        _hostState.CurrentAction = HostCurrentAction.Bidding;
                        _hostState.AuctionId     = message.AuctionId;
                    }
                }
                else
                {
                    bid = new AuctionBid(MachineId, false, null, message.AuctionId, -1, BidReasons.Empty, 0);
                }
            }
            else
            {
                bid = new AuctionBid(MachineId, false, null, message.AuctionId, -1, BidReasons.CantBid, 0);
            }


            LoadAvailabilityResponce availabilityResponce =
                new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid);

            CommunicationModule.SendMessage(availabilityResponce);
        }
Esempio n. 29
0
        public void CalculateWinners_TwoItems_TwoBidsBid()
        {
            //Arrange

            Auction auction = raid.NewAuction(2);

            AuctionBid bid1 = auction.AddBid("main", 104, main);
            AuctionBid bid2 = auction.AddBid("main2", 45, main);

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

            //Assert
            completedAuction.AssertNumberOfWinners(2);
            completedAuction.AssertWinner(bid1, 1);
            completedAuction.AssertWinner(bid2, 1);
        }
Esempio n. 30
0
        public void CalculateWinners_TwoItems_SingleBid()
        {
            //Arrange

            Auction auction = raid.NewAuction(2);

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

            auction.Bids.AddOrUpdate(mainBid);

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

            //Assert
            completedAuction.AssertNumberOfWinners(1);
            completedAuction.AssertWinner(mainBid, 1);
        }
Esempio n. 31
0
        public void CalculateWinners_OneItem_ThreeBidsOutOfOrder()
        {
            //Arrange

            Auction auction = raid.NewAuction(1);

            auction.AddBid("main2", 17, main);
            auction.AddBid("alt", 104, alt);
            AuctionBid mainBid = auction.AddBid("main", 50, main);

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

            //Assert
            completedAuction.AssertNumberOfWinners(1);
            completedAuction.AssertWinner(mainBid, 26);
        }
        /// <summary>
        /// Sends a bid async.
        /// </summary>
        /// <param name="bid">The bid to send.</param>
        /// <returns>Continuation with the send result.</returns>
        public async Task<bool> SendBidAsync(AuctionBid bid)
        {
            // fake direct validation logic
            if (bid.NewBid <= await this.GetCurrentBidAsync(bid))
            {
                bid.ValidationMessages.AddMessage(ValidationLevel.Error, "Your bid has been surpassed.");
                return false;
            }

            if (bid.NewBid >= bid.CurrentBid * 100)
            {
                bid.ValidationMessages.AddMessage(
                    () => bid.NewBid, ValidationLevel.Warning, "Your bid surpasses the current bid by a 100 times.");
            }

            //// here should be the send logic

            return true;
        }
 /// <summary>
 /// Gets the current bid async.
 /// </summary>
 /// <param name="auctionBid">Bid so far.</param>
 /// <returns>Continuation with the current bid value as result.</returns>
 public async Task<double> GetCurrentBidAsync(AuctionBid auctionBid)
 {
     // Simulates a lengthy, asynchronous computation
     await Task.Delay(1000);
     return auctionBid.CurrentBid + 10;
 }
Esempio n. 34
0
        public void AuctionEnd(int LocalID)
        {
            IParcelManagementModule parcelManagement = m_scene.RequestModuleInterface<IParcelManagementModule>();
            if (parcelManagement != null)
            {
                ILandObject landObject = parcelManagement.GetLandObject(LocalID);
                if (landObject == null)
                    return;

                AuctionInfo info = GetAuctionInfo(LocalID);
                AuctionBid highestBid = new AuctionBid() {Amount = 0};
                foreach (AuctionBid bid in info.AuctionBids)
                    if (highestBid.Amount < bid.Amount)
                        highestBid = bid;

                IOfflineMessagesConnector offlineMessages =
                    Framework.Utilities.DataManager.RequestPlugin<IOfflineMessagesConnector>();
                if (offlineMessages != null)
                    offlineMessages.AddOfflineMessage(new GridInstantMessage()
                                                          {
                                                              binaryBucket = new byte[0],
                                                              dialog = (byte) InstantMessageDialog.MessageBox,
                                                              fromAgentID = UUID.Zero,
                                                              fromAgentName = "System",
                                                              fromGroup = false,
                                                              imSessionID = UUID.Random(),
                                                              message =
                                                                  "You won the auction for the parcel " +
                                                                  landObject.LandData.Name + ", paying " +
                                                                  highestBid.Amount + " for it",
                                                              offline = 0,
                                                              ParentEstateID = 0,
                                                              Position = Vector3.Zero,
                                                              RegionID = m_scene.RegionInfo.RegionID,
                                                              timestamp = (uint) Util.UnixTimeSinceEpoch(),
                                                              toAgentID = highestBid.AuctionBidder
                                                          });
                landObject.UpdateLandSold(highestBid.AuctionBidder, UUID.Zero, false, landObject.LandData.AuctionID,
                                          highestBid.Amount, landObject.LandData.Area);
            }
        }