public void DeleteAuctionTest() { var mock = new Mock <IAuctionBusiness>(); mock.Setup(x => x.DeleteAuctionAsync(It.IsAny <int>())).ReturnsAsync(true); this._auctionBusiness = mock.Object; //Act var actual = _auctionBusiness.DeleteAuctionAsync(1).Result; //Assert Assert.True(actual); }
public async Task <IActionResult> DeleteAuctionAsync(int auctionId) { bool result = false; var userId = _userManager.GetUserId(HttpContext.User); if (_usersBusiness.IsAllowed(auctionId, userId)) { result = await _auctionBusiness.DeleteAuctionAsync(auctionId); } else { ModelState.AddModelError(string.Empty, ErrorConstants.NotAllowed); var model = new DetailViewModel() { Auction = await _auctionBusiness.GetAuctionAsync(auctionId), Bids = await _bidBusiness.GetBidsAsync(auctionId) }; return(View("Detail", model)); } if (result) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, ErrorConstants.CantDeleteAuction); var model = new DetailViewModel() { Auction = await _auctionBusiness.GetAuctionAsync(auctionId), Bids = await _bidBusiness.GetBidsAsync(auctionId) }; return(View("Detail", model)); } }