public void ObjectDictionaryTest() { var o = new { A = "a", B = "b" }; var objD = new ObjectDictionaryWrapper(o); Assert.AreEqual(objD["A"].ToString(), "a"); Assert.IsTrue(objD.ContainsKey("B")); Assert.AreEqual(2, objD.Count); }
/// <summary> /// Composes URL from named route using given object's properties as context. /// </summary> public static string GetRouteUrl(string routeName, object context) { IDictionary <string, object> routeContext = null; if (context != null) { var conv = ConvertManager.FindConverter(context.GetType(), typeof(IDictionary <string, object>)); if (conv != null) { routeContext = conv.Convert(context, typeof(IDictionary <string, object>)) as IDictionary <string, object>; } else { routeContext = new ObjectDictionaryWrapper(context); } } return(GetRouteUrl(routeName, routeContext)); }
public void Does_serialize_ObjectDictionaryWrapper_line_breaks() { var prop = new Dictionary <string, string> { ["text"] = "line\nbreak" }; var dto = new ObjectDictionaryWrapper { Prop = prop }; Assert.That(dto.ToJson(), Is.EqualTo("{\"Prop\":{\"text\":\"line\\nbreak\"}}")); var nested = new ObjectDictionaryWrapper { Prop = new Dictionary <string, Dictionary <string, string> > { ["a"] = prop } }; Assert.That(nested.ToJson(), Is.EqualTo("{\"Prop\":{\"a\":{\"text\":\"line\\nbreak\"}}}")); }