public void Setup() { _characterRelationDao = new GenericDao <CharacterRelation, CharacterRelationDto, Guid>(_logger); Broadcaster.Reset(); TestHelpers.Reset(); _session = TestHelpers.Instance.GenerateSession(); _channelHttpClient = TestHelpers.Instance.ChannelHttpClient; _connectedAccountHttpClient = TestHelpers.Instance.ConnectedAccountHttpClient; _friendHttpClient = TestHelpers.Instance.FriendHttpClient; _fDelPacketHandler = new FdelPacketHandler(_friendHttpClient.Object, _channelHttpClient.Object, _connectedAccountHttpClient.Object); _characterDao = new Mock <IGenericDao <CharacterDto> >(); _friendController = new FriendController(_logger, _characterRelationDao, _characterDao.Object, new FriendRequestHolder(), _connectedAccountHttpClient.Object); _friendHttpClient.Setup(s => s.GetListFriends(It.IsAny <long>())) .Returns((long id) => _friendController.GetFriends(id)); _friendHttpClient.Setup(s => s.DeleteFriend(It.IsAny <Guid>())) .Callback((Guid id) => _friendController.Delete(id)); }
public async void GetAllFriendsRoute_Test() { // Arrange var user = CreatePerson(); var friend1 = CreatePerson(); var friend2 = CreatePerson(); var listOfFriends = new List <Person>() { friend1, friend2 }; _personRepository .Setup(x => x.Single(It.IsAny <Expression <Func <Person, bool> > >())) .ReturnsAsync(user); _friendRepository .Setup(x => x.GetConfirmedFriendsWithRelationshipAsync( It.IsAny <Person>(), It.IsAny <FriendsWith>())) .ReturnsAsync(listOfFriends); var personController = new PersonController(_personRepository.Object, _mapper, _emailHelper.Object, _tokenClass.Object); var friendController = new FriendController(_personRepository.Object, _friendRepository.Object, _mapper); // Act var result = await friendController.GetFriends(user.Name); var okResult = result as OkObjectResult; var returnedFriendListJSON = okResult.Value as string; var returnedFriends = JsonSerializer.Deserialize <List <Person> >(returnedFriendListJSON); // Assert Assert.True(okResult != null); Assert.Equal(200, okResult.StatusCode); Assert.True(returnedFriends.Count == listOfFriends.Count); }