Example #1
0
            public void ListItemReference_Unset()
            {
                var xml = Xml(
                    "<Foo $x>",
                    "<One x:id='1'> <Value>One</Value> </One>",
                    "<List>",
                    "<Foo x:ref='1'/>",
                    "</List>",
                    "</Foo>"
                    );
                var foo = Create <IFoo>(xml);

                foo.List[0] = Create <IFoo>("<Foo> <Value>Two</Value> </Foo>");

                CustomAssert.AreXmlEquivalent(
                    Xml(
                        "<Foo $x>",
                        "<One> <Value>One</Value> </One>",
                        "<List>",
                        "<Foo> <Value>Two</Value> </Foo>",
                        "</List>",
                        "</Foo>"
                        ),
                    xml
                    );

                Assert.AreEqual(1, foo.List.Count);
                Assert.AreNotSame(foo.One, foo.List[0]);
                Assert.AreEqual("Two", foo.List[0].Value);
            }
Example #2
0
        public void Create()
        {
            var xml    = Xml("<X/>");
            var cursor = Cursor(xml, "A[B='b']/C[D[E][F='f'] and G]/@H", CursorFlags.Multiple);

            Assert.False(cursor.MoveNext());

            cursor.Create(TypeA.ClrType);
            cursor.Value = "h";

            CustomAssert.AreXmlEquivalent(
                string.Concat(
                    "<X>",
                    "<A>",
                    "<C H='h'>",
                    "<D> <E/> <F>f</F> </D>",
                    "<G/>",
                    "</C>",
                    "<B>b</B>",
                    "</A>",
                    "</X>"
                    ),
                xml
                );
        }
            public void Set_Assign_ExternalReference()
            {
                var xml = Xml(
                    "<Foo $x>",
                    "<One x:id='1'> <Value>One</Value> </One>",
                    "</Foo>"
                    );
                var foo = Create <IFoo>(xml);

                foo.Set = new HashSet <IFoo> {
                    foo.One
                };

                CustomAssert.AreXmlEquivalent(Xml(
                                                  "<Foo $x>",
                                                  "<One x:id='1'> <Value>One</Value> </One>",
                                                  "<Set>",
                                                  "<Foo x:ref='1'/>",
                                                  "</Set>",
                                                  "</Foo>"
                                                  ), xml);

                Assert.AreEqual(1, foo.Set.Count);
                CollectionAssert.Contains(foo.Set, foo.One);
            }
Example #4
0
            public void Set()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>(xml);

                foo.Value = "value";

                CustomAssert.AreXmlEquivalent(
                    string.Concat(
                        "<Foo>",
                        "<A>",
                        "<C H='value'>",
                        "<D E=''>",
                        "<F>f</F>",
                        "</D>",
                        "<G/>",
                        "</C>",
                        "<B>b</B>",
                        "</A>",
                        "</Foo>"
                        ),
                    xml
                    );
                Assert.AreEqual("value", foo.Value);
            }
            public void Set_Reference()
            {
                SetValue(Node, "A", null, ValueA, SetResult.ProceedTracked);
                SetValue(Node, "B", null, ValueA, SetResult.Return);

                CustomAssert.AreXmlEquivalent(Xml("<Root $x> <A x:id='1'/> <B x:ref='1'/> <C/> </Root>"), Document);
            }
Example #6
0
        public void AsVirtual_WhenParentIsVirtualNode()
        {
            IXmlNode root,
                     node;
            IXmlCursor cursor;

            root   = Node("<X/>");
            cursor = root.Select(
                Path("Item"),
                IncludedTypes,
                NamespaceSource.Instance,
                CursorFlags.Mutable
                );
            cursor.MoveNext();
            cursor = cursor.Select(
                Path("Other"),
                IncludedTypes,
                NamespaceSource.Instance,
                CursorFlags.Mutable
                );
            cursor.MoveNext();
            node = cursor;

            node.Value = "1";

            CustomAssert.AreXmlEquivalent("<X> <Item><Other>1</Other></Item> </X>", root.Xml);
        }
Example #7
0
            public void ListItemReference_Set()
            {
                var xml = Xml(
                    "<Foo $x>",
                    "<One> <Value>One</Value> </One>",
                    "<List>",
                    "<Foo> <Value>Two</Value> </Foo>",
                    "</List>",
                    "</Foo>"
                    );
                var foo = Create <IFoo>(xml);

                foo.List[0] = foo.One;

                CustomAssert.AreXmlEquivalent(
                    Xml(
                        "<Foo $x>",
                        "<One x:id='1'> <Value>One</Value> </One>",
                        "<List>",
                        "<Foo x:ref='1'/>",
                        "</List>",
                        "</Foo>"
                        ),
                    xml
                    );
            }
            public void Set_Primary_Again_DifferentValue()
            {
                SetValue(Node, "A", null, ValueA, SetResult.ProceedTracked);
                SetValue(Node, "A", ValueA, OtherA, SetResult.ProceedTracked);

                CustomAssert.AreXmlEquivalent(OriginalXml, Document);
            }
            public void Reset_Primary()
            {
                SetValue(Node, "A", null, ValueA, SetResult.ProceedTracked);
                SetValue(Node, "B", null, ValueA, SetResult.Return);
                SetValue(Node, "A", ValueA, OtherA, SetResult.ProceedTracked);

                CustomAssert.AreXmlEquivalent(Xml("<Root $x> <A/> <B C='c'> d <E>f</E> g </B> </Root>"), Document);
            }
Example #10
0
        public void Foo()
        {
            var foo = Create <IA>();

            foo.A = "a";

            CustomAssert.AreXmlEquivalent("<XX xmlns='urn:a'> <A>a</A> </XX>", XmlAdapter.For(foo).Node.Xml);
        }
Example #11
0
        public void Value_OfElement_WhenSet()
        {
            var node = NodeForElement("<X/>");

            node.Value = "a";

            CustomAssert.AreXmlEquivalent("<X>a</X>", node.Xml);
        }
Example #12
0
            public void Delete_Whole()
            {
                var xml = Xml("<Foo>", "<A>", "<B Id='2'> <C>value2</C> </B>", "</A>", "</Foo>");

                Create <IFoo>(xml).A = null;

                CustomAssert.AreXmlEquivalent("<Foo/>", xml);
            }
Example #13
0
        public void IsNil_OfElement_WhenSetToFalse()
        {
            var node = NodeForElement("<X> <Y/> </X>");

            node.IsNil = false;

            CustomAssert.AreXmlEquivalent("<X> <Y/> </X>", node.Xml);
        }
Example #14
0
        public void IsNil_OfElement_WhenValueSet()
        {
            var node = NodeForElement("<X xsi:nil='true' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>");

            node.Value = "V";

            CustomAssert.AreXmlEquivalent("<X>V</X>", node.Xml);
        }
Example #15
0
        public void IsNil_OfElement_WhenSetToTrue()
        {
            var node = NodeForElement("<X> <Y/> </X>");

            node.IsNil = true;

            CustomAssert.AreXmlEquivalent("<X xsi:nil='true' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>", node.Xml);
        }
Example #16
0
            public void Set()
            {
                var xml = Xml("<Foo> <X>x</X> <Y>y</Y> </Foo>");
                var foo = Create <IFoo>(xml);

                foo.A = "*";

                CustomAssert.AreXmlEquivalent("<Foo> <X>x</X> <Y>*</Y> </Foo>", xml);
            }
            public void Set()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>(xml);

                foo.A = "a";

                CustomAssert.AreXmlEquivalent("<Foo> <A>a</A> </Foo>", xml);
            }
Example #18
0
        public void Set()
        {
            var xml = Xml("<Foo/>");
            var foo = Create <IFoo>(xml);

            foo.Strings = Strings;

            CustomAssert.AreXmlEquivalent(StringsXml, xml);
        }
            public void Set_ToArray_Element()
            {
                var xml = Xml("<Root $xsi> <Array xsi:nil='true'/> </Root>");
                var obj = Create <IRoot>(xml);

                obj.Array = new[] { "TestValue" };

                CustomAssert.AreXmlEquivalent(Xml("<Root $xsi> <Array> <string>TestValue</string> </Array> </Root>"), xml);
            }
            public void NondestructiveRead()
            {
                var xml = Xml("<Obj/>");
                var obj = Create <IObj>(xml);

                Assert.True(obj.Foo.Bar.Id == Guid.Empty);

                CustomAssert.AreXmlEquivalent("<Obj/>", xml);
            }
            public void SetProperty_ElementBehavior_String()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>(xml);

                foo.A = "a";

                CustomAssert.AreXmlEquivalent("<Foo> <A>a</A> </Foo>", xml);
            }
            public void Reset_Primary()
            {
                SetValue(Node, "A", null, ValueA, SetResult.ProceedTracked);
                SetValue(Node, "B", null, ValueA, SetResult.Return);
                SetValue(Node, "C", null, ValueA, SetResult.Return);
                SetValue(Node, "A", ValueA, OtherA, SetResult.ProceedTracked);

                CustomAssert.AreXmlEquivalent(Xml("<Root $x> <A/> <B x:id='1'/> <C x:ref='1'/> </Root>"), Document);
            }
            public void SetPropertyOnVirtual()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>(xml);

                foo.A.B = "b";

                CustomAssert.AreXmlEquivalent("<Foo> <A> <B>b</B> </A> </Foo>", xml);
            }
            public void Get_Missing()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>("<Foo/>");

                Assert.NotNull(foo.A);
                Assert.IsEmpty(foo.A);
                CustomAssert.AreXmlEquivalent("<Foo/>", xml);
            }
            public void Get_Attribute()
            {
                var xml = Xml("<Foo A='a'/>");
                var foo = Create <IFoo>(xml);

                Assert.NotNull(foo.A);
                Assert.IsEmpty(foo.A);
                CustomAssert.AreXmlEquivalent("<Foo A='a'/>", xml);
            }
            public void Set()
            {
                var xml = Xml("<Foo/>");
                var foo = Create <IFoo>(xml);

                foo.A = Items;

                CustomAssert.AreXmlEquivalent("<Foo> <A> <int>1</int> <int>2</int> </A> </Foo>", xml);
            }
            public void Set_ToNull_Attribute()
            {
                var xml = Xml("<Root Value='TestValue'/>");
                var obj = Create <IRoot>(xml);

                obj.Value = null;

                CustomAssert.AreXmlEquivalent(Xml("<Root $xsi> <Value xsi:nil='true'/> </Root>"), xml);
            }
            public void Set_ToValue_Element()
            {
                var xml = Xml("<Root $xsi> <Value xsi:nil='true'/> </Root>");
                var obj = Create <IRoot>(xml);

                obj.Value = "TestValue";

                CustomAssert.AreXmlEquivalent(Xml("<Root $xsi> <Value>TestValue</Value> </Root>"), xml);
            }
Example #29
0
            public void Complex_Collection_Assign_InternalReferences()
            {
                var xml = Xml("<Foo $x/>");
                var foo = Create <IFoo>(xml);

                var a = Create <IFoo>();

                a.Value = "a";
                var b = Create <IFoo>();

                b.Value = "b";
                var c = Create <IFoo>();

                c.Value = "c";

                var list = new List <IFoo> {
                    a, b, c
                };

                foreach (var x in list)
                {
                    x.Set = new HashSet <IFoo>(list.Except(Enumerable.Repeat(x, 1)));
                }

                foo.List = list;

                //a  .Set  = new HashSet<IFoo> {    b, c };
                //b  .Set  = new HashSet<IFoo> { a,    c }; // no effect, due to order of operations
                //c  .Set  = new HashSet<IFoo> { a, b    }; // no effect, due to order of operations
                //foo.List = new List   <IFoo> { a, b, c };

                CustomAssert.AreXmlEquivalent(
                    Xml(
                        "<Foo $x>",
                        "<List>",
                        "<Foo>",
                        "<Value>a</Value>",
                        "<Set>",
                        "<Foo x:id='1'> <Value>b</Value> </Foo>",
                        "<Foo x:id='2'> <Value>c</Value> </Foo>",
                        "</Set>",
                        "</Foo>",
                        "<Foo x:ref='1'/>",
                        "<Foo x:ref='2'/>",
                        "</List>",
                        "</Foo>"
                        ),
                    xml
                    );

                Assert.AreEqual(3, foo.List.Count);
                Assert.AreEqual(2, foo.List[0].Set.Count);
                CollectionAssert.Contains(foo.List[0].Set, foo.List[1]);
                CollectionAssert.Contains(foo.List[0].Set, foo.List[2]);
                CollectionAssert.DoesNotContain(foo.List[0].Set, foo);
            }
Example #30
0
            public void Reset_AllButOne()
            {
                SetValue(Node, "A", null, ValueA, SetResult.ProceedTracked);
                SetValue(Node, "B", null, ValueA, SetResult.Return);
                SetValue(Node, "C", null, ValueA, SetResult.Return);
                SetValue(Node, "A", ValueA, OtherA, SetResult.ProceedTracked);
                SetValue(Node, "B", ValueA, OtherB, SetResult.ProceedTracked);

                CustomAssert.AreXmlEquivalent(OriginalXml, Document);
            }