public void Serialiser_Writes_Material_Values_Correctly_To_String() { var model = new Model(); var materialGroup = new MaterialGroup(); materialGroup.Id = -1; var material = new Material(Color3.Red, Color3.Green, Color3.Blue, Color3.Black, 10, 1); materialGroup.Add(material); model.Add(materialGroup); var immlSerialiser = new ImmlSerialiser(); var immlString = immlSerialiser.Write(model); var textReader = new StringReader(immlString); var xDoc = XDocument.Load(textReader); var xElementMaterial = xDoc.Descendants(XName.Get("Material", immlSerialiser.Namespace)).FirstOrDefault(); Assert.NotNull(xElementMaterial); Assert.Equal(material.Ambient.ToString(), xElementMaterial.Attribute(XName.Get("Ambient")).Value); Assert.Equal(material.Diffuse.ToString(), xElementMaterial.Attribute(XName.Get("Diffuse")).Value); Assert.Equal(material.Emissive.ToString(), xElementMaterial.Attribute(XName.Get("Emissive")).Value); Assert.Equal(material.Specular.ToString(), xElementMaterial.Attribute(XName.Get("Specular")).Value); Assert.Equal(material.Power.ToString(), xElementMaterial.Attribute(XName.Get("Power")).Value); Assert.Equal(material.Opacity.ToString(), xElementMaterial.Attribute(XName.Get("Opacity")).Value); }
public void Serialiser_Can_Write_A_Simple_Nested_Hierarchy_To_A_String() { var immlDocument = new ImmlDocument(); immlDocument.Author = Guid.NewGuid().ToString(); var model = new Model(); model.Name = Guid.NewGuid().ToString(); model.Source = string.Format("http://{0}", Guid.NewGuid().ToString()); var primitive = new Primitive(); primitive.Name = Guid.NewGuid().ToString(); var camera = new Camera(); camera.Name = Guid.NewGuid().ToString(); primitive.Add(camera); model.Add(primitive); immlDocument.Add(model); var immlSerialiser = new ImmlSerialiser(); var immlString = immlSerialiser.Write(immlDocument); var textReader = new StringReader(immlString); var xDoc = XDocument.Load(textReader); //verify the model is in the correct place var xElementModel = xDoc.Descendants(XName.Get("Model", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == model.Name).FirstOrDefault(); Assert.NotNull(xElementModel); Assert.Equal(immlDocument.Name, xElementModel.Parent.Attribute(XName.Get("Name")).Value); //verify the primitive is in the correct place var xElementPrimitive = xDoc.Descendants(XName.Get("Primitive", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == primitive.Name).FirstOrDefault(); Assert.NotNull(xElementPrimitive); Assert.Equal(model.Name, xElementPrimitive.Parent.Attribute(XName.Get("Name")).Value); //verify the camera is in the correct place var xElementCamera = xDoc.Descendants(XName.Get("Camera", immlSerialiser.Namespace)).Where(e => e.Attribute(XName.Get("Name")).Value == camera.Name).FirstOrDefault(); Assert.NotNull(xElementCamera); Assert.Equal(primitive.Name, xElementCamera.Parent.Attribute(XName.Get("Name")).Value); }