コード例 #1
0
            public ChannelUser PrepareResolve(PropertyChangedEventHandler configurationWasChangedCheck)
            {
                UsernameConfiguration configuration = new UsernameConfiguration();

                configuration.PropertyChanged += configurationWasChangedCheck;

                configurationManagerMock
                .Setup(x => x.LoadConfiguration <UsernameConfiguration>())
                .Returns(configuration);

                return(CreateUserWithUnresolvedName());
            }
コード例 #2
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);
        }
コード例 #3
0
 public UsernameGenerator(
     IGenericCodeGenerator generator,
     UsernameConfiguration configuration
     ) : base(generator, configuration)
 {
 }