Exemple #1
0
        public void CanSerialise()
        {
            var subject = new PatchDataLoader();

            var doc1 = new XmlDocument();
            var node = doc1.AppendChild(doc1.CreateNode(XmlNodeType.Element, "Data", ""));
            node.AppendChild(doc1.CreateNode(XmlNodeType.Element, "aha", "NSaha"));

            var doc2 = new XmlDocument();
            node = doc2.AppendChild(doc2.CreateNode(XmlNodeType.Element, "Data", ""));
            node.AppendChild(doc2.CreateNode(XmlNodeType.Element, "oho","NSoho"));

            var testDefinition = new PatchDefinition()
                                     {
                                         Category = PatchCategory.Enhancement,
                                         UIPatches = new List<UIPatch>
                                                         {
                                                             new UIPatch()
                                                                 {
                                                                     PatchMode = UIPatchMode.Replace,
                                                                     Data = doc1,
                                                                     FilePath = "assetpath/subdir/target.xml",
                                                                     XPath = "//aha[@id='bla'"
                                                                 },
                                                             new UIPatch()
                                                                 {
                                                                     PatchMode = UIPatchMode.Replace,
                                                                     Data = doc2,
                                                                     FilePath = "assetpath/dir2/targets.xml",
                                                                     XPath = "//oha[@id='bl'"
                                                                 },

                                                         }
                                     };

            var targetPath = Path.Combine(Directory.GetCurrentDirectory(),  "filee.xml");

            var patches = new PatchData()
                              {
                                  Definitions = new List<PatchDefinition>()
                                                    {
                                                        testDefinition
                                                    }
                              };

            subject.SaveData(patches, targetPath);

            Assert.IsTrue(File.Exists(targetPath));

            string contents = "";
            using (var stringReader = new StreamReader(targetPath))
            {
                contents = stringReader.ReadToEnd();
            }

            Assert.IsTrue(contents.Contains("NSaha"));
            Assert.IsTrue(contents.Contains("NSoho"));
        }