public void GivenCollectionWithKeyAsIntegerWhenGetIntegerThenReturnValue()
        {
            // arrange
            var testClass = new NameValueCollection { { TestKey, "9" } };

            // act
            var result = testClass.GetInteger(TestKey, 3);

            // assert
            Assert.That(result, Is.EqualTo(9));
        }
        public void GivenCollectionWithKeyAsEmtpyStringWhenGetIntegerThenReturnDefault()
        {
            // arrange
            var testClass = new NameValueCollection { { TestKey, string.Empty } };

            // act
            var result = testClass.GetInteger(TestKey, 3);

            // assert
            Assert.That(result, Is.EqualTo(3));
        }
        public override void Initialize(string name, NameValueCollection config)
        {
            Condition.Requires(name, "name").IsNotNullOrWhiteSpace();
            Condition.Requires(config, "config").IsNotNull();

            if (config.ContainsKey("requiresQuestionAndAnswer"))
            {
                throw new ProviderException("unrecognized attribute requiresQuestionAndAnswer");
            }

            if (config.ContainsKey("enablePasswordRetrieval"))
            {
                throw new ProviderException("unrecognized attribute enablePasswordRetrieval");
            }

            if (config.ContainsKey("enablePasswordReset"))
            {
                throw new ProviderException("unrecognized attribute enablePasswordReset");
            }

            if (config.ContainsKey("passwordFormat"))
            {
                throw new ProviderException("unrecognized attribute passwordFormat");
            }

            this.connectionStringName = config.GetString("connectionStringName", "DefaultConnection");
            this.userTableName = config.GetString("userTableName", "UserProfile");
            this.userIdColumn = config.GetString("userIdColumn", "UserId");
            this.userNameColumn = config.GetString("userNameColumn", "UserName");
            this.userEmailColumn = config.GetString("userEmailColumn");
            this.autoCreateTables = config.GetBoolean("autoCreateTables", true);
            this.autoInitialize = config.GetBoolean("autoInitialize", true);
            this.maxInvalidPasswordAttempts = config.GetInteger("maxInvalidPasswordAttempts", int.MaxValue);
            this.minRequiredNonalphanumericCharacters = config.GetInteger("minRequiredNonalphanumericCharacters");
            this.minRequiredPasswordLength = config.GetInteger("minRequiredPasswordLength", 1);
            this.requiresUniqueEmail = config.GetBoolean("requiresUniqueEmail");
            this.maxEmailLength = config.GetInteger("maxEmailLength", 254);
            this.maxUserNameLength = config.GetInteger("maxUserNameLength", 56);
            this.maxPasswordLength = config.GetInteger("maxPasswordLength", 128);
            this.emailStrengthRegularExpression = config.GetString(
                "emailStrengthRegularExpression", @"^[0-9a-zA-Z.+_-]+@[0-9a-zA-Z.+_-]+\.[a-zA-Z]{2,4}$");
            this.userNameRegularExpression = config.GetString("userNameRegularExpression", @"^[0-9a-zA-Z_-]+$");
            this.ApplicationName = config.GetString("applicationName", "/");
            this.allowEmailAsUserName = config.GetBoolean("allowEmailAsUserName", true);

            try
            {
                new Regex(this.emailStrengthRegularExpression);
            }
            catch (ArgumentException e)
            {
                throw new ProviderException("invalid value for emailStrengthRegularExpression", e);
            }

            try
            {
                new Regex(this.userNameRegularExpression);
            }
            catch (ArgumentException e)
            {
                throw new ProviderException("invalid value for userNameRegularExpression", e);
            }

            if (config.ContainsKey("passwordAttemptWindowInSeconds") && config.ContainsKey("passwordAttemptWindow"))
            {
                throw new ProviderException(
                    "passwordAttemptWindowInSeconds and passwordAttemptWindow cannot both be set");
            }

            if (config.ContainsKey("passwordAttemptWindowInSeconds"))
            {
                this.passwordAttemptWindowInSeconds = config.GetInteger("passwordAttemptWindowInSeconds", int.MaxValue);
            }
            else
            {
                var passwordAttemptWindowInMinutes = config.GetInteger("passwordAttemptWindow", -1);
                if (passwordAttemptWindowInMinutes < 0)
                {
                    this.passwordAttemptWindowInSeconds = int.MaxValue;
                }
                else
                {
                    this.passwordAttemptWindowInSeconds = passwordAttemptWindowInMinutes * 60;
                }
            }

            if (this.requiresUniqueEmail && !this.HasEmailColumnDefined)
            {
                throw new ProviderException("requiresUniqueEmail cannot be defined without userEmailColumn");
            }

            config.Remove("userTableName");
            config.Remove("userIdColumn");
            config.Remove("userNameColumn");
            config.Remove("userEmailColumn");
            config.Remove("autoCreateTables");
            config.Remove("autoInitialize");
            config.Remove("passwordAttemptWindow");
            config.Remove("passwordAttemptWindowInSeconds");
            config.Remove("maxEmailLength");
            config.Remove("maxUserNameLength");
            config.Remove("maxPasswordLength");
            config.Remove("emailStrengthRegularExpression");
            config.Remove("userNameRegularExpression");
            config.Remove("allowEmailAsUserName");

            var providerName = string.Empty;
            var connectionString = ConfigurationManager.ConnectionStrings[this.ConnectionStringName];
            if (connectionString != null)
            {
                providerName = connectionString.ProviderName;
            }

            this.sqlQueryBuilder = this.sqlQueryBuilderFactory(
                providerName, this.userTableName, this.userIdColumn, this.userNameColumn, this.userEmailColumn);

            base.Initialize(name, config);

            if (this.AutoInitialize)
            {
                this.InitializeDatabaseConnection();

                if (this.HasEmailColumnDefined)
                {
                    this.CreateUserEmailColumn();
                }
            }
        }
        public void GivenCollectionWithKeyAsNotIntegerAndNoDefaulWhenGetIntegerThenReturnZero()
        {
            // arrange
            var testClass = new NameValueCollection { { TestKey, "xx" } };

            // act
            var result = testClass.GetInteger(TestKey);

            // assert
            Assert.That(result, Is.EqualTo(0));
        }