示例#1
0
        public void ObjectFlattenTest()
        {
            var          o         = new ForAttributeTest();
            PropertyInfo info      = o.GetType().GetProperty("Users");
            Attribute    attribute = info.GetCustomAttribute(typeof(ListFlattenerAttribute));

            Assert.IsTrue(attribute.GetType() == typeof(ListFlattenerAttribute));
            Assert.AreEqual("Users", ((ListFlattenerAttribute)attribute).PropertyName);

            XmlNode node = ((ListFlattenerAttribute)attribute).Flatten(info.GetValue(o), info.PropertyType);

            Assert.IsNotNull(node);

            if (node.ChildNodes != null && node.ChildNodes.Count == 4)
            {
                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    Assert.AreEqual(o.Users[i].Discriminator.ToString(), node.ChildNodes[i].SelectSingleNode(".//Discriminator").InnerText);
                    Assert.AreEqual(o.Users[i].Tag, node.ChildNodes[i].SelectSingleNode(".//Tag").InnerText);
                    Assert.AreEqual(o.Users[i].Name, node.ChildNodes[i].SelectSingleNode(".//Name").InnerText);
                }
            }
            else
            {
                throw new AssertFailedException("Object not properly flattened. Expected 4 child elements");
            }
        }
示例#2
0
        public void PrimitiveFlattenTest()
        {
            var          o         = new ForAttributeTest();
            PropertyInfo info      = o.GetType().GetProperty("Items");
            Attribute    attribute = info.GetCustomAttribute(typeof(ListFlattenerAttribute));

            Assert.IsTrue(attribute.GetType() == typeof(ListFlattenerAttribute));
            Assert.AreEqual("Items", ((ListFlattenerAttribute)attribute).PropertyName);

            var  value    = info.GetValue(o);
            Type propType = info.PropertyType;

            XmlNode node = ((ListFlattenerAttribute)attribute).Flatten(value, propType);

            if (node.ChildNodes != null && node.ChildNodes.Count == 4)
            {
                for (int i = 0; i < node.ChildNodes.Count; i++)
                {
                    Assert.AreEqual((i + 1).ToString(), node.ChildNodes[i].InnerText);
                }
            }
            else
            {
                throw new AssertFailedException("Object not properly flattened. Expected 4 child elements");
            }
        }