Example #1
0
        public Task <HttpResponseMessage> Bid(int auctionId, int buyerId, double bidValue)
        {
            HttpResponseMessage response;

            try
            {
                var result = auctionBusinessService.PlaceBid(auctionId, buyerId, bidValue);

                if (result != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, result);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.ExpectationFailed, "Place a bid was not possible for this auction.");
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            var taskCompletion = new TaskCompletionSource <HttpResponseMessage>();

            taskCompletion.SetResult(response);

            return(taskCompletion.Task);
        }
        public void When_Place_A_Bid_Then_TheAuctionBid_Should_Be_Added_For_TheBuyer()
        {
            //Arrange
            var auction = new Auction
                          (
                It.IsAny <int>(),
                new Item(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(), 50)
                          );

            mockRepository.Setup(x => x.GetById(1)).Returns(auction);

            //Act
            auctionService.PlaceBid(1, 2, 100);

            //Assert
            mockRepository.Verify(x => x.Update(auction), Times.Once);

            Assert.That(auction.Bids.Count == 1);
            Assert.That(auction.Bids.FirstOrDefault().BuyerId == 2);
        }