Пример #1
0
 public void CreateBidsByService(IList <Bid> bids)
 {
     foreach (var bid in bids)
     {
         LinkBidToScenarioAuction(bid);
         BidsService.PlaceBid(bid);
     }
 }
Пример #2
0
        public void PlaceBid_WithNullBid_WillThrowException()
        {
            TestDelegate act =
                () => BidsService.PlaceBid(null);

            var ex = Assert.Throws <ArgumentNullException>(act);

            StringAssert.Contains("Value cannot be null.\r\nParameter name: bid", ex.Message);
        }
Пример #3
0
        private Bid CreateBid(int auctionId, string username, double price)
        {
            Bid bid = new Bid()
            {
                Username = username, Price = price, AuctionId = auctionId
            };

            BidsService.PlaceBid(bid);
            return(bid);
        }
Пример #4
0
        public void PlaceBid_WithoutAuctionId_WillThrowException()
        {
            Bid bid = new Bid()
            {
                Username = "******", Price = 11
            };

            TestDelegate act = () => BidsService.PlaceBid(bid);

            var ex = Assert.Throws <ArgumentException>(act);

            StringAssert.Contains("AuctionId can't be null", ex.Message);
        }
Пример #5
0
        public void PlaceBid_WithInvalidPrice_WillThrowException(double price)
        {
            Bid bid = new Bid()
            {
                Username = "******", Price = price
            };

            TestDelegate act = () => BidsService.PlaceBid(bid);

            var ex = Assert.Throws <ArgumentException>(act);

            StringAssert.Contains("Invalid price, price should be greater than 0", ex.Message);
        }
Пример #6
0
        public void PlaceBid_WithInvalidUsername_WillThrowException(string username)
        {
            Bid bid = new Bid()
            {
                Price = 10, Username = username
            };

            TestDelegate act = () => BidsService.PlaceBid(bid);

            var ex = Assert.Throws <ArgumentException>(act);

            StringAssert.Contains("Username can't be null", ex.Message);
        }
Пример #7
0
        public void PlaceBid_WithValidUsernameAndPrice_WillBeSaved(double price, string username)
        {
            var newBid = new Bid()
            {
                Price     = price,
                Username  = username,
                AuctionId = 1
            };

            BidsService.PlaceBid(newBid);

            var bids      = BidsService.GetAllBids(1);
            var actualBid = bids.First();

            actualBid.ShouldCompare(newBid);
        }
Пример #8
0
        public void PlaceBid_UpdatePrice_WillUpdateTheLastBid()
        {
            var firstBid = new Bid()
            {
                AuctionId = 1, Price = 10, Username = "******"
            };

            BidsService.PlaceBid(firstBid);

            var secondBid = new Bid()
            {
                AuctionId = 1, Price = 12, Username = "******"
            };

            BidsService.PlaceBid(secondBid);

            var allBids = BidsService.GetAllBids(1);

            Assert.AreEqual(1, allBids.Count);
            allBids[0].ShouldCompare(secondBid);
        }
Пример #9
0
        public IHttpActionResult PlaceBid(Bid bid)
        {
            if (bid == null)
            {
                return(BadRequest("Bid cannot be empty!"));
            }
            if (!bid.Price.HasValue)
            {
                return(BadRequest("Price cannot be empty!"));
            }
            if (string.IsNullOrEmpty(bid.Username))
            {
                return(BadRequest("Username cannot be empty!"));
            }
            if (bid.Price <= 0)
            {
                return(BadRequest("Price must be greater than 0"));
            }

            BidsService.PlaceBid(bid);

            return(Ok());
        }