// ReSharper disable UnusedParameter.Local void Verify_Check(bool isValid, params string[] values) // ReSharper restore UnusedParameter.Local { //------------Setup for test-------------------------- const char SplitToken = ','; Func<string> getValue = () => string.Join(SplitToken.ToString(CultureInfo.InvariantCulture), values); var rule = new IsValidFileNameRule(getValue, SplitToken) { LabelText = "The item" }; //------------Execute Test--------------------------- var result = rule.Check(); //------------Assert Results------------------------- if(isValid) { Assert.IsNull(result); } else { StringAssert.Contains("The item contains an invalid file name", result.Message); } }
protected virtual string ValidatePath(string label, string path, Action onError, bool pathIsRequired) { if (!pathIsRequired && string.IsNullOrWhiteSpace(path)) { return string.Empty; } var errors = new List<IActionableErrorInfo>(); RuleSet fileActivityRuleSet = new RuleSet(); IsValidExpressionRule isValidExpressionRule = new IsValidExpressionRule(() => path, DataListSingleton.ActiveDataList.Resource.DataList); fileActivityRuleSet.Add(isValidExpressionRule); errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError)); string pathValue; path.TryParseVariables(out pathValue, onError, variableValue: ValidUriSchemes[0] + "://temp"); if (errors.Count == 0) { IsStringEmptyOrWhiteSpaceRule isStringEmptyOrWhiteSpaceRuleUserName = new IsStringEmptyOrWhiteSpaceRule(() => path) { LabelText = label, DoError = onError }; IsValidFileNameRule isValidFileNameRule = new IsValidFileNameRule(() => path) { LabelText = label, DoError = onError }; fileActivityRuleSet.Add(isStringEmptyOrWhiteSpaceRuleUserName); fileActivityRuleSet.Add(isValidExpressionRule); errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError)); } UpdateErrors(errors); return pathValue; }