public void InsertElement_PatchGenerator_Accepts_MultipleInserts() { var sourceXml = XDocument.Parse("<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>"); var replaces = new BasePatch[] { new PatchInstead("/sitecore/sites", "site[@name='a']", new XElement("site", new XAttribute("name", "1"))), new PatchInstead("/sitecore/sites", "site[@name='b']", new XElement("site", new XAttribute("name", "2"))) }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(replaces); var roots = result.XPathSelectElements("/configuration/sitecore/sites"); Assert.AreEqual(1, roots.Count()); var patches = result.XPathSelectElements("/configuration/sitecore/sites/site"); Assert.IsNotNull(patches); Assert.AreEqual(2, patches.Count()); var first = patches.ElementAt(0).Attribute("name"); Assert.AreEqual("1", first.Value); var second = patches.ElementAt(1).Attribute("name"); Assert.AreEqual("2", second.Value); }
public void PatchNewChild_PatchGenerator_Accepts_Insert() { var ins = new PatchNewChild("/sitecore/sites", new XElement("site", new XAttribute("name", "c"))); var xml = XDocument.Parse("<sitecore><sites/></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { ins }); var sites = result .Element("configuration") .Element("sitecore") .Element("sites") .Elements("site"); Assert.AreEqual(1, sites.Count()); var newSite = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site"); Assert.IsNotNull(newSite); Assert.AreEqual("c", newSite.Attribute("name").Value); }
public void PatchNewChild_ParentWithMultipleInstancesOfTargetNode_CausesAttributeCopy() { var xml = XDocument.Parse("<sitecore><node name=\"1\"/><node name=\"2\"/></sitecore>"); var ins1 = new PatchNewChild("/sitecore/node[@name='1']", new XElement("xml")); var ins2 = new PatchNewChild("/sitecore/node[@name='2']", new XElement("abc")); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { ins1, ins2 }); var nodes = result .Element("configuration") .Element("sitecore") .Elements("node"); Assert.AreEqual(2, nodes.Count()); var node1 = nodes.ElementAt(0); Assert.AreEqual("node", node1.Name.LocalName); Assert.AreEqual(1, node1.Attributes().Count()); Assert.AreEqual("1", node1.Attribute("name").Value); Assert.IsNotNull(node1.Element("xml")); var node2 = nodes.ElementAt(1); Assert.AreEqual("node", node2.Name.LocalName); Assert.AreEqual(1, node2.Attributes().Count()); Assert.AreEqual("2", node2.Attribute("name").Value); Assert.IsNotNull(node2.Element("abc")); }
public void InsertElement_PatchGenerator_Accepts_Insert() { var ins = new PatchInstead("/sitecore/sites", "site[@name='a']", new XElement("site", new XAttribute("name", "c"))); var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { ins }); var sites = result .Element("configuration") .Element("sitecore") .Element("sites") .Elements("site"); Assert.AreEqual(1, sites.Count()); var newSite = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site"); Assert.IsNotNull(newSite); Assert.AreEqual("c", newSite.Attribute("name").Value); Assert.IsNotNull(newSite.Attribute(Namespaces.Patch + "instead")); }
public void PatchAttribute_PatchGenerator_Accepts_MultiplePatchAttribute_OnSameElement() { var patches = new BasePatch[] { new PatchAttribute("/sitecore/sites/site[@name='a']", "cheese", "1"), new PatchAttribute("/sitecore/sites/site[@name='a']", "biscuits", "2") }; var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(patches); var el = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site"); Assert.IsNotNull(el); var patch1 = el.Elements().ElementAt(0); Assert.IsNotNull(patch1); Assert.AreEqual("cheese", patch1.Attribute("name").Value); Assert.AreEqual("1", patch1.Attribute("value").Value); var patch2 = el.Elements().ElementAt(1); Assert.IsNotNull(patch2); Assert.AreEqual("biscuits", patch2.Attribute("name").Value); Assert.AreEqual("2", patch2.Attribute("value").Value); }
private void DoMake() { string patch_ext = VFSConst.Patch_File_Extension; if (patch_ext.StartsWith(".")) { patch_ext = patch_ext.Substring(1, patch_ext.Length - 1); } string current_project_dir = Directory.GetCurrentDirectory(); string save_dir = EditorPrefs.GetString("TINAX_VFS_PATCH_OUTPUT_DIR_CACHE", current_project_dir); string save_path = EditorUtility.SaveFilePanel( IsChinese ? "保存补丁位置" : "Save Patch Path", save_dir, $"{wnd_param.current_version}", patch_ext); if (save_path.IsNullOrEmpty()) { return; } if (!Directory.Exists(Path.GetDirectoryName(save_path))) { Debug.LogError("Folder Not Found:" + Path.GetDirectoryName(save_path)); return; } EditorPrefs.SetString("TINAX_VFS_PATCH_OUTPUT_DIR_CACHE", Path.GetDirectoryName(save_path)); var patchgen = new PatchGenerator(); patchgen.MakePatchFromVersionLibrary(wnd_param.branchName, wnd_param.current_version, select_version.Value, save_path); }
public void SetAttribute_PatchGenerator_Accepts_MultipleSetAttribute_OnDifferentElements() { var sets = new BasePatch[] { new SetAttribute("/sitecore/sites/site[@name='a']", "cheese", "1"), new SetAttribute("/sitecore/sites/site[@name='b']", "cheese", "2") }; var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(sets); var patches = result .Element("configuration") .Element("sitecore") .Element("sites") .Elements("site"); Assert.IsNotNull(patches); Assert.AreEqual(2, patches.Count()); var patch1 = patches.ElementAt(0); var attr1 = patch1.Attribute(Namespaces.Set + "cheese"); Assert.IsNotNull(attr1); Assert.AreEqual("1", attr1.Value); var patch2 = patches.ElementAt(1); var attr2 = patch2.Attribute(Namespaces.Set + "cheese"); Assert.IsNotNull(attr2); Assert.AreEqual("2", attr2.Value); }
public PatchGenerationForm(ListBox patchListView, XDocument sourceXml, string sourceFileName) { InitializeComponent(); this.ConfigureDialog(); if (!File.Exists("Sitecore.Kernel.dll")) { previewBtn.Enabled = false; } if (patchListView == null) { throw new ArgumentNullException(nameof(patchListView)); } _sourceXml = sourceXml ?? throw new ArgumentNullException(nameof(sourceXml)); _sourceFileName = sourceFileName; _patches = extractPatches(patchListView); var generator = new PatchGenerator(_sourceXml); _patch = generator.GeneratePatchFile(_patches); patchXmlEdit.Text = _patch.ToString(); // Generating a preview for a patch with errors can crash the Sitecore patch engine // So we prevent that to avoid the confusing UI generated if (patchXmlEdit.Text.Contains("<!--ERROR:")) { previewBtn.Enabled = false; } patchXmlEdit.Select(0, 0); }
// Use this for initialization void Start() { PatchGenerator gen = this.GetComponent <PatchGenerator> (); GameObject p = gen.NextPatch(); p.SetActive(true); }
public void PatchGenerator_GeneratePatchFile_NullPatches_Throws() { var source = XDocument.Parse("<sites/>"); var sut = new PatchGenerator(source); sut.GeneratePatchFile(null); }
public void PatchGenerator_GeneratePatchFile_EmptyPatches_GivesADocument() { var source = XDocument.Parse("<sites/>"); var sut = new PatchGenerator(source); XDocument result = sut.GeneratePatchFile(new BasePatch[] { }); Assert.IsNotNull(result); }
internal static extern void CvPlanarObjectDetectorTrain( IntPtr objectDetector, IntPtr image, int npoints, int patchSize, int nstructs, int structSize, int nviews, ref LDetector keyPointDetector, ref PatchGenerator patchGenerator);
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); } }
public void SetAttribute_InvalidXPath_Throws() { var patches = new BasePatch[] { new SetAttribute("/sitecore/sites/site[@name='b'", "cheese", "1"), }; var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(patches); }
public void PatchGenerator_GeneratePatchFile_NoPatches_GivesEmptyOutput() { var source = XDocument.Parse("<sites/>"); var sut = new PatchGenerator(source); var result = sut.GeneratePatchFile(new BasePatch[] { }); Assert.AreEqual("configuration", result.Root.Name); Assert.AreEqual(string.Empty, result.Root.Value); }
public void PatchDelete_InvalidXPath_Throws() { var sourceXmlText = "<sitecore><sites><site name=\"a\"/></sites></sitecore>"; var sourceXml = XDocument.Parse(sourceXmlText); var deletes = new BasePatch[] { new PatchDelete("/sitecore/sites/site[@name='z'"), }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(deletes); }
public void InserElement_InvalidXPath_Throws() { var sourceXmlText = "<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>"; var sourceXml = XDocument.Parse(sourceXmlText); var inserts = new BasePatch[] { new PatchInsert("/sitecore/xsites[", ElementInsertPosition.Before, "site[@name='b']", new XElement("site", new XAttribute("name", "before"))) }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(inserts).ToString(); }
public void SetAttribute_XPathMatchingNothing_AddsComment() { var patches = new BasePatch[] { new SetAttribute("/sitecore/sites/site[@name='b']", "cheese", "1"), }; var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(patches); Assert.IsTrue(result.ToString().Contains("<!--ERROR:")); }
public void InserElement_InvalidXPath_Throws() { var sourceXmlText = "<sitecore><sites><site name=\"a\"/></sites></sitecore>"; var sourceXml = XDocument.Parse(sourceXmlText); var replaces = new BasePatch[] { new PatchInstead("/sitecore/zsites[", "site[@name='b']", new XElement("site", new XAttribute("name", "2"))) }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(replaces).ToString(); }
public void InserElement_XPathMatchingNothing_AddsComment() { var sourceXmlText = "<sitecore><sites><site name=\"a\"/></sites></sitecore>"; var sourceXml = XDocument.Parse(sourceXmlText); var replaces = new BasePatch[] { new PatchInstead("/sitecore/zsites", "site[@name='b']", new XElement("site", new XAttribute("name", "2"))) }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(replaces).ToString(); Assert.IsTrue(result.ToString().Contains("<!--ERROR:")); }
public void InserElement_XPathMatchingNothing_AddsComment() { var sourceXmlText = "<sitecore><sites><site name=\"a\"/></sites></sitecore>"; var sourceXml = XDocument.Parse(sourceXmlText); var deletes = new BasePatch[] { new PatchDelete("/sitecore/sites/sitae[@name='z']"), }; var sut = new PatchGenerator(sourceXml); var result = sut.GeneratePatchFile(deletes); Assert.IsTrue(result.ToString().Contains("<!--ERROR:")); }
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); }
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); }
public void PatchDelete_PatchGenerator_Accepts_Delete() { var de = new PatchDelete("/sitecore/sites/site[@name='a']"); var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/><site name=\"b\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { de }); var patch = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site") .Element(Namespaces.Patch + "delete"); Assert.IsNotNull(patch); }
public void PatchGenerator_GeneratePatchFile_AddsPatchingNamespacesToRoot() { var source = XDocument.Parse("<sites/>"); var sut = new PatchGenerator(source); var result = sut.GeneratePatchFile(new BasePatch[] { }); var patchNS = result.Root.Attribute(XNamespace.Xmlns + "patch"); Assert.IsNotNull(patchNS); Assert.AreEqual("http://www.sitecore.net/xmlconfig/", patchNS.Value); var setNS = result.Root.Attribute(XNamespace.Xmlns + "set"); Assert.IsNotNull(setNS); Assert.AreEqual("http://www.sitecore.net/xmlconfig/set/", setNS.Value); }
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); }
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); }
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); }
public void SetAttribute_PatchGenerator_Accepts_SetAttribute() { var sa = new SetAttribute("/sitecore/sites/site[@name='a']", "cheese", "1"); var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { sa }); var patch = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site"); Assert.IsNotNull(patch); var attr = patch.Attribute(Namespaces.Set + "cheese"); Assert.IsNotNull(attr); Assert.AreEqual("1", attr.Value); }
public void SetAttribute_PatchGenerator_Accepts_MultipleSetAttribute_OnSameElement() { var sets = new BasePatch[] { new SetAttribute("/sitecore/sites/site[@name='a']", "cheese", "1"), new SetAttribute("/sitecore/sites/site[@name='a']", "biscuits", "2") }; var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(sets); var patches = result .Element("configuration") .Element("sitecore") .Element("sites") .Elements("site"); Assert.IsNotNull(patches); Assert.AreEqual(1, patches.Count()); var patch = patches.First(); var attr1 = patch.Attribute(Namespaces.Set + "cheese"); Assert.IsNotNull(attr1); Assert.AreEqual("1", attr1.Value); var attr2 = patch.Attribute(Namespaces.Set + "biscuits"); Assert.IsNotNull(attr2); Assert.AreEqual("2", attr2.Value); var originalAttr = patch.Attribute("name"); Assert.IsNotNull(originalAttr); Assert.AreEqual("a", originalAttr.Value); }
public void PatchAttribute_PatchGenerator_Accepts_PatchAttribute() { var pa = new PatchAttribute("/sitecore/sites/site[@name='a']", "cheese", "1"); var xml = XDocument.Parse("<sitecore><sites><site name=\"a\"/></sites></sitecore>"); var sut = new PatchGenerator(xml); var result = sut.GeneratePatchFile(new BasePatch[] { pa }); var el = result .Element("configuration") .Element("sitecore") .Element("sites") .Element("site"); Assert.IsNotNull(el); var patch = el.Element(Namespaces.Patch + "attribute"); Assert.IsNotNull(patch); Assert.AreEqual("cheese", patch.Attribute("name").Value); Assert.AreEqual("1", patch.Attribute("value").Value); }