public void IPropertiesExtensionMethodsTest() { var graph = new PropertyGraph(123UL, g => g.SetProperty (new KeyValuePair<String, Object>("hello", "world!")). SetProperties(new List<KeyValuePair<String, Object>>() { new KeyValuePair<String, Object>("graphs", "are cool!"), new KeyValuePair<String, Object>("Keep", "it simple!")}). SetProperties(new Dictionary<String, Object>() { { "a", "b" }, { "c", "d" } }). SetProperty ("e", "f")); Assert.AreEqual(123UL, graph.GetProperty("Id")); Assert.AreEqual("world!", graph.GetProperty("hello")); Assert.AreEqual("are cool!", graph.GetProperty("graphs")); Assert.AreEqual("it simple!", graph.GetProperty("Keep")); Assert.AreEqual("b", graph.GetProperty("a")); Assert.AreEqual("d", graph.GetProperty("c")); Assert.AreEqual(123UL, graph.GetProperty("Id", typeof(UInt64))); Assert.AreEqual("world!", graph.GetProperty("hello", typeof(String))); Assert.AreEqual("are cool!", graph.GetProperty("graphs", typeof(String))); Assert.AreEqual("it simple!", graph.GetProperty("Keep", typeof(String))); Assert.AreNotEqual("world!", graph.GetProperty("hello", typeof(UInt64))); // --[Action<TValue>]-------------------------------------------------------------- Nullable<Boolean> check; check = null; graph.UseProperty("false", OnSuccess_PropertyValue => check = true); Assert.IsNull(check); check = null; graph.UseProperty("Id", OnSuccess_PropertyValue => check = true); Assert.IsTrue(check.Value); check = null; graph.UseProperty("hello", OnSuccess_PropertyValue => check = true); Assert.IsTrue(check.Value); check = null; graph.UseProperty("graphs", OnSuccess_PropertyValue => check = true); Assert.IsTrue(check.Value); // --[Action<TKey, TValue>]-------------------------------------------------------- check = null; graph.UseProperty("false", (OnSuccess_PropertyKey, PropertyValue) => check = true); Assert.IsNull(check); check = null; graph.UseProperty("Id", (OnSuccess_PropertyKey, PropertyValue) => check = true); Assert.IsTrue(check.Value); check = null; graph.UseProperty("hello", (OnSuccess_PropertyKey, PropertyValue) => check = true); Assert.IsTrue(check.Value); check = null; graph.UseProperty("graphs", (OnSuccess_PropertyKey, PropertyValue) => check = true); Assert.IsTrue(check.Value); // --[Action<TValue>]--[Error]----------------------------------------------------- check = null; graph.GetProperty("false", OnSuccess_PropertyValue => check = true, OnError => check = false); Assert.IsFalse(check.Value); check = null; graph.GetProperty("Id", OnSuccess_PropertyValue => check = true, OnError => check = false); Assert.IsTrue(check.Value); check = null; graph.GetProperty("hello", OnSuccess_PropertyValue => check = true, OnError => check = false); Assert.IsTrue(check.Value); check = null; graph.GetProperty("graphs", OnSuccess_PropertyValue => check = true, OnError => check = false); Assert.IsTrue(check.Value); // --[Action<TKey, TValue>]--[Error]----------------------------------------------- check = null; graph.GetProperty("false", (OnSuccess_PropertyKey, PropertyValue) => check = true, OnError => check = false); Assert.IsFalse(check.Value); check = null; graph.GetProperty("Id", (OnSuccess_PropertyKey, PropertyValue) => check = true, OnError => check = false); Assert.IsTrue(check.Value); check = null; graph.GetProperty("hello", (OnSuccess_PropertyKey, PropertyValue) => check = true, OnError => check = false); Assert.IsTrue(check.Value); check = null; graph.GetProperty("graphs", (OnSuccess_PropertyKey, PropertyValue) => check = true, OnError => check = false); Assert.IsTrue(check.Value); // --[Func<TValue, TResult>]------------------------------------------------------- Assert.AreEqual("world!?", graph.PropertyFunc("hello", PropertyValue => { return (PropertyValue as String) + "?"; })); Assert.AreEqual(124UL, graph.PropertyFunc("Id", PropertyValue => { return ( (UInt64) PropertyValue ) + 1; })); Assert.AreEqual(0, graph.PropertyFunc("XYZ", PropertyValue => { return ( (UInt64) PropertyValue ) + 1; })); Assert.AreEqual(null, graph.PropertyFunc("XYZ", PropertyValue => { return ( (String) PropertyValue ); })); Assert.AreEqual("world!?", graph.PropertyFunc("hello", typeof(String), PropertyValue => { return (PropertyValue as String) + "?"; })); Assert.AreEqual(124UL, graph.PropertyFunc("Id", typeof(UInt64), PropertyValue => { return ( (UInt64) PropertyValue ) + 1; })); Assert.AreEqual(null, graph.PropertyFunc("XYZ", typeof(UInt64), PropertyValue => { return ( (UInt64) PropertyValue ) + 1; })); Assert.AreEqual(null, graph.PropertyFunc("XYZ", typeof(String), PropertyValue => { return ( (String) PropertyValue ); })); // --[Func<TKey, TValue, TResult>]------------------------------------------------- Assert.AreEqual("hello world!", graph.PropertyFunc("hello", (OnSuccess_PropertyKey, PropertyValue) => { return OnSuccess_PropertyKey + " " + (PropertyValue as String); })); Assert.AreEqual("Id124", graph.PropertyFunc("Id", (OnSuccess_PropertyKey, PropertyValue) => { return OnSuccess_PropertyKey + ((UInt64) PropertyValue + 1); })); Assert.AreEqual("hello world!", graph.PropertyFunc("hello", typeof(String), (OnSuccess_PropertyKey, PropertyValue) => { return OnSuccess_PropertyKey + " " + (PropertyValue as String); })); Assert.AreEqual("Id124", graph.PropertyFunc("Id", typeof(UInt64), (OnSuccess_PropertyKey, PropertyValue) => { return OnSuccess_PropertyKey + ((UInt64) PropertyValue + 1); })); // Filtered Keys/Values var FilteredKeys1 = graph.FilteredKeys ((k, v) => true).ToList(); Assert.NotNull(FilteredKeys1); Assert.AreEqual(8, FilteredKeys1.Count); var FilteredKeys2 = graph.FilteredKeys ((k, v) => { if ((v as String).IsNotNullAndContains("!")) return true; else return false;}).ToList(); Assert.NotNull(FilteredKeys2); Assert.AreEqual(3, FilteredKeys2.Count); var FilteredValues1 = graph.FilteredValues((k, v) => true).ToList(); Assert.NotNull(FilteredValues1); Assert.AreEqual(8, FilteredValues1.Count); var FilteredValues2 = graph.FilteredValues((k, v) => { if ((v as String).IsNotNullAndContains("!")) return true; else return false; }).ToList(); Assert.NotNull(FilteredValues2); Assert.AreEqual(3, FilteredValues2.Count); }