private string BuildNodePath(XPathNavigator navigator, XPathFormat format)
        {
            switch (format)
            {
            case XPathFormat.Name:
                return(navigator.Name);

            case XPathFormat.LocalName:
                var builder = new StringBuilder("*[");
                builder.Append($"{XpathFunctionNames.LOCAL_NAME}()='{navigator.LocalName}'");
                if (!string.IsNullOrWhiteSpace(navigator.NamespaceURI))
                {
                    builder.AppendFormat(" and namespace-uri()='{0}'", navigator.NamespaceURI);
                }
                var discriminants = navigator.GetDiscriminants().ToArray();
                if (discriminants.Any())
                {
                    builder.AppendFormat(" and ({0})", BuildDiscriminantsSelector(navigator, discriminants));
                }
                builder.Append("]");
                return(builder.ToString());

            default:
                throw new ArgumentOutOfRangeException(nameof(format), format, null);
            }
        }
Beispiel #2
0
        public void CanCreateXPathWriter(XPathFormat format, Type expectedXPathWriterType)
        {
            // Arrange
            var configuration = Substitute.For <IConfiguration>();
            var factory       = new XPathWriterFactory(() => configuration);

            // Act
            var writer = factory.CreateForXPathFormat(format);

            // Assert
            Assert.That(writer, Is.Not.Null.And.TypeOf(expectedXPathWriterType));
        }
Beispiel #3
0
        public void StatusbarXPathFormatChangesWhenConfigurationIsChanged(XPathFormat xpathFormat, string expectedXPath)
        {
            // Arrange
            var configuration = new XPathToolsDialogPageAutomationModel(_visualStudio);

            // Act
            configuration.SetStatusbarXPathFormat(xpathFormat);
            SendKeys.SendWait("{LEFT}{RIGHT}"); // Move the caret to trigger a statusbar update

            // Assert
            var statusbar = new StatusbarAutomationModel(_visualStudio.MainWindow);

            Assert.That(statusbar.GetText(), Is.EqualTo(expectedXPath));
        }
Beispiel #4
0
        public void SetStatusbarXPathFormat(XPathFormat format)
        {
            // Ensure options dialog is closed before starting interaction sequence
            Close();

            // Open the XPath options dialog page
            Open();

            // Move to the last setting - this assumes that the XPath Tools settings page has focus and has 6 settings
            SendKeys.SendWait("{DOWN 6}");

            // Select the desired format - requires all formats to start with a different letter!
            var firstLetter = format.ToString()[0].ToString();

            SendKeys.SendWait(firstLetter);

            Close();
        }
 public IWriter CreateForXPathFormat(XPathFormat format)
 {
     return(CreateForCommandId((int)format));
 }
 public string BuildCurrentNodePath(XPathFormat format = XPathFormat.LocalName)
 {
     return(BuildNodePath(_navigator, format));
 }
        public string BuildAbsolutePath(XPathFormat format = XPathFormat.LocalName)
        {
            var hierarchy = BuildHierarchy(_navigator);

            return($"/{string.Join("/", hierarchy.Select(navigator => BuildNodePath(navigator, format)))}");
        }