public async void AddingExistingFriendToCharacter_ShouldThrowException()
        {
            var anyCharacter = new Character()
            {
                Name = "test"
            };

            _characterRepositoryMock.Setup(f => f.HasFriendAlready(anyCharacter, anyCharacter)).Returns(true);
            await Assert.ThrowsAsync <InvalidOperationException>(() => _sut.AddFriendToCharacterAsync(anyCharacter, anyCharacter));
        }
Example #2
0
        public async Task <ActionResult <List <CharacterResult> > > AddFriendToCharacter(int characterId, int friendId)
        {
            var character = await _characterRepository.GetCharacterAsync(characterId);

            if (character == null)
            {
                NotFound();
            }
            var friend = await _characterRepository.GetCharacterAsync(friendId);

            if (friend == null)
            {
                return(NotFound());
            }

            try
            {
                await _characterService.AddFriendToCharacterAsync(character, friend);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }

            return(CreatedAtAction(
                       "GetCharacter",
                       new { characterId },
                       _mapper.Map <CharacterResult>(character)));
        }