public void Returned_NodeData_Contains_Correct_NodeType()
        {
            var converter = new XomDataConverter();
            var xmlObject = new NodeA();

            var nodeData = converter.ConvertToXomNodeData(xmlObject, _xomReader);
            Assert.AreEqual(NodeA.XomNode, nodeData.NodeType, "Resulting NodeType was incorrect");
        }
        public void Can_Convert_Simple_Xml_Object_To_XomNodeData()
        {
            var converter = new XomDataConverter();
            var xmlObject = new NodeA();

            var nodeData = converter.ConvertToXomNodeData(xmlObject, _xomReader);
            Assert.IsNotNull(nodeData, "Returned node data object was null");
        }
        public void Can_Set_Nullable_Attribute_Source_To_Non_Nullable_Target()
        {
            const int testValue = 5;
            var serializer = new XomDataConverter();
            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                AttributeData = new { Attribute3 = (int?)testValue }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
            Assert.AreEqual(testValue, result.Attribute3, "Attribute3 had an incorrect value");
        }
        public void Can_Create_Child_Node_With_Name_Not_Matching_Property_Name()
        {
            var serializer = new XomDataConverter();
            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                ChildNodes = new KeyValuePair<string, XomNodeData>[]
                {
                    new KeyValuePair<string, XomNodeData>("C1", new XomNodeData { NodeType = NodeB.XomNode })
                }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
            Assert.IsNotNull(result.Child1, "Child1 was incorrectly null");
        }
        public void Returned_NodeData_Object_Contains_Child_Data()
        {
            var converter = new XomDataConverter();
            var xmlObject = new NodeA
            {
                Child1 = new NodeB(),
                CollectionChildren = new List<NodeB>()
                {
                    new NodeB()
                }
            };

            var nodeData = converter.ConvertToXomNodeData(xmlObject, _xomReader);
            Assert.IsNotNull(nodeData.ChildNodes, "Returned data did not have children");
            Assert.AreEqual(2, nodeData.ChildNodes.Length, "Returned data had an incorrect number of children");
            Assert.IsTrue(nodeData.ChildNodes.Any(x => x.Key == "Child1" && x.Value != null), "Returned data did not have a 'Child1' child that wasn't null");
            Assert.IsTrue(nodeData.ChildNodes.Any(x => x.Key == "CollectionChildren" && x.Value != null), "Returned data did not have a 'Child1' child that wasn't null");
        }
        public void Can_Serialize_IEnumerable_Data_Nodes_Into_Xml_Object_Collection()
        {
            var serializer = new XomDataConverter();
            var innerData1 = new XomNodeData
            {
                NodeType = NodeB.XomNode
            };

            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                ChildNodes = new KeyValuePair<string, XomNodeData>[]
                {
                    new KeyValuePair<string, XomNodeData>("CollectionChildren", innerData1),
                    new KeyValuePair<string, XomNodeData>("CollectionChildren", innerData1)
                }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
            Assert.AreEqual(2, result.CollectionChildren.Count, "Incorrect number of elements in the collection children node");
        }
        public void Returned_NodeData_Object_Contains_Correct_Attributes()
        {
            const string expectedAttributeName = "Attribute1";
            const string expectedAttributeValue = "Test1";

            var converter = new XomDataConverter();
            var xmlObject = new NodeA
            {
                Attribute1 = expectedAttributeValue
            };

            var nodeData = converter.ConvertToXomNodeData(xmlObject, _xomReader);
            Assert.IsNotNull(nodeData.AttributeData, "Nodes attribute data was null");

            var propertyValue = nodeData.AttributeData
                                        .GetType()
                                        .GetProperties()
                                        .Where(x => x.Name == expectedAttributeName)
                                        .Select(x => x.GetValue(nodeData.AttributeData, null))
                                        .FirstOrDefault();

            Assert.AreEqual(expectedAttributeValue, propertyValue, "Node's Attribute1 value was incorrect");
        }
        public UiStructureViewModel()
        {
            _menuItems = new ObservableCollection<UiStructureMenuItem>();
            var reader = new XomReader();
            var nodes = reader.GenerateNodes(typeof(AssetCollection));
            var rootNode = nodes.First(x => x.IsRoot);

            RootNode = new ObservableCollection<UiNode>(new[]
            {
                CreateRootNodeFromFile(@"E:\temp\ui.xml")
            });

            TestCommand = new RelayCommand(() =>
            {
                var root = _rootNode.First();
                var serializer = new XomDataConverter();
                var nodeData = root.CreateDataNode();
                var serializedData = serializer.ConvertToXmlObject(nodeData);
                var xmlSerializer = new XmlSerializer(serializedData.GetType());
                using (var stream = File.OpenWrite(@"c:\temp\test.xml"))
                    xmlSerializer.Serialize(stream, serializedData);
            });
        }
        public void Converts_Attribute_By_Xml_Name()
        {
            var serializer = new XomDataConverter();
            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                AttributeData = new { Attribute2 = "Test" }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
            Assert.AreEqual("Test", result.Attr2, "Attr2's value was incorrect");
        }
        public void Nullable_Attribute_Source_That_Has_Null_Value_Is_Ignored()
        {
            var serializer = new XomDataConverter();
            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                AttributeData = new { Attribute3 = (int?)null }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
            Assert.AreEqual(0, result.Attribute3, "Attribute3 had an incorrect value");
            Assert.IsFalse(result.Attribute3Set, "Attribute3's value was set when it shouldn't have been");
        }
 public void Exception_Thrown_When_Null_Object_Passed_Into_Seriailzer()
 {
     var serializer = new XomDataConverter();
     serializer.ConvertToXmlObject(null);
 }
        public void Exception_Thrown_When_Attribute_Types_Dont_Match()
        {
            var serializer = new XomDataConverter();
            var data = new XomNodeData
            {
                NodeType = NodeA.XomNode,
                AttributeData = new { Attribute2 = 1 }
            };

            var result = (NodeA)serializer.ConvertToXmlObject(data);
        }
        public void Creates_Correct_XML_Serialization_Object()
        {
            var data = new XomNodeData
            {
                NodeType = new XomNode { Type = typeof(NodeA) }
            };
            var serializer = new XomDataConverter();

            object result = serializer.ConvertToXmlObject(data);

            Assert.IsNotNull(result, "Resulting object was null");
            Assert.IsInstanceOfType(result, typeof(NodeA), "Resulting object was an incorrect type");
        }
 public void Exception_Thrown_When_Null_XomReader_Passed_In()
 {
     var inputObject = new object();
     var converter = new XomDataConverter();
     converter.ConvertToXomNodeData(inputObject, null);
 }
        private UiNode CreateRootNodeFromFile(string filename)
        {
            AssetCollection collection;

            using (var stream = File.OpenRead(filename))
            {
                var serializer = new XmlSerializer(typeof(AssetCollection));
                collection = (AssetCollection)serializer.Deserialize(stream);
            }

            var converter = new XomDataConverter();
            var nodeData = converter.ConvertToXomNodeData(collection, new XomReader());
            var node = UiNode.FromXomNodeData(nodeData, "UI Package");

            return node;
        }
 public void Exception_Thrown_When_Data_Object_Has_Null_XomNode()
 {
     var data = new XomNodeData();
     var serializer = new XomDataConverter();
     serializer.ConvertToXmlObject(data);
 }
 public void Returns_Null_When_Null_Object_Passed_In()
 {
     var converter = new XomDataConverter();
     var nodeData = converter.ConvertToXomNodeData(null, _xomReader);
     Assert.IsNull(nodeData, "Returned node data wasn't null but should have been");
 }