public async Task Should_Borrow_Games() { //Arrange unityOfWorkMock.Setup(c => c.Games.GetGameByIdWithBorrowed(It.Is <int>(c => c == 1))).ReturnsAsync(new Game("game 1")); unityOfWorkMock.Setup(c => c.Games.GetGameByIdWithBorrowed(It.Is <int>(c => c == 2))).ReturnsAsync(new Game("game 2")); //Act var serviceResult = await borrowGameService.BorrowGames(userId, new List <int> { 1, 2 }); //Assert Assert.IsTrue(serviceResult.Success); Assert.IsEmpty(serviceResult.ValidationMessages); }
public async Task <IActionResult> BorrowGame([FromBody] List <int> borrowedGamesIds) { try { var serviceResult = await _borrowGamesService.BorrowGames(GetUserId(), borrowedGamesIds); if (!serviceResult.Success) { return(BadRequest(serviceResult.ValidationMessages)); } var result = _mapper.Map <IList <BorrowedGame>, IList <CreateBorrowedGameDto> >(serviceResult.Result); return(Created($"BorrowGameId: {result.Select(c => c.BorrowedGameId).ToList()}", result)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }