示例#1
0
        public void TestDefaultGetSetConfigValues()
        {
            // Load a configuration in StfConfiguration
            var stfConfiguration = new StfConfiguration(@"TestData\Defaulting\DefaultSectionWithEnvironments.xml");

            stfConfiguration.Environment = stfConfiguration.DefaultEnvironment;

            var dUsername = stfConfiguration.GetConfigValue("Users.Username");
            var dPassword = stfConfiguration.GetConfigValue("Users.Password");

            StfAssert.AreEqual("Default Username is User_Kasper", "User_Kasper", dUsername);
            StfAssert.AreEqual("Default Password is K999", "K999", dPassword);

            var newUserName     = "******";
            var newUserPassword = "******";

            stfConfiguration.SetConfigValue("Users.Username", newUserName);
            stfConfiguration.SetConfigValue("Users.Password", newUserPassword);

            dUsername = stfConfiguration.GetConfigValue("Users.Username");
            dPassword = stfConfiguration.GetConfigValue("Users.Password");

            StfAssert.AreEqual("Default Username is updated", newUserName, dUsername);
            StfAssert.AreEqual("Default Password is updated", newUserPassword, dPassword);
        }
示例#2
0
        /// <summary>
        /// The get user info.
        /// </summary>
        /// <param name="userName">
        /// The user name.
        /// </param>
        /// <returns>
        /// The <see cref="User"/>.
        /// </returns>
        protected User GetUserInfo(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                return(default(User));
            }

            var    queryFormat = "Users.{0}.{1}";
            var    userNameKey = string.Format(queryFormat, userName, "Username");
            var    passwordKey = string.Format(queryFormat, userName, "Password");
            string user;
            string password;

            try
            {
                user     = StfConfiguration.GetConfigValue(userNameKey);
                password = StfConfiguration.GetConfigValue(passwordKey);
            }
            catch (Exception exception)
            {
                StfLogger.LogDebug(string.Format("Did not find a user for {0}. Errormessage: {1}", userNameKey, exception.Message));
                throw;
            }

            return(new User {
                UserName = user, Password = password
            });
        }