public void Range_rule_positive() { const string displayName = "User name"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, _rangeRuleValue, ResxValidator.Keywords.Range, RangeRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value min var value = MinRangeRuleValue.ToString(); var result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value middle value = new Random().Next(MinRangeRuleValue, MaxRangeRuleValue).ToString(); result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value max value = MaxRangeRuleValue.ToString(); result = validator.IsValid(MemberName, value, out _); Assert.True(result); }
public void Max_length_rule_negative() { var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, null) .SetUpRule(MemberName, MaxLengthRuleValue, ResxValidator.Keywords.MaxLength, MaxLengthRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value null var result = validator.IsValid(MemberName, null, out var gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format( MaxLengthRuleMessage, null, MaxLengthRuleValue)); // value empty var value = string.Empty; result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format( MaxLengthRuleMessage, null, MaxLengthRuleValue)); // value too long value = new string('a', MaxLengthRuleValue + 1); result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format( MaxLengthRuleMessage, null, MaxLengthRuleValue)); }
public void Length_rule_positive() { const string displayName = "User name"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, _lengthRuleValue, ResxValidator.Keywords.Length, LengthRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value min var value = new string('a', MinLengthRuleValue); var result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value middle value = new string('a', new Random() .Next(MinLengthRuleValue, MaxLengthRuleValue)); result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value max value = new string('a', MaxLengthRuleValue); result = validator.IsValid(MemberName, value, out _); Assert.True(result); }
public void Pattern_rule_negative() { var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, null) .SetUpRule(MemberName, PatternRuleValue, ResxValidator.Keywords.Pattern, PatternRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value null var result = validator.IsValid(MemberName, null, out var gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format( PatternRuleMessage, MemberName + ResxValidator.Keywords.DisplayName)); // value empty var value = string.Empty; result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format( PatternRuleMessage, MemberName + ResxValidator.Keywords.DisplayName)); // value incorrect value = "a"; result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format(PatternRuleMessage, MemberName + ResxValidator.Keywords.DisplayName)); }
public void Max_value_rule_positive() { const string displayName = "User name"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, MaxValueRuleValue, ResxValidator.Keywords.MaxValue, MaxValueRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value max var value = MaxValueRuleValue.ToString(); var result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value more than max value = (MaxValueRuleValue - 1).ToString(); result = validator.IsValid(MemberName, value, out _); Assert.True(result); }
public void Values_rule_positive() { const string displayName = "User name"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, _valuesRuleValue, ResxValidator.Keywords.Values, ValuesRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value var value = ValuesRuleFirstValue; var result = validator.IsValid(MemberName, value, out _); Assert.True(result); // value with spaces value = ValuesRuleLastValue; result = validator.IsValid(MemberName, value, out _); Assert.True(result); }
public void Range_rule_negative() { var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, null) .SetUpRule(MemberName, _rangeRuleValue, ResxValidator.Keywords.Range, RangeRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value null var result = validator.IsValid(MemberName, null, out var gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format(RangeRuleMessage, MemberName + ResxValidator.Keywords.DisplayName, _rangeRuleValue)); // value empty var value = string.Empty; result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format(RangeRuleMessage, MemberName + ResxValidator.Keywords.DisplayName, _rangeRuleValue)); // value too small value = (MinRangeRuleValue - 1).ToString(); result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format(RangeRuleMessage, MemberName + ResxValidator.Keywords.DisplayName, _rangeRuleValue)); // value too big value = (MaxRangeRuleValue + 1).ToString(); result = validator.IsValid(MemberName, value, out gotMessage); Assert.False(result); Assert.Equal(gotMessage, string.Format(RangeRuleMessage, MemberName + ResxValidator.Keywords.DisplayName, _rangeRuleValue)); }
public void Pattern_rule_positive() { const string displayName = "User email"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, PatternRuleValue, ResxValidator.Keywords.Pattern, ValuesRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value const string value = "*****@*****.**"; var result = validator.IsValid(MemberName, value, out _); Assert.True(result); }
public void Required_rule_positive() { const string displayName = "User name"; var mockLocalizer = new Mock <IStringLocalizer>() .SetUpDisplayName(MemberName, displayName) .SetUpRule(MemberName, null, ResxValidator.Keywords.Required, RequiredRuleMessage); var validator = new ResxValidator(mockLocalizer.Object); // value const string value = "a"; var result = validator.IsValid(MemberName, value, out _); Assert.True(result); }