public void Infer_SuccessfullyAccountsForExistingNamesWithNameUpdate() { var existingNames = new List <string>() { "Page1" }; Func <IEnumerable <string> > getExistingNames = () => { return(existingNames); }; var config = new ItemNameValidationConfig() { ReservedNames = new string[] { "Page", }, ValidateExistingNames = true, }; var validationService = new ItemNameService(config, getExistingNames); var result = validationService.Infer("Page"); Assert.Equal("Page2", result); existingNames.Add("Page2"); var result2 = validationService.Infer("Page"); Assert.Equal("Page3", result2); }
public void Validate_SuccessfullyAccountsForEmptyNames() { var config = new ItemNameValidationConfig() { ValidateEmptyNames = true, }; var validationService = new ItemNameService(config, null); var result = validationService.Validate(string.Empty); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.ErrorType == ValidationErrorType.EmptyName); Assert.Contains(result.Errors, e => e.ValidatorName == "EmptyNameValidator"); }
public void Infer_SuccessfullyAccountsForReservedNames() { var config = new ItemNameValidationConfig() { ReservedNames = new string[] { "Page", }, }; var validationService = new ItemNameService(config, null); var result = validationService.Infer("Page"); Assert.Equal("Page1", result); }
public void Validate_SuccessfullyAccountsForDefaultNames(string language) { SetUpFixtureForTesting(language); var config = new ItemNameValidationConfig() { ValidateDefaultNames = true, }; var validationService = new ItemNameService(config, null); var result = validationService.Validate("LiveTile"); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.ErrorType == ValidationErrorType.ReservedName); Assert.Contains(result.Errors, e => e.ValidatorName == "DefaultNamesValidator"); }
public void Validate_SuccessfullyAccountsForRegex() { var config = new ItemNameValidationConfig() { Regexs = new RegExConfig[] { new RegExConfig() { Name = "itemEndsWithPage", Pattern = ".*(?<!page)$", }, }, }; var validationService = new ItemNameService(config, null); var result = validationService.Validate("Testpage"); Assert.False(result.IsValid); Assert.Contains(result.Errors, e => e.ErrorType == ValidationErrorType.Regex); Assert.Contains(result.Errors, e => e.ValidatorName == "itemEndsWithPage"); }