public void InvalidInputInSingleValidatorThrowsException() { var invalidValue = "lowercase_only"; var optionSettingItem = new OptionSettingItem("id", "name", "description") { Validators = new() { new OptionSettingItemValidatorConfig { ValidatorType = OptionSettingItemValidatorList.Regex, Configuration = new RegexValidator { Regex = "^[A-Z]*$" } } } }; ValidationFailedException exception = null; // ACT try { optionSettingItem.SetValueOverride(invalidValue); } catch (ValidationFailedException e) { exception = e; } exception.ShouldNotBeNull(); exception.Message.ShouldContain("[A-Z]*"); }
public void CustomValidatorMessagePropagatesToValidationException() { // ARRANGE var customValidationMessage = "Custom Validation Message: Testing!"; var invalidValue = 100; var optionSettingItem = new OptionSettingItem("id", "name", "description") { Validators = new() { new OptionSettingItemValidatorConfig { ValidatorType = OptionSettingItemValidatorList.Range, Configuration = new RangeValidator { Min = 7, Max = 10, ValidationFailedMessage = customValidationMessage } } } }; ValidationFailedException exception = null; // ACT try { optionSettingItem.SetValueOverride(invalidValue); } catch (ValidationFailedException e) { exception = e; } exception.ShouldNotBeNull(); exception.Message.ShouldEqual(customValidationMessage); } }
private void Validate <T>(OptionSettingItem optionSettingItem, T value, bool isValid) { ValidationFailedException exception = null; try { optionSettingItem.SetValueOverride(value); } catch (ValidationFailedException e) { exception = e; } if (isValid) { exception.ShouldBeNull(); } else { exception.ShouldNotBeNull(); } }
public void InvalidInputInMultipleValidatorsThrowsException(string invalidValue) { var optionSettingItem = new OptionSettingItem("id", "name", "description") { Validators = new() { new OptionSettingItemValidatorConfig { ValidatorType = OptionSettingItemValidatorList.Required }, new OptionSettingItemValidatorConfig { ValidatorType = OptionSettingItemValidatorList.Range, Configuration = new RangeValidator { Min = 7, Max = 10 } } } }; ValidationFailedException exception = null; // ACT try { optionSettingItem.SetValueOverride(invalidValue); } catch (ValidationFailedException e) { exception = e; } exception.ShouldNotBeNull(); _output.WriteLine(exception.Message); }