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 UpdateGameThatNotExists() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); await loginRepository.Add(login); var gameService = new GameServiceBuilder(loginRepository).Build(); var result = await gameService.Update(_gameDto, login.Id); Assert.False(result.Success); }
public async Task AddGameSuccessfully() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); await loginRepository.Add(login); var gameService = new GameServiceBuilder(loginRepository).Build(); var result = await gameService.Add(_gameDto, login.Id); Assert.True(result.Success); }
public async Task AddGameThatLoginDoesNotExists() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); await loginRepository.Add(login); var gameService = new GameServiceBuilder(loginRepository).Build(); var result = await gameService.Add(_gameDto, 1000); Assert.False(result.Success); }
public async Task UpdateGameSuccessfully() { var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); var gameService = new GameServiceBuilder(loginRepository).Build(); await loginRepository.Add(login); var result = await gameService.Add(_gameDto, login.Id); Assert.True(result.Success); var insertedGame = login.Games.Single(); Assert.Equal(insertedGame.Name, _gameDto.Name); }
public async Task DeleteGameSuccessfully() { const int expectedCount = 0; var login = new LoginBuilder().Build(); var loginRepository = new LoginRepositoryBuilder().Build(); var gameService = new GameServiceBuilder(loginRepository).Build(); await loginRepository.Add(login); await gameService.Add(_gameDto, login.Id); var insertedGame = login.Games.Single(); var result = await gameService.Delete(insertedGame.Id, login.Id); Assert.True(result.Success); Assert.Equal(login.Games.Count, expectedCount); }
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 DontLendGameThatIsAlreadyLent() { 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); // Try to lend again var result = await gameService.Lend(gameLoanDto, login.Id); Assert.False(result.Success); }