Ejemplo n.º 1
0
        public Task <HttpResponseMessage> PostAuction(Auction entity)
        {
            HttpResponseMessage response;

            try
            {
                auctionBusinessService.Save(entity);
                response = Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            var taskCompletion = new TaskCompletionSource <HttpResponseMessage>();

            taskCompletion.SetResult(response);

            return(taskCompletion.Task);
        }
        public void When_Saving_An_Auction_Then_TheRepository_Should_Be_Called(bool newAuction)
        {
            var auction = newAuction ? new Auction() : new Auction(1, It.IsAny <Item>());

            mockRepository.Setup(x => x.Create(auction)).Verifiable();
            mockRepository.Setup(x => x.Update(auction)).Verifiable();

            auctionService.Save(auction);

            if (newAuction)
            {
                mockRepository.Verify(x => x.Create(It.IsAny <Auction>()), Times.Once);
                mockRepository.Verify(x => x.Update(It.IsAny <Auction>()), Times.Never);
            }
            else
            {
                mockRepository.Verify(x => x.Create(It.IsAny <Auction>()), Times.Never);
                mockRepository.Verify(x => x.Update(It.IsAny <Auction>()), Times.Once);
            }
        }