public string GetTagNamePart(string tagName, bool isLocalName = false) { if (tagName == null) { return(isLocalName ? throw new ArgumentNullException(nameof(tagName), "Tag Name cannot be null.") : "*"); } if (isLocalName) { _xPathValidator.ValidateNCName(tagName, "Tag Name"); } else { _xPathValidator.ValidateQName(tagName, "Tag Name"); } if (isLocalName) { return($"*[local-name()='{tagName}']"); } if (_xPathValidator.IsReservedFunctionName(tagName)) { return($"*[name()='{tagName}']"); } return(tagName); }
public XPathBuilder_GetAttributePart_Tests() { _xPathValidator = new XPathValidator(); _xPathValidatorMock = Substitute.For <IXPathValidator>(); _xPathValidatorMock.IsReservedFunctionName(Arg.Any <string>()) .Returns(x => _xPathValidator.IsReservedFunctionName(x.Arg <string>())); _xPathValidatorMock.When(x => x.ValidateQName(Arg.Any <string>(), Arg.Any <string>())) .Do(x => _xPathValidator.ValidateQName(x.ArgAt <string>(0), x.ArgAt <string>(1))); _xPathValidatorMock.When(x => x.ValidateNCName(Arg.Any <string>(), Arg.Any <string>())) .Do(x => _xPathValidator.ValidateNCName(x.ArgAt <string>(0), x.ArgAt <string>(1))); _cssValidatorMock = Substitute.For <ICssValidator>(); _builder = new XPathBuilder(_xPathValidatorMock, _cssValidatorMock); }