Ejemplo n.º 1
0
        public void Setup()
        {
            TypeAdapterConfig <MapNpcDto, MapNpc> .NewConfig()
            .ConstructUsing(src => new MapNpc(null, null, null, null, _logger));

            Broadcaster.Reset();
            TestHelpers.Reset();
            _session                    = TestHelpers.Instance.GenerateSession();
            _targetSession              = TestHelpers.Instance.GenerateSession();
            _channelHttpClient          = TestHelpers.Instance.ChannelHttpClient;
            _connectedAccountHttpClient = TestHelpers.Instance.ConnectedAccountHttpClient;
            _friendHttpClient           = TestHelpers.Instance.FriendHttpClient;
            _characterRelationDao       = new GenericDao <CharacterRelation, CharacterRelationDto, Guid>(_logger);
            _friendRequestHolder        = new FriendRequestHolder();
            _connectedAccountHttpClient.Setup(s => s.GetCharacter(_targetSession.Character.CharacterId, null))
            .Returns((new ServerConfiguration(),
                      new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = _targetSession.Character.CharacterId
                }
            }));
            _connectedAccountHttpClient.Setup(s => s.GetCharacter(_session.Character.CharacterId, null))
            .Returns((new ServerConfiguration(),
                      new ConnectedAccount
            {
                ChannelId = 1, ConnectedCharacter = new Character {
                    Id = _session.Character.CharacterId
                }
            }));
            _finsPacketHandler = new FinsPacketHandler(_friendHttpClient.Object, _channelHttpClient.Object,
                                                       _connectedAccountHttpClient.Object);
        }
Ejemplo n.º 2
0
 public FriendController(ILogger logger, IDao <CharacterRelationDto, Guid> characterRelationDao,
                         IDao <CharacterDto, long> characterDao, FriendRequestHolder friendRequestHolder,
                         IConnectedAccountHttpClient connectedAccountHttpClient)
 {
     _logger = logger;
     _characterRelationDao       = characterRelationDao;
     _characterDao               = characterDao;
     _friendRequestHolder        = friendRequestHolder;
     _connectedAccountHttpClient = connectedAccountHttpClient;
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }