Пример #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 UpdateFriendThatNotExists()
        {
            var login           = new LoginBuilder().Build();
            var loginRepository = new LoginRepositoryBuilder().Build();

            await loginRepository.Add(login);

            var friendService = new FriendServiceBuilder(loginRepository).Build();
            var result        = await friendService.Update(_friendDto, login.Id);

            Assert.False(result.Success);
        }
Пример #3
0
        public async Task AddFriendSuccessfully()
        {
            var login           = new LoginBuilder().Build();
            var loginRepository = new LoginRepositoryBuilder().Build();

            await loginRepository.Add(login);

            var friendService = new FriendServiceBuilder(loginRepository).Build();
            var result        = await friendService.Add(_friendDto, login.Id);

            Assert.True(result.Success);
        }
Пример #4
0
        public async Task AddFriendThatLoginDoesNotExists()
        {
            var login           = new LoginBuilder().Build();
            var loginRepository = new LoginRepositoryBuilder().Build();

            await loginRepository.Add(login);

            var friendService = new FriendServiceBuilder(loginRepository).Build();
            var result        = await friendService.Add(_friendDto, 1000);

            Assert.False(result.Success);
        }
Пример #5
0
        public async Task UpdateFriendSuccessfully()
        {
            var login           = new LoginBuilder().Build();
            var loginRepository = new LoginRepositoryBuilder().Build();
            var friendService   = new FriendServiceBuilder(loginRepository).Build();

            await loginRepository.Add(login);

            var result = await friendService.Add(_friendDto, login.Id);

            Assert.True(result.Success);

            var insertedFriend = login.Friends.Single();

            Assert.Equal(insertedFriend.Name, _friendDto.Name);
            Assert.Equal(insertedFriend.PhoneNumber, _friendDto.PhoneNumber);
        }
Пример #6
0
        public async Task DeleteFriendSuccessfully()
        {
            const int expectedCount   = 0;
            var       login           = new LoginBuilder().Build();
            var       loginRepository = new LoginRepositoryBuilder().Build();
            var       friendService   = new FriendServiceBuilder(loginRepository).Build();

            await loginRepository.Add(login);

            await friendService.Add(_friendDto, login.Id);

            var insertedFriend = login.Friends.Single();
            var result         = await friendService.Delete(insertedFriend.Id, login.Id);

            Assert.True(result.Success);
            Assert.Equal(login.Friends.Count, expectedCount);
        }
Пример #7
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);
        }
Пример #8
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);
        }