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);
        }
Beispiel #2
0
        public void then_creating_xpath_tag_with_reserved_name()
        {
            _xPathValidator.IsReservedFunctionName("reserved:Name").Returns(true);

            var result = _builder.GetTagNamePart("reserved:Name");

            result.ShouldBe("*[name()='reserved:Name']");

            _xPathValidator.Received(1).ValidateQName("reserved:Name", "Tag Name");
            _xPathValidator.DidNotReceiveWithAnyArgs().ValidateNCName(Arg.Any <string>(), Arg.Any <string>());
            _xPathValidator.Received(1).IsReservedFunctionName("reserved:Name");

            _cssValidator.DidNotReceiveWithAnyArgs().ValidateClassName(Arg.Any <string>());
        }
        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);
        }