public void TestConstruction() { var obj = new ClassWithDictionaries(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); foreach (var guid in container.Guids) { var node = container.GetModelNode(guid); if (model != node) { Console.WriteLine(node.PrintHierarchy()); } } Assert.That(model.GetChild("StringIntDic").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic)); Assert.That(model.GetChild("StringIntDic").Content.IsReference, Is.False); Assert.That(model.GetChild("StringClassDic").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic)); Assert.That(model.GetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); var enumerator = obj.StringClassDic.GetEnumerator(); foreach (var reference in (ReferenceEnumerable)model.GetChild("StringClassDic").Content.Reference) { enumerator.MoveNext(); var keyValuePair = enumerator.Current; Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key)); Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value)); } //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList)); //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList)); //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null); //Assert.That(container.Guids.Count(), Is.EqualTo(10)); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); var model = container.GetOrCreateNode(obj); ((Dictionary <string, int>)model["StringIntDic"].Retrieve())["b"] = 42; ((Dictionary <string, int>)model["StringIntDic"].Retrieve()).Add("d", 26); Assert.Equal(4, obj.StringIntDic.Count); Assert.Equal(42, obj.StringIntDic["b"]); Assert.Equal(26, obj.StringIntDic["d"]); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); var model = container.GetOrCreateNode(obj); ((Dictionary <string, int>)model["StringIntDic"].Value)["b"] = 42; ((Dictionary <string, int>)model["StringIntDic"].Value).Add("d", 26); Assert.That(obj.StringIntDic.Count, Is.EqualTo(4)); Assert.That(obj.StringIntDic["b"], Is.EqualTo(42)); Assert.That(obj.StringIntDic["d"], Is.EqualTo(26)); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42; ((Dictionary <string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26); Assert.That(obj.StringIntDic.Count, Is.EqualTo(4)); Assert.That(obj.StringIntDic["b"], Is.EqualTo(42)); Assert.That(obj.StringIntDic["d"], Is.EqualTo(26)); }
public void TestConstruction() { var obj = new ClassWithDictionaries(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); foreach (var guid in container.Guids) { var node = container.GetModelNode(guid); if (model != node) Console.WriteLine(node.PrintHierarchy()); } Assert.That(model.GetChild("StringIntDic").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic)); Assert.That(model.GetChild("StringIntDic").Content.IsReference, Is.False); Assert.That(model.GetChild("StringClassDic").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic)); Assert.That(model.GetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); var enumerator = obj.StringClassDic.GetEnumerator(); foreach (var reference in (ReferenceEnumerable)model.GetChild("StringClassDic").Content.Reference) { enumerator.MoveNext(); var keyValuePair = enumerator.Current; Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key)); Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value)); } //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList)); //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList)); //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null); //Assert.That(container.Guids.Count(), Is.EqualTo(10)); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); ((Dictionary <string, int>)model.TryGetChild("StringIntDic").Content.Value)["b"] = 42; ((Dictionary <string, int>)model.TryGetChild("StringIntDic").Content.Value).Add("d", 26); Assert.That(obj.StringIntDic.Count, Is.EqualTo(4)); Assert.That(obj.StringIntDic["b"], Is.EqualTo(42)); Assert.That(obj.StringIntDic["d"], Is.EqualTo(26)); Helper.PrintModelContainerContent(container, model); Helper.ConsistencyCheck(container, obj); }
public void TestConstruction() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); Assert.That(model.TryGetChild("StringIntDic").Children.Count, Is.EqualTo(0)); Assert.That(model.TryGetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic)); Assert.That(model.TryGetChild("StringIntDic").Content.IsReference, Is.False); Assert.That(model.TryGetChild("StringClassDic").Children.Count, Is.EqualTo(0)); Assert.That(model.TryGetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic)); Assert.That(model.TryGetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); var enumerator = obj.StringClassDic.GetEnumerator(); foreach (var reference in model.TryGetChild("StringClassDic").Content.Reference.AsEnumerable) { enumerator.MoveNext(); var keyValuePair = enumerator.Current; Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key)); Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value)); } //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList)); //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList)); //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null); //Assert.That(container.Guids.Count(), Is.EqualTo(10)); }
public void TestConstruction() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); Assert.That(model.TryGetChild("StringIntDic").Children.Count, Is.EqualTo(0)); Assert.That(model.TryGetChild("StringIntDic").Content.Value, Is.SameAs(obj.StringIntDic)); Assert.That(model.TryGetChild("StringIntDic").Content.IsReference, Is.False); Assert.That(model.TryGetChild("StringClassDic").Children.Count, Is.EqualTo(0)); Assert.That(model.TryGetChild("StringClassDic").Content.Value, Is.SameAs(obj.StringClassDic)); Assert.That(model.TryGetChild("StringClassDic").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); var enumerator = obj.StringClassDic.GetEnumerator(); foreach (var reference in model.TryGetChild("StringClassDic").Content.Reference.AsEnumerable) { enumerator.MoveNext(); var keyValuePair = enumerator.Current; Assert.That(reference.Index, Is.EqualTo(keyValuePair.Key)); Assert.That(reference.ObjectValue, Is.EqualTo(keyValuePair.Value)); } //Assert.That(model.GetChild("SimpleStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList)); //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("NestedStructList").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList)); //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.That(model.GetChild("ListOfSimpleStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(model.GetChild("ListOfNestedStructLists").Children.Count, Is.EqualTo(0)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null); //Assert.That(container.Guids.Count(), Is.EqualTo(10)); }
public void TestConstruction() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); var model = container.GetOrCreateNode(obj); Assert.That(model["StringIntDic"].Retrieve(), Is.SameAs(obj.StringIntDic)); Assert.That(model["StringIntDic"].IsReference, Is.False); Assert.That(model["StringClassDic"].Retrieve(), Is.SameAs(obj.StringClassDic)); //Assert.That(model["StringClassDic"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); var enumerator = obj.StringClassDic.GetEnumerator(); foreach (var reference in model["StringClassDic"].Target.ItemReferences) { enumerator.MoveNext(); var keyValuePair = enumerator.Current; Assert.Equal(keyValuePair.Key, reference.Index); Assert.Equal(keyValuePair.Value, reference.ObjectValue); } //Assert.Equal(0, model.GetChild("SimpleStructList").Children.Count); //Assert.That(model.GetChild("SimpleStructList").Content.Value, Is.SameAs(obj.SimpleStructList)); //Assert.That(model.GetChild("SimpleStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.Equal(0, model.GetChild("NestedStructList").Children.Count); //Assert.That(model.GetChild("NestedStructList").Content.Value, Is.SameAs(obj.NestedStructList)); //Assert.That(model.GetChild("NestedStructList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //Assert.Equal(0, model.GetChild("ListOfSimpleStructLists").Children.Count); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Value, Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model.GetChild("ListOfSimpleStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfSimpleStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.Equal(0, model.GetChild("ListOfNestedStructLists").Children.Count); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Value, Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model.GetChild("ListOfNestedStructLists").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //foreach (var reference in (ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference) //{ // Assert.That(reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); //} //Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null); //Assert.Equal(10, container.Guids.Count()); }
public static void AllPrimitivesConversion() { ClassWithDictionaries obj; Guid guid = Guid.NewGuid(); void Verify() { Assert.Equal("test", obj.BoolKey[true].Value); Assert.Equal("test", obj.EnumKey[MyEnum.One].Value); Assert.Equal("test", obj.GuidKey[guid].Value); Assert.Equal("test", obj.IntKey[1].Value); Assert.Equal("test", obj.FloatKey[1.34f].Value); Assert.Equal("test", obj.DoubleKey[1.35].Value); Assert.Equal("test", obj.StringKey["key"].Value); } var options = new JsonSerializerOptions(); options.Converters.Add(new DictionaryKeyValueConverter()); obj = new ClassWithDictionaries { BoolKey = new Dictionary <bool, Entity> { [true] = new Entity { Value = "test" } }, EnumKey = new Dictionary <MyEnum, Entity> { [MyEnum.One] = new Entity { Value = "test" } }, GuidKey = new Dictionary <Guid, Entity> { [guid] = new Entity { Value = "test" } }, DoubleKey = new Dictionary <double, Entity> { [1.35] = new Entity { Value = "test" } }, FloatKey = new Dictionary <float, Entity> { [1.34f] = new Entity { Value = "test" } }, IntKey = new Dictionary <int, Entity> { [1] = new Entity { Value = "test" } }, // String is actually handled by built-in converter, not the custom converter. StringKey = new Dictionary <string, Entity> { ["key"] = new Entity { Value = "test" } }, }; // Verify baseline. Verify(); string json = JsonSerializer.Serialize(obj, options); obj = JsonSerializer.Deserialize <ClassWithDictionaries>(json, options); // Verify. Verify(); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); ((Dictionary<string, int>)model.TryGetChild("StringIntDic").Content.Value)["b"] = 42; ((Dictionary<string, int>)model.TryGetChild("StringIntDic").Content.Value).Add("d", 26); Assert.That(obj.StringIntDic.Count, Is.EqualTo(4)); Assert.That(obj.StringIntDic["b"], Is.EqualTo(42)); Assert.That(obj.StringIntDic["d"], Is.EqualTo(26)); Helper.PrintModelContainerContent(container, model); Helper.ConsistencyCheck(container, obj); }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithDictionaries(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value)["b"] = 42; ((Dictionary<string, int>)model.GetChild("StringIntDic").Content.Value).Add("d", 26); Assert.That(obj.StringIntDic.Count, Is.EqualTo(4)); Assert.That(obj.StringIntDic["b"], Is.EqualTo(42)); Assert.That(obj.StringIntDic["d"], Is.EqualTo(26)); }