Example #1
0
        public PatchPreviewForm(string sourceXml, string patchXml, Dictionary <string, string> roles)
        {
            InitializeComponent();
            this.ConfigureDialog();

            renderRoles(rolesLabel, roles);

            var result = SitecorePatcher.ApplyWithRoles(sourceXml, patchXml, "preview.patch.config", roles);

            var xml = XDocument.Parse(result);

            richTextBox.Text = xml.ToString();

            foreach (var line in richTextBox.Lines)
            {
                if (line.Contains("preview.patch.config"))
                {
                    int idx = richTextBox.Find(line);
                    richTextBox.Select(idx, line.Length);
                    richTextBox.SelectionColor = Color.Red;
                }
            }

            richTextBox.Select(0, 0);
        }
Example #2
0
        public void IntegrationTest_MultiPatchOnSitecoreConfig_GivesRightAnswers()
        {
            var xml = System.IO.File.ReadAllText(@"..\..\ExampleXml\Sitecore.config");

            var sitecoreConfig = XDocument.Parse(xml);

            var newSite = new XElement("site",
                                       new XAttribute("inherits", "site1"),
                                       new XAttribute("name", "new"),
                                       new XAttribute("hostName", "www.test.com")
                                       );

            var newDataFolder = new XElement("sc.variable",
                                             new XAttribute("name", "dataFolder"),
                                             new XAttribute("value", "/sitedata")
                                             );

            var patches = new BasePatch[] {
                new PatchInsert("/sitecore/sites", ElementInsertPosition.After, "site[@name='website']", newSite),
                new SetAttribute("/sitecore/mediaLibrary/mediaPrefixes/prefix[@value='~/media']", "value", "~/art"),
                new PatchInstead("/sitecore", "sc.variable[@name='dataFolder']", newDataFolder),
                new PatchDelete("/sitecore/tracking/untrackedPages/add[@path='/sitecore/default.aspx']")
            };

            var sut = new PatchGenerator(sitecoreConfig);

            var patchData = sut.GeneratePatchFile(patches);

            var newXml = SitecorePatcher.ApplyWithoutRoles(xml, patchData.ToString(), "testpatch.config");


            var newXDoc = XDocument.Parse(newXml);

            var patchedSite = newXDoc.XPathSelectElement("/sitecore/sites/site[@name='new']");

            Assert.IsNotNull(patchedSite);
            Assert.AreEqual("site1", patchedSite.Attribute("inherits").Value);

            var patchedMediaPrefix = newXDoc.XPathSelectElement("/sitecore/mediaLibrary/mediaPrefixes/prefix");

            Assert.IsNotNull(patchedMediaPrefix);
            Assert.AreEqual("~/art", patchedMediaPrefix.Attribute("value").Value);

            var patchedVariable = newXDoc.XPathSelectElement("/sitecore/sc.variable[@name='dataFolder']");

            Assert.IsNotNull(patchedVariable);
            Assert.AreEqual("/sitedata", patchedVariable.Attribute("value").Value);

            var patchedPages = newXDoc.XPathSelectElements("/sitecore/tracking/untrackedPages/add");

            foreach (var patchedPage in patchedPages)
            {
                Assert.AreNotEqual("/sitecore/default.aspx']", patchedPage.Attribute("path").Value);
            }
        }
Example #3
0
        public void InserElement_GivesCorrectResult_ComparedToSitecore()
        {
            var sourceXmlText = "<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>";
            var sourceXml     = XDocument.Parse(sourceXmlText);

            var replaces = new BasePatch[] {
                new PatchInstead("/sitecore/sites", "site[@name='b']", new XElement("site", new XAttribute("name", "2"))),
                new PatchInstead("/sitecore/sites", "site[@name='a']", new XElement("site", new XAttribute("name", "1")))
            };

            var sut = new PatchGenerator(sourceXml);

            var patchXmlText = sut.GeneratePatchFile(replaces).ToString();

            var resultXmlText = SitecorePatcher.ApplyWithoutRoles(sourceXmlText, patchXmlText);

            Assert.AreEqual("<sitecore><sites><site name=\"1\" /><site name=\"2\" /></sites></sitecore>", resultXmlText);
        }
Example #4
0
        public void SetAttribute_GivesCorrectResult_ComparedToSitecore()
        {
            var sourceXmlText = "<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>";
            var sourceXml     = XDocument.Parse(sourceXmlText);

            var sets = new BasePatch[] {
                new SetAttribute("/sitecore/sites/site[@name='a']", "fish", "trout"),
                new SetAttribute("/sitecore/sites/site[@name='b']", "insect", "spider")
            };

            var sut = new PatchGenerator(sourceXml);

            var patchXmlText = sut.GeneratePatchFile(sets).ToString();

            var resultXmlText = SitecorePatcher.ApplyWithoutRoles(sourceXmlText, patchXmlText);

            Assert.AreEqual("<sitecore><sites><site name=\"a\" fish=\"trout\" /><site name=\"b\" insect=\"spider\" /></sites></sitecore>", resultXmlText);
        }
Example #5
0
        public void PatchDelete_GivesCorrectResult_ComparedToSitecore()
        {
            var sourceXmlText = "<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>";
            var sourceXml     = XDocument.Parse(sourceXmlText);

            var deletes = new BasePatch[] {
                new PatchDelete("/sitecore/sites/site[@name='a']"),
                new PatchDelete("/sitecore/sites/site[@name='b']")
            };

            var sut = new PatchGenerator(sourceXml);

            var patchXmlText = sut.GeneratePatchFile(deletes).ToString();

            var resultXmlText = SitecorePatcher.ApplyWithoutRoles(sourceXmlText, patchXmlText);

            Assert.AreEqual("<sitecore><sites></sites></sitecore>", resultXmlText);
        }
Example #6
0
        public void InserElement_GivesCorrectResult_ComparedToSitecore()
        {
            var sourceXmlText = "<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>";
            var sourceXml     = XDocument.Parse(sourceXmlText);

            var inserts = new BasePatch[] {
                new PatchInsert("/sitecore/sites", ElementInsertPosition.Before, "site[@name='b']", new XElement("site", new XAttribute("name", "before"))),
                new PatchInsert("/sitecore/sites", ElementInsertPosition.After, "site[@name='b']", new XElement("site", new XAttribute("name", "after")))
            };

            var sut = new PatchGenerator(sourceXml);

            var patchXmlText = sut.GeneratePatchFile(inserts).ToString();

            var resultXmlText = SitecorePatcher.ApplyWithoutRoles(sourceXmlText, patchXmlText);

            Assert.AreEqual("<sitecore><sites><site name=\"a\" /><site name=\"before\" /><site name=\"b\" /><site name=\"after\" /></sites></sitecore>", resultXmlText);
        }
Example #7
0
        public void IntegrationTest_RoleNamespace_IsHandledCorrectly()
        {
            var xml = System.IO.File.ReadAllText(@"..\..\ExampleXml\role-namespace.config");

            var sitecoreConfig = XDocument.Parse(xml);

            var patches = new BasePatch[] {
                new SetAttribute("/sitecore/sc.variable[@name='mediaFolder' and @role:require='Standalone']", "value", "~/StandAloneData"),
            };

            var sut = new PatchGenerator(sitecoreConfig);

            var patchData = sut.GeneratePatchFile(patches);

            var patchElement = patchData
                               .Element("configuration")
                               .Element("sitecore")
                               .Element("sc.variable");

            Assert.IsNotNull(patchElement);
            Assert.AreEqual(4, patchElement.Attributes().Count());
            Assert.AreEqual("mediaFolder", patchElement.Attribute("name").Value);

            var roles = new Dictionary <string, string>()
            {
                { "role", "Standalone" }
            };

            var newXml = SitecorePatcher.ApplyWithRoles(xml, patchData.ToString(), "testpatch.config", roles);

            Assert.IsFalse(string.IsNullOrWhiteSpace(newXml));

            var newXDoc = XDocument.Parse(newXml);

            var newElement = newXDoc.XPathSelectElement("/sitecore/sc.variable[@name='mediaFolder']");

            Assert.IsNotNull(newElement);
            Assert.AreEqual(3, newElement.Attributes().Count());
            Assert.AreEqual("~/StandAloneData", newElement.Attribute("value").Value);
        }