public void DynamicModelBase_XmlConversion_SerializesCorrectly() { // This is to verify approach used in formatter for sample api, // to address issue brought up here: // https://github.com/nihaue/TRex/issues/8 var testModel = new DynamicSchemaTestModel(new { Value1 = 1, Value2 = "Two", Value3 = new { NestedValue1 = "Nested", NestedValue2 = "Value" } }); dynamic dynTestModel = testModel; var serializedJsonString = JsonConvert.SerializeObject(new { Root = dynTestModel }); var xmlDoc = JsonConvert.DeserializeXmlNode(serializedJsonString); MemoryStream serializedXmlStream = new MemoryStream(Encoding.Default.GetBytes(xmlDoc.OuterXml)); var outputDoc = XDocument.Load(serializedXmlStream); Assert.AreEqual(Convert.ToString(dynTestModel.Value1), outputDoc.Root.Element("Value1").Value, "Property serialization of root level member failed"); Assert.AreEqual(Convert.ToString(dynTestModel.Value3.NestedValue1), outputDoc.Root.Element("Value3").Element("NestedValue1").Value, "Property serialization of nested member failed"); }
public void DynamicModelBase_FromDictionary_PropertiesReadable() { var myDictionary = new Dictionary <string, object> { { "prop1", "value1" }, { "prop2", 2 } }; var testModel = new DynamicSchemaTestModel(myDictionary); dynamic dynTestModel = testModel; Assert.AreEqual(Convert.ToString(myDictionary["prop1"]), Convert.ToString(dynTestModel.prop1), "Dictionary value not readable from dynamic test model with dictionary as source"); Assert.AreEqual(Convert.ToInt32(myDictionary["prop2"]), Convert.ToInt32(dynTestModel.prop2), "Dictionary value not readable from dynamic test model with dictionary as source"); }
public IHttpActionResult FriendlyAsSource( DynamicSchemaTestModel lookupParameter, string noAttributeParameter) { return(Ok()); }