public void CreateXElementElementaryDataTypes() { var person = new Person() { Name = "Peter", Birthday = new DateTime(2015, 7, 7), Height = 180, Weight = 80 }; var expectedElement = new XElement("Person"); expectedElement.SetElementValue("Name", "Peter"); expectedElement.SetElementValue("Birthday", "2015-07-07T00:00:00"); expectedElement.SetElementValue("Weight", "80"); expectedElement.SetElementValue("Height", "180"); var dataStore = new PersonDataStore(); var xElement = dataStore.CreateXElement(person); var guid = xElement.GetGuid(); expectedElement.SetAttributeValue("ref", guid); Assert.AreEqual(expectedElement.Value, xElement.Value); }
public void CreateXElementMultipleReferenceDataTypes() { var father = new Person() { Name = "Father", Birthday = new DateTime(1970, 7, 7), Height = 180, Weight = 80 }; var mother = new Person() { Name = "Mother", Birthday = new DateTime(1975, 7, 7), Height = 175, Weight = 72 }; var child = new Child() { Father = father, Mother = mother }; var child2 = new Child() { Father = father, Mother = mother }; var children = new Children() { ChildOne = child, ChildTwo = child2 }; var expectedFather = new XElement("Person"); expectedFather.SetElementValue("Name", "Father"); expectedFather.SetElementValue("Birthday", "1970-07-07T00:00:00"); expectedFather.SetElementValue("Weight", "80"); expectedFather.SetElementValue("Height", "180"); var expectedMother = new XElement("Person"); expectedMother.SetElementValue("Name", "Mother"); expectedMother.SetElementValue("Birthday", "1975-07-07T00:00:00"); expectedMother.SetElementValue("Weight", "72"); expectedMother.SetElementValue("Height", "175"); var expectedChild1 = new XElement("ChildOne", expectedFather, expectedMother); var expectedChild2 = new XElement("ChildTwo", expectedFather, expectedMother); var expectedChildren = new XElement("Children", expectedChild1, expectedChild2); var dataStore = new ChildrenDataStore(); var actualElement = dataStore.CreateXElement(children); var guid = actualElement.GetGuid(); expectedChildren.SetAttributeValue("ref", guid); guid = actualElement.Elements().ElementAt(0).GetGuid(); expectedChild1.SetAttributeValue("ref", guid); guid = actualElement.Elements().ElementAt(1).GetGuid(); expectedChild2.SetAttributeValue("ref", guid); guid = actualElement.Elements().ElementAt(0).Elements().ElementAt(0).GetGuid(); expectedFather.SetAttributeValue("ref", guid); guid = actualElement.Elements().ElementAt(0).Elements().ElementAt(1).GetGuid(); expectedMother.SetAttributeValue("ref", guid); Assert.AreEqual(expectedChildren.Value, actualElement.Value); }