Ejemplo n.º 1
0
        public void FxElementTest_Three()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(@"<Parent><X>old value</X></Parent>");
            var context = InitContext <MyClass>(string.Format(typeFrameXml, multiFrameworkXml), 2, forceAlignment: false);

            var fx = context.fx.Frameworks[1];
            FrameworkTypeEntry typeEntry = fx.Types.First();

            XmlElement parentx = doc.DocumentElement;

            System.Func <FrameworkTypeEntry, bool> runfx = (te) =>
            {
                DocUtils.AddElementWithFx(
                    te,
                    parentx,
                    isFirst: typeEntry.Framework.IsFirstFrameworkForType(typeEntry),
                    isLast: typeEntry.Framework.IsLastFrameworkForType(typeEntry),
                    allfxstring: new Lazy <string>(() => typeEntry.Framework.AllFrameworksWithType(typeEntry)),
                    clear: parent =>
                {
                    parent.RemoveAll();
                },
                    findExisting: parent =>
                {
                    return(parent.SelectSingleNode("X") as XmlElement);
                },
                    addItem: parent =>
                {
                    var item       = parent.OwnerDocument.CreateElement("X");
                    item.InnerText = "value";
                    parent.AppendChild(item);
                    return(item);
                });
                return(true);
            };

            runfx(context.fx.Frameworks[0].Types.First());
            runfx(context.fx.Frameworks[1].Types.First());
            runfx(context.fx.Frameworks[2].Types.First());

            Assert.AreEqual(parentx.ChildNodes.Count, 1);
        }
Ejemplo n.º 2
0
        public void FxElementTest_Two()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(@"<Parent><X>old value</X></Parent>");
            var context = InitContext <MyClass>(string.Format(typeFrameXml, multiFrameworkXml), 0, forceAlignment: false);

            var fx = context.fx.Frameworks[1];
            FrameworkTypeEntry typeEntry = fx.Types.First();

            XmlElement parentx = doc.DocumentElement;

            System.Func <FrameworkTypeEntry, string, bool> runfx = (te, value) =>
            {
                DocUtils.AddElementWithFx(
                    te,
                    parentx,
                    isFirst: te.Framework.IsFirstFrameworkForType(te),
                    isLast: te.Framework.IsLastFrameworkForType(te),
                    allfxstring: new Lazy <string>(() => typeEntry.Framework.AllFrameworksWithType(typeEntry)),
                    clear: parent =>
                {
                    parent.RemoveAll();
                },
                    findExisting: parent =>
                {
                    return(parent.ChildNodes.Cast <XmlElement>().SingleOrDefault(e => e.Name == "X" && e.Value == value));
                },
                    addItem: parent =>
                {
                    var item       = parent.OwnerDocument.CreateElement("X");
                    item.InnerText = value;
                    parent.AppendChild(item);
                    return(item);
                });
                return(true);
            };

            runfx(context.fx.Frameworks[0].Types.First(), "one");
            runfx(context.fx.Frameworks[1].Types.First(), "two");

            Assert.AreEqual(parentx.ChildNodes.Count, 2);
            Assert.IsTrue(parentx.ChildNodes.Cast <XmlElement>().Any(e => e.HasAttribute(Consts.FrameworkAlternate)), "fx check");
        }
Ejemplo n.º 3
0
        public void FxElementTest()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(@"<Parent><X>old value</X></Parent>");
            var context = InitContext <MyClass>(string.Format(typeFrameXml, multiFrameworkXml), 0, forceAlignment: false);

            var fx = context.fx.Frameworks[0];
            FrameworkTypeEntry typeEntry = fx.Types.First();

            XmlElement parentx = doc.DocumentElement;


            DocUtils.AddElementWithFx(
                typeEntry,
                parentx,
                clear: parent =>
            {
                parent.RemoveAll();
            },
                findExisting: parent =>
            {
                return(parent.SelectSingleNode("X") as XmlElement);
            },
                addItem: parent =>
            {
                var item       = parent.OwnerDocument.CreateElement("X");
                item.InnerText = "value";
                parent.AppendChild(item);
                return(item);
            });

            Assert.AreEqual(1, parentx.ChildNodes.Count);
            Assert.AreEqual("value", parentx.ChildNodes[0].InnerText);
            Assert.AreEqual("One", parentx.ChildNodes[0].Attributes[0].Value);
        }