public void ResolveUsername_UsernameCached_ShouldReturnCachedConfiguration()
        {
            bool             configurationChanged = false;
            ChannelUser      user       = fixture.PrepareCachedResolve((sender, eventArgs) => { configurationChanged = true; });
            UsernameResolver testObject = fixture.CreateTestObject();

            var result = testObject.ResolveUsername(user);

            Assert.That(result.RealUsername, Is.EqualTo(user.RealUsername));
            Assert.That(result.UserId, Is.EqualTo(user.UserId));
            Assert.That(result.Username, Is.EqualTo("Resolved Name"));
            Assert.That(configurationChanged, Is.False);
        }
        public void ResolveUsername_UsernameNotCached_GivenUsernameWithUnderscoreAndNumbers_ShouldResolveNameProperlyAndChangeConfiguration()
        {
            bool             configurationChanged = false;
            ChannelUser      user       = fixture.PrepareResolve((sender, eventArgs) => { configurationChanged = true; });
            UsernameResolver testObject = fixture.CreateTestObject();

            var result = testObject.ResolveUsername(user);

            Assert.That(result.RealUsername, Is.EqualTo(user.RealUsername));
            Assert.That(result.UserId, Is.EqualTo(user.UserId));
            Assert.That(result.Username, Is.EqualTo("Real name"));
            Assert.That(configurationChanged, Is.True);
        }
Ejemplo n.º 3
0
        public void RemovePresence(ChannelUser user)
        {
            string userId = user.UserId;

            presentUsers.Remove(userId);

            if (!presencesThisSession.ContainsKey(userId))
            {
                presencesThisSession[userId] = 1;
            }
            else
            {
                presencesThisSession[userId]++;
            }
        }
Ejemplo n.º 4
0
        public bool IsGreetingNecessary(ChannelUser user)
        {
            string userId = user.UserId;

            if (!presentUsers.Contains(userId))
            {
                if (!presencesThisSession.TryGetValue(userId, out int presences))
                {
                    return(true);
                }

                return(presences < 1);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public ChannelUser ResolveUsername(ChannelUser user)
        {
            UsernameConfiguration usernameConfiguration = configurationManager.LoadConfiguration <UsernameConfiguration>();

            if (usernameConfiguration.TryGetValue(user.UserId, out string cachedUsername))
            {
                return(user.WithResolvedUsername(cachedUsername));
            }

            StringBuilder sb       = new StringBuilder();
            string        username = user.RealUsername;

            for (int index = 0; index < username.Length; index++)
            {
                char letter = username[index];

                if (char.IsUpper(letter) && index != 0)
                {
                    sb.Append($" {letter}");
                }
                else if (letter == '_')
                {
                    sb.Append(" ");
                }
                else if (char.IsNumber(letter))
                {
                    continue;
                }
                else
                {
                    sb.Append(letter);
                }
            }

            string targetUsername = sb.ToString();

            ChannelUser userWithResolvedUsername = user.WithResolvedUsername(targetUsername);

            usernameConfiguration.AddUsername(userWithResolvedUsername);
            return(userWithResolvedUsername);
        }
Ejemplo n.º 6
0
 public bool IsSayByeNecessary(ChannelUser user)
 {
     return(presentUsers.Contains(user.UserId));
 }
Ejemplo n.º 7
0
        public void RecordPresence(ChannelUser user)
        {
            string userId = user.UserId;

            presentUsers.Add(userId);
        }