示例#1
0
        public async Task LoginAs(string chatApiKey, string battleTag, string chatRoom)
        {
            var user = await _authenticationService.GetUser(chatApiKey, battleTag);

            var ban = await _banRepository.GetBan(battleTag.ToLower());

            var nowDate = DateTime.Now.ToString("yyyy-MM-dd");

            if (ban != null && string.Compare(ban.endDate, nowDate, StringComparison.Ordinal) > 0)
            {
                await Clients.Caller.SendAsync("PlayerBannedFromChat", ban);
            }
            else
            {
                if (!user.VerifiedBattletag)
                {
                    await Clients.Caller.SendAsync("ChatKeyInvalid");
                }

                _connections.Add(Context.ConnectionId, chatRoom, user);
                await Groups.AddToGroupAsync(Context.ConnectionId, chatRoom);

                var usersOfRoom = _connections.GetUsersOfRoom(chatRoom);

                await Clients.Group(chatRoom).SendAsync("UserEntered", user);

                await Clients.Caller.SendAsync("StartChat", usersOfRoom, _chatHistory.GetMessages(chatRoom));
            }
        }
示例#2
0
        public async Task InvitePlayer_ClanNotPresent()
        {
            await _banRepo.UpdateBans(new List <BannedPlayerReadmodel>
            {
                new BannedPlayerReadmodel
                {
                    battleTag = "user#1",
                    endDate   = "2020-01-02"
                },
                new BannedPlayerReadmodel
                {
                    battleTag = "user#2",
                    endDate   = "2020-01-03"
                }
            });

            var bans = await _banRepo.GetBans();

            Assert.AreEqual("user#2", bans[0].battleTag);
            Assert.AreEqual("user#1", bans[1].battleTag);
            Assert.AreEqual("user#1", (await _banRepo.GetBan("user#1")).battleTag);
        }