public void TestViewModelUpdate() { var obj = new ClassWithStructs(); var container = new NodeContainer(); container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct)); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); // Modify direct struct via Quantum, check value on actual object var structNode = container.GetNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(15); Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15)); // Modify nested struct via Quantum, check value on actual object structNode = container.GetNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("FirstValue").Content.Update(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.GetNode(obj); structNode = container.GetNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10)); structNode = container.GetNode(((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 TestPushTarget() { var obj = new Class { ClassMember = new Class() }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ClassMember)); path.PushTarget(); var targetNode = nodeContainer.GetNode(obj.ClassMember); var nodes = new IGraphNode[] { rootNode, rootNode[nameof(Class.ClassMember)], targetNode }; Assert.NotNull(targetNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(targetNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
public void TestPushIndexAndMember() { var obj = new Class { ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode); path.PushMember(nameof(Class.ListMember)); path.PushTarget(); path.PushIndex(new NodeIndex(1)); path.PushMember(nameof(Class.IntMember)); var targetNode = nodeContainer.GetNode(obj.ListMember[1]); var intNode = targetNode[nameof(Class.IntMember)]; var nodes = new IGraphNode[] { rootNode, rootNode[nameof(Class.ListMember)], rootNode[nameof(Class.ListMember)].Target, targetNode, intNode }; Assert.NotNull(targetNode); Assert.NotNull(intNode); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(intNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
public void TestPushTargetAndMember() { var obj = new Class { ClassMember = new Class() }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget().PushMember(nameof(Class.IntMember)); var targetNode = nodeContainer.GetNode(obj.ClassMember); var intNode = targetNode.GetChild(nameof(Class.IntMember)); var nodes = new[] { rootNode, rootNode.GetChild(nameof(Class.ClassMember)), targetNode, intNode }; Assert.NotNull(targetNode); Assert.NotNull(intNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); Assert.AreEqual(rootNode, path.RootNode); Assert.AreEqual(intNode, path.GetNode()); var i = 0; foreach (var node in path) { Assert.AreEqual(nodes[i++], node); } Assert.AreEqual(nodes.Length, i); }
public void TestConstruction() { var obj = new ClassWithLists(); var container = new NodeContainer(); var model = container.GetOrCreateNode(obj); Assert.That(model["IntList"].Retrieve(), Is.SameAs(obj.IntList)); Assert.That(model["IntList"].IsReference, Is.False); Assert.That(model["ClassList"].Retrieve(), Is.SameAs(obj.ClassList)); //Assert.That(model["ClassList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); Assert.That(model["SimpleStructList"].Retrieve(), Is.SameAs(obj.SimpleStructList)); //Assert.That(model["SimpleStructList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); Assert.That(model["NestedStructList"].Retrieve(), Is.SameAs(obj.NestedStructList)); //Assert.That(model["NestedStructList"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); Assert.That(model["ListOfSimpleStructLists"].Retrieve(), Is.SameAs(obj.ListOfSimpleStructLists)); //Assert.That(model["ListOfSimpleStructLists"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); foreach (var reference in model["ListOfSimpleStructLists"].Target.ItemReferences) { Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference))); } Assert.That(model["ListOfNestedStructLists"].Retrieve(), Is.SameAs(obj.ListOfNestedStructLists)); //Assert.That(model["ListOfNestedStructLists"].Reference, Is.AssignableFrom(typeof(ReferenceEnumerable))); foreach (var reference in model["ListOfNestedStructLists"].Target.ItemReferences) { Assert.That(reference, Is.AssignableFrom(typeof(ObjectReference))); } Assert.That(container.GetNode(obj.ClassList[0]), !Is.Null); }
private void UpdatePublicUIElementsEntry(Guid rootId, [CanBeNull] string name) { var node = NodeContainer.GetNode((UILibraryAsset)Asset.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target; var index = new Index(rootId); using (var transaction = UndoRedoService.CreateTransaction()) { // update UILibraryAsset's PublicUIElements collection if (string.IsNullOrWhiteSpace(name)) { // Remove the entry if it exists if (node.Indices.Contains(index)) { node.Remove(name, index); UndoRedoService.SetName(transaction, $"Remove '{name}' export from the UILibrary"); } } else { if (!node.Indices.Contains(index)) { // Note: update would probably work, but we want to remove the item when Undo node.Add(name, index); UndoRedoService.SetName(transaction, $"Add '{name}' export to the UILibrary"); } else { node.Update(name, index); UndoRedoService.SetName(transaction, "Update name of export in the UILibrary"); } } } }
protected AssetCompositeHierarchyViewModel([NotNull] AssetViewModelConstructionParameters parameters) : base(parameters) { Asset.Hierarchy.Parts.Values.ForEach(TrackBaseChanges); var parts = NodeContainer.GetNode(Asset.Hierarchy.Parts); parts.ItemChanged += PartsChanged; Session.DeletedAssetsChanged += AssetsDeleted; }
private void RemoveLibrary(UILibraryViewModel library) { factories.RemoveWhere(l => l.Category == library.Url); var node = NodeContainer.GetNode(library.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target; node.ItemChanged -= LibraryContentChanged; }
private void UntrackBaseChanges(TAssetPartDesign part) { if (part != null) { var partNode = NodeContainer.GetNode(part); partNode[nameof(IAssetPartDesign.Base)].ValueChanged -= BaseChanged; } }
/// <inheritdoc /> public override void Destroy() { Asset.Hierarchy.Parts.Values.ForEach(UntrackBaseChanges); var parts = NodeContainer.GetNode(Asset.Hierarchy.Parts); parts.ItemChanged -= PartsChanged; Session.DeletedAssetsChanged -= AssetsDeleted; base.Destroy(); }
private void ClearPublicUIElements() { var node = NodeContainer.GetNode((UILibraryAsset)Asset.Asset)[nameof(UILibraryAsset.PublicUIElements)].Target; if (node is Xenko.Core.Assets.Quantum.Internal.AssetObjectNode) { ((Xenko.Core.Assets.Quantum.Internal.AssetObjectNode)node).Clear(); } }
public static void ConsistencyCheck(NodeContainer container, object rootObject) { var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); var model = container.GetNode(rootObject); visitor.Check((GraphNode)model, rootObject, rootObject.GetType(), true); foreach (var node in container.Nodes) { visitor.Check((GraphNode)node, node.Content.Value, node.Content.Type, true); } }
public static void ConsistencyCheck(NodeContainer container, object rootObject) { var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); var model = container.GetNode(rootObject); visitor.Check((GraphNode)model, rootObject, rootObject.GetType(), true); foreach (var node in container.Nodes) { visitor.Check((GraphNode)node, node.Content.Value, node.Content.Type, true); } }
public void MakeAdjactedBothWay(NodeContainer nodes) { foreach (var node in nodes) { foreach (var adjacted in node.adjacentNodes) { var adjNode = nodes.GetNode(adjacted); var corrected = adjNode.adjacentNodes.Concat(new[] {node.id}).ToArray(); adjNode.adjacentNodes = corrected; } } }
public void TestListOfNestedStructListsUpdate() { var obj = new ClassWithLists(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last(); var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last(); var structNode = container.GetNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(32); Helper.PrintModelContainerContent(container, model); Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32)); Helper.ConsistencyCheck(container, obj); }
public SceneViewModel([NotNull] AssetViewModelConstructionParameters parameters) : base(parameters) { SetAsDefaultCommand = new AnonymousCommand(ServiceProvider, SetAsDefault); assetCommands.Add(new MenuCommandInfo(ServiceProvider, SetAsDefaultCommand) { DisplayName = "Set as default", Tooltip = "Set as default scene" }); UpdateCommands(); Session.SessionStateChanged += SessionStateChanged; var assetNode = NodeContainer.GetNode(Asset); childrenNode = assetNode[nameof(SceneAsset.ChildrenIds)].Target; parentNode = assetNode[nameof(SceneAsset.Parent)]; }
public void TestObjectReference() { var nodeContainer = new NodeContainer(); var instance = new TestObject { Name = "Test" }; var container = new ObjectContainer { Instance = instance }; var containerNode = nodeContainer.GetOrCreateNode(container); Helper.TestNonCollectionObjectContentNode(containerNode, container, 1); var memberNode = containerNode.Children.First(); Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instance, false); var instanceNode = nodeContainer.GetNode(instance); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance); memberNode = instanceNode.Children.First(); Helper.TestMemberContentNode(instanceNode, memberNode, instance, instance.Name, nameof(TestObject.Name), false); }
public void TestNestedStructItemUpdate() { var obj = new ClassWithLists(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First(); var structNode = container.GetNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(32); Helper.PrintModelContainerContent(container, model); Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32)); //var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); //visitor.Check((GraphNode)model, obj, typeof(ClassWithLists), true); Helper.ConsistencyCheck(container, obj); }
private void BaseChanged(object sender, MemberNodeChangeEventArgs e) { var part = NodeContainer.GetNode(((TAssetPartDesign)e.Member.Parent.Retrieve()).Part); var baseInfo = (BasePart)e.Member.Retrieve(); if (baseInfo == null) { AssetHierarchyPropertyGraph.RefreshBase((IAssetNode)part, null); } else { var baseAsset = Session.GetAssetById(baseInfo.BasePartAsset.Id) as AssetCompositeHierarchyViewModel <TAssetPartDesign, TAssetPart>; TAssetPartDesign basePart; if (baseAsset != null && baseAsset.Asset.Hierarchy.Parts.TryGetValue(baseInfo.BasePartId, out basePart)) { var basePartNode = (IAssetNode)NodeContainer.GetNode(basePart.Part); AssetHierarchyPropertyGraph.RefreshBase((IAssetNode)part, basePartNode); } } }
public void UpdateProperties(Guid elementId, IReadOnlyDictionary <string, object> changes) { var partId = new AbsoluteId(Asset.Id, elementId); var element = (UIElementViewModel)FindPartViewModel(partId); if (element == null) { return; } var node = NodeContainer.GetNode(element.AssetSideUIElement); if (node == null) { return; } using (var transaction = UndoRedoService.CreateTransaction()) { foreach (var kv in changes) { var propertyName = kv.Key; var propertyValue = kv.Value; var member = node.TryGetChild(propertyName); if (member == null) { continue; } // Update properties only when they actually changed var currentValue = member.Retrieve(); if (currentValue != propertyValue) { member.Update(propertyValue); } } UndoRedoService.SetName(transaction, $"Update {element.ElementType.Name}"); } }
public void TestConstruction() { var obj = new ClassWithLists(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); 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.GetNode(obj.ClassList[0]), !Is.Null); Assert.That(container.Guids.Count(), Is.EqualTo(18)); Helper.ConsistencyCheck(container, obj); }
public void TestObjectReferenceUpdate() { var nodeContainer = new NodeContainer(); var instance = new TestObject { Name = "Test" }; var container = new ObjectContainer { Instance = instance }; var containerNode = nodeContainer.GetOrCreateNode(container); var memberNode = containerNode.Children.First(); var instanceNode = memberNode.Content.Reference.AsObject.TargetNode; // Update to a new instance var newInstance = new TestObject { Name = "Test2" }; memberNode.Content.Update(newInstance); Helper.TestMemberContentNode(containerNode, memberNode, container, newInstance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstance); var newInstanceNode = nodeContainer.GetNode(newInstance); Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstanceNode, newInstance); Assert.AreNotEqual(instanceNode.Guid, newInstanceNode.Guid); // Update to null memberNode.Content.Update(null); Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true); Helper.TestNullObjectReference(memberNode.Content.Reference); // Update back to the initial instance memberNode.Content.Update(instance); Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance); }
public void TestPushIndex() { var obj = new Class { ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)); var targetNode = nodeContainer.GetNode(obj.ListMember[1]); var nodes = new[] { rootNode, rootNode.TryGetChild(nameof(Class.ListMember)), targetNode }; Assert.NotNull(targetNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(targetNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }
public void TestObjectReference() { var nodeContainer = new NodeContainer(); var instance = new TestObject { Name = "Test" }; var container = new ObjectContainer { Instance = instance }; var containerNode = nodeContainer.GetOrCreateNode(container); Helper.TestObjectContentNode(containerNode, container, 1); var memberNode = containerNode.Children.First(); Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instance); var instanceNode = nodeContainer.GetNode(instance); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance); memberNode = instanceNode.Children.First(); Helper.TestMemberContentNode(instanceNode, memberNode, instance, instance.Name, nameof(TestObject.Name), false); }
public void TestListOfNestedStructListsUpdate() { var obj = new ClassWithLists(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); var listRef = ((ReferenceEnumerable)model.GetChild("ListOfNestedStructLists").Content.Reference).Last(); var objRef = ((ReferenceEnumerable)listRef.TargetNode.Content.Reference).Last(); var structNode = container.GetNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(32); Helper.PrintModelContainerContent(container, model); Assert.That(obj.ListOfNestedStructLists[1][0].Struct.SecondValue, Is.EqualTo(32)); Helper.ConsistencyCheck(container, obj); }
public void TestPushIndexAndMember() { var obj = new Class { ListMember = { new Class(), new Class(), new Class() } }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ListMember)).PushIndex(new Index(1)).PushMember(nameof(Class.IntMember)); var targetNode = nodeContainer.GetNode(obj.ListMember[1]); var intNode = targetNode.GetChild(nameof(Class.IntMember)); var nodes = new[] { rootNode, rootNode.GetChild(nameof(Class.ListMember)), targetNode, intNode }; Assert.NotNull(targetNode); Assert.NotNull(intNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); Assert.AreEqual(rootNode, path.RootNode); Assert.AreEqual(intNode, path.GetNode()); var i = 0; foreach (var node in path) { Assert.AreEqual(nodes[i++], node); } Assert.AreEqual(nodes.Length, i); }
public void TestObjectReferenceUpdate() { var nodeContainer = new NodeContainer(); var instance = new TestObject { Name = "Test" }; var container = new ObjectContainer { Instance = instance }; var containerNode = nodeContainer.GetOrCreateNode(container); var memberNode = containerNode.Children.First(); var instanceNode = memberNode.Content.Reference.AsObject.TargetNode; // Update to a new instance var newInstance = new TestObject { Name = "Test2" }; memberNode.Content.Update(newInstance); Helper.TestMemberContentNode(containerNode, memberNode, container, newInstance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstance, false); var newInstanceNode = nodeContainer.GetNode(newInstance); Helper.TestNonNullObjectReference(memberNode.Content.Reference, newInstanceNode, newInstance); Assert.AreNotEqual(instanceNode.Guid, newInstanceNode.Guid); // Update to null memberNode.Content.Update(null); Helper.TestMemberContentNode(containerNode, memberNode, container, null, nameof(ObjectContainer.Instance), true); Helper.TestNullObjectReference(memberNode.Content.Reference); // Update back to the initial instance memberNode.Content.Update(instance); Helper.TestMemberContentNode(containerNode, memberNode, container, instance, nameof(ObjectContainer.Instance), true); Helper.TestNonNullObjectReference(memberNode.Content.Reference, instanceNode, instance); }
/// <inheritdoc /> protected override IObjectNode GetPropertiesRootNode() { return(NodeContainer.GetNode(((UIAssetBase)Asset).Design)); }
public void TestNestedStructItemUpdate() { var obj = new ClassWithLists(); var container = new NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); var objRef = ((ReferenceEnumerable)model.GetChild("NestedStructList").Content.Reference).First(); var structNode = container.GetNode(((ObjectReference)objRef.TargetNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(32); Helper.PrintModelContainerContent(container, model); Assert.That(obj.NestedStructList[0].Struct.SecondValue, Is.EqualTo(32)); //var visitor = new ModelConsistencyCheckVisitor(container.NodeBuilder); //visitor.Check((GraphNode)model, obj, typeof(ClassWithLists), true); Helper.ConsistencyCheck(container, obj); }
public void TestViewModelUpdate() { var obj = new ClassWithStructs(); var container = new NodeContainer(); container.NodeBuilder.PrimitiveTypes.Add(typeof(PrimitiveStruct)); IGraphNode model = container.GetOrCreateNode(obj); Helper.PrintModelContainerContent(container, model); // Modify direct struct via Quantum, check value on actual object var structNode = container.GetNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); structNode.GetChild("SecondValue").Content.Update(15); Assert.That(obj.NestedStruct.SecondValue, Is.EqualTo(15)); // Modify nested struct via Quantum, check value on actual object structNode = container.GetNode(((ObjectReference)structNode.GetChild("Struct").Content.Reference).TargetGuid); structNode.GetChild("FirstValue").Content.Update(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.GetNode(obj); structNode = container.GetNode(((ObjectReference)model.GetChild("NestedStruct").Content.Reference).TargetGuid); Assert.That(structNode.GetChild("SecondValue").Content.Value, Is.EqualTo(10)); structNode = container.GetNode(((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 NodeContainer(); IGraphNode model = container.GetOrCreateNode(obj); 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.GetNode(obj.ClassList[0]), !Is.Null); Assert.That(container.Guids.Count(), Is.EqualTo(18)); Helper.ConsistencyCheck(container, obj); }
public void TestPushTarget() { var obj = new Class { ClassMember = new Class() }; var nodeContainer = new NodeContainer(); var rootNode = nodeContainer.GetOrCreateNode(obj); var path = new GraphNodePath(rootNode).PushMember(nameof(Class.ClassMember)).PushTarget(); var targetNode = nodeContainer.GetNode(obj.ClassMember); var nodes = new[] { rootNode, rootNode.TryGetChild(nameof(Class.ClassMember)), targetNode }; Assert.NotNull(targetNode); Assert.True(path.IsValid); Assert.False(path.IsEmpty); AssertAreEqual(rootNode, path.RootNode); AssertAreEqual(targetNode, path.GetNode()); var i = 0; foreach (var node in path) { AssertAreEqual(nodes[i++], node); } AssertAreEqual(nodes.Length, i); }