public void TestViewModelUpdate() { var obj = new ClassWithStructs(); var container = new ModelContainer(); container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct)); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); // Modify direct struct via Quantum, check value on actual object var structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 15; Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15)); // Modify nested struct via Quantum, check value on actual object structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("FirstValue").Content.Value = 20; Assert.That(obj.NestedStruct.Struct.FirstValue, Is.EqualTo(20)); // Modify direct struct on actual value, check value via Quantum obj.NestedStruct = new NestedStruct { Struct = new SimpleStruct { FirstValue = 30 }, SecondValue = 10 }; // TODO: this is needed to refresh the references in the node - maybe we could add a Refresh method in the IModelNode? model = container.GetModelNode(obj); structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10)); structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("FirstValue").Content.Value, Is.EqualTo(30)); // Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues. Helper.ConsistencyCheck(container, obj); }
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 static void ConsistencyCheck(ModelContainer container, object rootObject) { var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); var model = container.GetModelNode(rootObject); visitor.Check((ModelNode)model, rootObject, rootObject.GetType(), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
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 static void ConsistencyCheck(ModelContainer container, object rootObject) { var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); var model = container.GetModelNode(rootObject); visitor.Check((ModelNode)model, rootObject, rootObject.GetType(), true); foreach (var node in container.Models) { visitor.Check((ModelNode)node, node.Content.Value, node.Content.Type, true); } }
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 TestListOfNestedStructListsUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last(); var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last(); var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 32; Helper.PrintModelContainerContent(container, model); Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32)); Helper.ConsistencyCheck(container, obj); }
public void TestNestedStructItemUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First(); var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 32; Helper.PrintModelContainerContent(container, model); Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true); Helper.ConsistencyCheck(container, obj); }
public void TestConstruction() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); 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 model.GetChild("ListOfSimpleStructLists").Content.Reference.AsEnumerable) { 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 model.GetChild("ListOfNestedStructLists").Content.Reference.AsEnumerable) { Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference))); } Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null); Assert.That(container.Guids.Count(), Is.EqualTo(18)); Helper.ConsistencyCheck(container, obj); }
/// <inheritdoc/> public bool UpdateTarget(ModelContainer modelContainer) { if (TargetNode == null) { var guid = modelContainer.GetGuid(ObjectValue, Type); if (TargetGuid != guid) { throw new InvalidOperationException("The Guid of the object value is different from the current TargetGuid. The given ModelContainer may be different."); } if (TargetGuid != Guid.Empty) { TargetNode = modelContainer.GetModelNode(TargetGuid); if (TargetNode.Content.Value != null && !Type.IsInstanceOfType(TargetNode.Content.Value)) { throw new InvalidOperationException("The type of the node content does not match the type of this reference"); } return(TargetNode != null); } } return(false); }
public void TestConstruction() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); 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 model.GetChild("ListOfSimpleStructLists").Content.Reference.AsEnumerable) { 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 model.GetChild("ListOfNestedStructLists").Content.Reference.AsEnumerable) { Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference))); } Assert.That(container.GetModelNode(obj.ClassList[0]), !Is.Null); Assert.That(container.Guids.Count(), Is.EqualTo(18)); Helper.ConsistencyCheck(container, obj); }
public void TestListOfNestedStructListsUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last(); var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last(); var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 32; Helper.PrintModelContainerContent(container, model); Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32)); Helper.ConsistencyCheck(container, obj); }
public void TestNestedStructItemUpdate() { var obj = new ClassWithLists(); var container = new ModelContainer(); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First(); var structNode = container.GetModelNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 32; Helper.PrintModelContainerContent(container, model); Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32)); var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); visitor.Check((ModelNode)model, obj, typeof(ClassWithLists), true); Helper.ConsistencyCheck(container, obj); }
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 TestViewModelUpdate() { var obj = new ClassWithStructs(); var container = new ModelContainer(); container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct)); IModelNode model = container.GetOrCreateModelNode(obj, obj.GetType()); Helper.PrintModelContainerContent(container, model); // Modify direct struct via Quantum, check value on actual object var structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Value = 15; Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15)); // Modify nested struct via Quantum, check value on actual object structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("FirstValue").Content.Value = 20; Assert.That(obj.NestedStruct.Struct.FirstValue, Is.EqualTo(20)); // Modify direct struct on actual value, check value via Quantum obj.NestedStruct = new NestedStruct { Struct = new SimpleStruct { FirstValue = 30 }, SecondValue = 10 }; // TODO: this is needed to refresh the references in the node - maybe we could add a Refresh method in the IModelNode? model = container.GetModelNode(obj); structNode = container.GetModelNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10)); structNode = container.GetModelNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("FirstValue").Content.Value, Is.EqualTo(30)); // Finally, we run the ModelConsistencyCheckVisitor to detect potential other issues. Helper.ConsistencyCheck(container, obj); }