Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }