public void Test_Add_Distant_Friend() { _targetSession.Character.FriendRequestCharacters.TryAdd(0, _session.Character.CharacterId); var flPacket = new FlPacket { CharacterName = _targetSession.Character.Name }; _handler.AddDistantFriend(flPacket); Assert.IsTrue(_session.Character.CharacterRelations.Any(s => s.Value.RelatedCharacterId == _targetSession.Character.CharacterId) && _targetSession.Character.CharacterRelations.Any(s => s.Value.RelatedCharacterId == _session.Character.CharacterId)); }
public async Task Test_Add_Distant_FriendAsync() { var targetSession = await TestHelpers.Instance.GenerateSessionAsync().ConfigureAwait(false); var friendRequestHolder = new FriendRequestHolder(); friendRequestHolder.FriendRequestCharacters.TryAdd(Guid.NewGuid(), new Tuple <long, long>(targetSession.Character.CharacterId, _session !.Character.CharacterId)); var flPacket = new FlPacket { CharacterName = targetSession.Character.Name }; TestHelpers.Instance.ConnectedAccountHttpClient .Setup(s => s.GetCharacterAsync(targetSession.Character.CharacterId, null)) .ReturnsAsync(new Tuple <ServerConfiguration?, ConnectedAccount?>(new ServerConfiguration(), new ConnectedAccount { ChannelId = 1, ConnectedCharacter = new Character { Id = targetSession.Character.CharacterId } })); TestHelpers.Instance.ConnectedAccountHttpClient .Setup(s => s.GetCharacterAsync(_session.Character.CharacterId, null)) .ReturnsAsync(new Tuple <ServerConfiguration?, ConnectedAccount?>(new ServerConfiguration(), new ConnectedAccount { ChannelId = 1, ConnectedCharacter = new Character { Id = _session.Character.CharacterId } })); using var friend = new FriendController(Logger, _characterRelationDao !, TestHelpers.Instance.CharacterDao, friendRequestHolder, TestHelpers.Instance.ConnectedAccountHttpClient.Object); TestHelpers.Instance.FriendHttpClient.Setup(s => s.AddFriendAsync(It.IsAny <FriendShipRequest>())) .Returns(friend.AddFriendAsync(new FriendShipRequest { CharacterId = _session.Character.CharacterId, FinsPacket = new FinsPacket { CharacterId = targetSession.Character.VisualId, Type = FinsPacketType.Accepted } })); await _flPacketHandler !.ExecuteAsync(flPacket, _session).ConfigureAwait(false); Assert.IsTrue(await _characterRelationDao !.FirstOrDefaultAsync(s => (s.CharacterId == _session.Character.CharacterId) && (s.RelatedCharacterId == targetSession.Character.CharacterId) && (s.RelationType == CharacterRelationType.Friend)).ConfigureAwait(false) != null); }
public void Test_Add_Distant_Friend() { var targetSession = TestHelpers.Instance.GenerateSession(); var friendRequestHolder = new FriendRequestHolder(); friendRequestHolder.FriendRequestCharacters.TryAdd(Guid.NewGuid(), new Tuple <long, long>(targetSession.Character.CharacterId, _session.Character.CharacterId)); var flPacket = new FlPacket { CharacterName = targetSession.Character.Name }; TestHelpers.Instance.ConnectedAccountHttpClient .Setup(s => s.GetCharacter(targetSession.Character.CharacterId, null)) .Returns((new ServerConfiguration(), new ConnectedAccount { ChannelId = 1, ConnectedCharacter = new Character { Id = targetSession.Character.CharacterId } })); TestHelpers.Instance.ConnectedAccountHttpClient .Setup(s => s.GetCharacter(_session.Character.CharacterId, null)) .Returns((new ServerConfiguration(), new ConnectedAccount { ChannelId = 1, ConnectedCharacter = new Character { Id = _session.Character.CharacterId } })); using var friend = new FriendController(_logger, _characterRelationDao, TestHelpers.Instance.CharacterDao, friendRequestHolder, TestHelpers.Instance.ConnectedAccountHttpClient.Object); TestHelpers.Instance.FriendHttpClient.Setup(s => s.AddFriend(It.IsAny <FriendShipRequest>())) .Returns(friend.AddFriend(new FriendShipRequest { CharacterId = _session.Character.CharacterId, FinsPacket = new FinsPacket { CharacterId = targetSession.Character.VisualId, Type = FinsPacketType.Accepted } })); _flPacketHandler.Execute(flPacket, _session); Assert.IsTrue(_characterRelationDao.FirstOrDefault(s => (s.CharacterId == _session.Character.CharacterId) && (s.RelatedCharacterId == targetSession.Character.CharacterId) && (s.RelationType == CharacterRelationType.Friend)) != null); }
/// <summary> /// flPacket packet /// </summary> /// <param name="flPacket"></param> public void AddDistantFriend(FlPacket flPacket) { ClientSession target = ServerManager.Instance.Sessions.Values.FirstOrDefault(s => s.Character.Name == flPacket.CharacterName); if (target == null) { Session.SendPacket(new InfoPacket { Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER, Session.Account.Language) }); return; } var fins = new FinsPacket { CharacterId = target.Character.CharacterId, Type = FinsPacketType.Accepted }; AddFriend(fins); }
/// <summary> /// flPacket packet /// </summary> /// <param name="flPacket"></param> public void AddDistantFriend(FlPacket flPacket) { var target = Broadcaster.Instance.GetCharacter(s => s.Name == flPacket.CharacterName); if (target == null) { Session.SendPacket(new InfoPacket { Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER, Session.Account.Language) }); return; } var fins = new FinsPacket { CharacterId = target.VisualId, Type = FinsPacketType.Accepted }; AddFriend(fins); }