public void TestMultipleNestedStruct() { var obj = new SimpleClassWithNestedStruct(1.0, "test", 5.0, "inner value"); Assert.That(obj.Struct.FirstValue, Is.EqualTo(1.0)); Assert.That(obj.Struct.SecondValue, Is.EqualTo("test")); Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(5.0)); Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("inner value")); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); var structNode = model.GetChild("Struct").Content.Reference.AsObject.TargetNode; structNode.GetChild("FirstValue").Content.Value = 2.0; structNode.GetChild("SecondValue").Content.Value = "new value"; structNode = structNode.GetChild("InnerStruct").Content.Reference.AsObject.TargetNode; structNode.GetChild("FirstValue").Content.Value = 7.0; structNode.GetChild("SecondValue").Content.Value = "new inner value"; Assert.That(obj.Struct.FirstValue, Is.EqualTo(2.0)); Assert.That(obj.Struct.SecondValue, Is.EqualTo("new value")); Assert.That(obj.Struct.InnerStruct.FirstValue, Is.EqualTo(7.0)); Assert.That(obj.Struct.InnerStruct.SecondValue, Is.EqualTo("new inner value")); }
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 TestConstruction() { var obj = new ClassWithLists(); 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("IntList").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("IntList").Content.Value, Is.SameAs(obj.IntList)); Assert.That(model.GetChild("IntList").Content.IsReference, Is.False); Assert.That(model.GetChild("ClassList").Children.Count, Is.EqualTo(0)); Assert.That(model.GetChild("ClassList").Content.Value, Is.SameAs(obj.ClassList)); Assert.That(model.GetChild("ClassList").Content.Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); 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(ObjectReference))); } 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(ObjectReference))); } Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null); Assert.That(container.Guids.Count(), Is.EqualTo(14)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
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 TestPrimitiveItemUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); ((List <int>)model.GetChild("IntList").Content.Value)[1] = 42; ((List <int>)model.GetChild("IntList").Content.Value).Add(26); Assert.That(obj.IntList.Count, Is.EqualTo(4)); Assert.That(obj.IntList[1], Is.EqualTo(42)); Assert.That(obj.IntList[3], Is.EqualTo(26)); Helper.ConsistencyCheck(container, obj); }
public static void PrintModelContainerContent(ModelContainer container, IModelNode rootNode = null) { Console.WriteLine(@"Container content:"); Console.WriteLine(@"------------------"); // Print the root node first, if specified if (rootNode != null) Console.WriteLine(rootNode.PrintHierarchy()); // Print other nodes next // TODO: FIXME //foreach (var node in container.Guids.Select(container.GetModelNode).Where(x => x != rootNode)) //{ // Console.WriteLine(node.PrintHierarchy()); //} Console.WriteLine(@"------------------"); }
public void TestSimpleContent() { var obj = new SimpleClass(1, "test"); Assert.That(obj.FirstValue, Is.EqualTo(1)); Assert.That(obj.SecondValue, Is.EqualTo("test")); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); model.GetChild("FirstValue").Content.Value = 2; model.GetChild("SecondValue").Content.Value = "new value"; Assert.That(obj.FirstValue, Is.EqualTo(2)); Assert.That(obj.SecondValue, Is.EqualTo("new value")); }
public static void PrintModelContainerContent(ModelContainer container, IModelNode rootNode = null) { Console.WriteLine(@"Container content:"); Console.WriteLine(@"------------------"); // Print the root node first, if specified if (rootNode != null) { Console.WriteLine(rootNode.PrintHierarchy()); } // Print other nodes next // TODO: FIXME //foreach (var node in container.Guids.Select(container.GetModelNode).Where(x => x != rootNode)) //{ // Console.WriteLine(node.PrintHierarchy()); //} Console.WriteLine(@"------------------"); }
public void TestNestedStructItemUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First(); objRef.TargetNode.GetChild("Struct").GetChild("SecondValue").Content.Value = 32; Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
public void TestNullLists() { var obj = new ClassWithNullLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); foreach (var node in container.Guids.Select(container.GetModelNode).Where(x => model != x)) { Console.WriteLine(node.PrintHierarchy()); } var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithNullLists), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
public void TestConstruction() { var obj = new ClassWithStructs(); var container = new ModelContainer(); container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct)); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); Assert.That(model.GetChild("NestedStruct").Children.Count, Is.EqualTo(2)); Assert.That(model.GetChild("NestedStruct").GetChild("Struct").Children.Count, Is.EqualTo(2)); Assert.That(model.GetChild("PrimitiveStruct").Children.Count, Is.EqualTo(0)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithStructs), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
public void TestPrimitiveItemUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Console.WriteLine(model.PrintHierarchy()); ((List <int>)model.GetChild("IntList").Content.Value)[1] = 42; ((List <int>)model.GetChild("IntList").Content.Value).Add(26); Assert.That(obj.IntList.Count, Is.EqualTo(4)); Assert.That(obj.IntList[1], Is.EqualTo(42)); Assert.That(obj.IntList[3], Is.EqualTo(26)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }