Example #1
0
        static int Main(string[] args)
        {
            if (args.Length != 6)
            {
                Usage();
                return(1);
            }

            XmlDocument document = new XmlDocument();

            document.PreserveWhitespace = true;
            document.Load(args[0]);
            XPathNavigator navigator = document.CreateNavigator();


            AddSortKeysToXml.SortKeyGenerator sortKeyGenerator = GetSortKeyGeneratorFromArgument(args[3]);
            string xpathSortKeySource     = args[2];
            string xpathPlaceToPutSortKey = args[4];
            string attribute = args[5];

            AddSortKeysToXml.AddSortKeys(navigator, xpathSortKeySource, sortKeyGenerator, xpathPlaceToPutSortKey, attribute);

            document.Save(args[1]);

            return(0);
        }
Example #2
0
 public void AddSortKeys_XPathSourceEmpty_Throws()
 {
     Assert.Throws <XPathException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            string.Empty,
                                            _sortKeyGenerator,
                                            _xpathElementToPutSortKeyAttributeIn,
                                            _attribute));
 }
Example #3
0
 public void AddSortKeys_AttributeEmpty_Throws()
 {
     Assert.Throws <ArgumentException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            _xpathSortKeySource,
                                            _sortKeyGenerator,
                                            _xpathElementToPutSortKeyAttributeIn,
                                            string.Empty));
 }
Example #4
0
 public void AddSortKeys_XPathSourceNull_Throws()
 {
     Assert.Throws <ArgumentNullException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            null,
                                            _sortKeyGenerator,
                                            _xpathElementToPutSortKeyAttributeIn,
                                            _attribute));
 }
Example #5
0
 public void AddSortKeys_XPathDestinationEmpty_Throws()
 {
     Assert.Throws <XPathException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            _xpathSortKeySource,
                                            _sortKeyGenerator,
                                            string.Empty,
                                            _attribute));
 }
Example #6
0
 public void AddSortKeys_XPathDestinationNull_Throws()
 {
     Assert.Throws <ArgumentNullException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            _xpathSortKeySource,
                                            _sortKeyGenerator,
                                            null,
                                            _attribute));
 }
Example #7
0
 public void AddSortKeys_PrefixInvalidCharacter_Throws()
 {
     Assert.Throws <ArgumentException>(
         () => AddSortKeysToXml.AddSortKeys(_document,
                                            _xpathSortKeySource,
                                            _sortKeyGenerator,
                                            _xpathElementToPutSortKeyAttributeIn,
                                            "1",
                                            _attribute,
                                            _uri));
 }
Example #8
0
        public void AddSortKeys()
        {
            AddSortKeysToXml.AddSortKeys(_document,
                                         _xpathSortKeySource,
                                         _sortKeyGenerator,
                                         _xpathElementToPutSortKeyAttributeIn,
                                         _attribute);

            string expectedXml = "<test>\r\n  <node sort-key=\"1QKG20810400\">z</node>\r\n  <node sort-key=\"1O1020810400\">a</node>\r\n  <node sort-key=\"1O4G20810400\">b</node>\r\n  <node sort-key=\"1Q4G20810400\">q</node>\r\n</test>";

            Assert.AreEqual(NormalizeLineBreaks(expectedXml),
                            NormalizeLineBreaks(_document.OuterXml));
        }
Example #9
0
        public void AddSortKeys_EmptyDocument()
        {
            XmlDocument document = new XmlDocument();

            XPathNavigator navigator = document.CreateNavigator();

            AddSortKeysToXml.AddSortKeys(navigator,
                                         _xpathSortKeySource,
                                         _sortKeyGenerator,
                                         _xpathElementToPutSortKeyAttributeIn,
                                         _attribute);

            Assert.AreEqual(string.Empty, navigator.OuterXml);
        }