public void Test_CreateNodeFromOutputPort_NoConnection(TestingMode testingMode) { var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel); Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb); var db = gedb.Build(); var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0]; var node0 = GraphModel.CreateNode <Type1FakeNodeModel>("Node0", Vector2.zero); var output0 = node0.Output; TestPrereqCommandPostreq(testingMode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); return(new CreateNodeFromPortCommand(new[] { output0 }, Vector2.down, item)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(0)); var newNode = GetNode(1); Assert.That(newNode, Is.TypeOf <Type0FakeNodeModel>()); var portModel = node0.OutputsByDisplayOrder.First(); Assert.That(portModel?.GetConnectedPorts().Count(), Is.EqualTo(0)); }); }
public void Test_CreateNodeFromSearcherCommand([Values] TestingMode mode) { var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel); Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb); var db = gedb.Build(); var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0]; TestPrereqCommandPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(0)); return(new CreateNodeFromSearcherCommand(new Vector2(100, 200), item, new SerializableGUID("0123456789abcdef0123456789abcdef"))); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); Assert.That(GraphModel.NodeModels.First(), Is.TypeOf <Type0FakeNodeModel>()); Assert.AreEqual(new SerializableGUID("0123456789abcdef0123456789abcdef"), GraphModel.NodeModels.First().Guid); Assert.That(GraphModel.NodeModels.First().Position, Is.EqualTo(new Vector2(100, 200))); } ); }
public void TestCreateNodeOnEdge_WithOutputNodeConnectedToUnknown([Values] TestingMode mode) { var constantNode = GraphModel.CreateConstantNode(typeof(int).GenerateTypeHandle(), "int1", Vector2.zero); var addNode = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero); GraphModel.CreateEdge(addNode.Input0, constantNode.OutputPort); GraphModel.CreateEdge(addNode.Input1, constantNode.OutputPort); var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel); Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb); var db = gedb.Build(); var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0]; TestPrereqCommandPostreq(mode, () => { RefreshReference(ref addNode); RefreshReference(ref constantNode); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(addNode, Is.Not.Null); Assert.That(addNode.Input0, Is.ConnectedTo(constantNode.OutputPort)); var edge = GraphModel.EdgeModels.First(); return(new CreateNodeOnEdgeCommand(edge, Vector2.zero, item)); }, () => { RefreshReference(ref addNode); RefreshReference(ref constantNode); var multiplyNode = GraphModel.NodeModels.OfType <Type0FakeNodeModel>().ToList()[1]; Assert.IsNotNull(multiplyNode); Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(3)); Assert.That(constantNode.OutputPort, Is.ConnectedTo(multiplyNode.Input0)); Assert.That(multiplyNode.Output0, Is.ConnectedTo(addNode.Input0)); Assert.That(constantNode.OutputPort, Is.Not.ConnectedTo(addNode.Input0)); } ); }
public void TestCreateNodeOnEdge_BothPortsConnected([Values] TestingMode mode) { var constant = GraphModel.CreateConstantNode(typeof(int).GenerateTypeHandle(), "int", Vector2.zero); var unary = GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero); var edge = GraphModel.CreateEdge(unary.Input0, constant.OutputPort); var gedb = new GraphElementSearcherDatabase(Stencil, GraphModel); Type0FakeNodeModel.AddToSearcherDatabase(GraphModel, gedb); var db = gedb.Build(); var item = (GraphNodeModelSearcherItem)db.Search(nameof(Type0FakeNodeModel))[0]; TestPrereqCommandPostreq(mode, () => { RefreshReference(ref unary); RefreshReference(ref constant); edge = GetEdge(0); Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GetEdgeCount(), Is.EqualTo(1)); Assert.That(unary.Input0, Is.ConnectedTo(constant.OutputPort)); return(new CreateNodeOnEdgeCommand(edge, Vector2.zero, item)); }, () => { RefreshReference(ref unary); RefreshReference(ref constant); RefreshReference(ref edge); var unary2 = GraphModel.NodeModels.OfType <Type0FakeNodeModel>().ToList()[1]; Assert.IsNotNull(unary2); Assert.That(GetNodeCount(), Is.EqualTo(3)); Assert.That(GetEdgeCount(), Is.EqualTo(2)); Assert.That(constant.OutputPort, Is.ConnectedTo(unary2.Input0)); Assert.That(unary2.Output0, Is.ConnectedTo(unary.Input0)); Assert.IsFalse(GraphModel.EdgeModels.Contains(edge)); } ); }