public async Task ReturnGameSuccessfully() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); var gameService = new GameServiceBuilder(loginRepository).Build(); var friendService = new FriendServiceBuilder(loginRepository).Build(); await loginRepository.Add(login); await gameService.Add(_gameDto, login.Id); await friendService.Add(_friendDto, login.Id); var insertedGame = login.Games.Single(); var insertedFriend = login.Friends.Single(); var gameLoanDto = new GameLoanDto(insertedGame.Id, insertedFriend.Id); await gameService.Lend(gameLoanDto, login.Id); var gameReturnDto = new GameReturnDto(insertedGame.Id); var result = await gameService.Return(gameReturnDto, login.Id); Assert.True(result.Success); Assert.Null(insertedGame.FriendId); }
public async Task <ActionResult <Result> > Return(GameReturnDto gameReturnDto) { var loginId = await GetLoginId(); var result = await _gameService.Return(gameReturnDto, loginId); return(Ok(result)); }
public async Task DontReturnGameThatIsNotLent() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); var gameService = new GameServiceBuilder(loginRepository).Build(); var friendService = new FriendServiceBuilder(loginRepository).Build(); await loginRepository.Add(login); await gameService.Add(_gameDto, login.Id); await friendService.Add(_friendDto, login.Id); var insertedGame = login.Games.Single(); var gameReturnDto = new GameReturnDto(insertedGame.Id); var result = await gameService.Return(gameReturnDto, login.Id); Assert.False(result.Success); Assert.Null(insertedGame.FriendId); }
public async Task <Result> Return(GameReturnDto gameReturnDto, int loginId) { try { var login = await GetLoginIfExists(loginId); var game = GetGame(login, gameReturnDto.GameId); if (game.FriendId == null) { return(new Result(false, "Game is not lent")); } login.ReturnGame(game.Id); await _loginRepository.Update(login); return(new Result(true, "Game returned")); } catch (Exception exception) { return(new Result(false, exception.Message)); } }