示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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);
        }