public async Task CreateBidAsync_CreateValidBid_BidCreated() { var bid = new BidDTO() { BidId = 6, Date = new DateTime(2019, 1, 1, 12, 0, 0), PlacedUserName = "******", LotId = 1, Price = 20 }; _mockUnitWork.Setup(x => x.UserProfiles.FindAsync(It.IsAny <Expression <Func <UserProfile, bool> > >(), 10, 0)) .ReturnsAsync((Items: _users, TotalCount: 1)); _mockUnitWork.Setup(x => x.Lots.GetAsync(bid.LotId)).ReturnsAsync(new Lot() { LotId = 1, BeginDate = new DateTime(2018, 1, 1, 12, 0, 0), EndDate = new DateTime(2020, 1, 1, 12, 0, 0) }); _mockUnitWork.Setup(x => x.Bids.GetAsync(bid.BidId)).ReturnsAsync(new Bid() { BidId = 6 }); var createdBid = await _service.CreateBidAsync(bid); Assert.That(createdBid, Is.Not.Null); Assert.That(createdBid.BidId, Is.EqualTo(bid.BidId)); _mockUnitWork.Verify(x => x.SaveAsync(), Times.Once); }
public async Task <IHttpActionResult> CreateBidAsync(int lotId, BidDTO bid) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bid.Price = Math.Round(bid.Price, 2); bid.PlacedUserName = User.Identity.Name; bid.LotId = lotId; var createdBid = await _bidsService.CreateBidAsync(bid); return(Created(Request.RequestUri + "/" + createdBid?.LotId, createdBid)); }