public void Disconnect_Should_Throw_WhenConnectionNotInGraph() { var graph = new GraphModel(GraphTypeWithConnections); var connection = new ConnectionModel(Substitute.For <IConnectionType>()); Assert.That(() => graph.Disconnect(connection), Throws.InvalidOperationException); }
public void Disconnect_Should_Batch_WithConnect() { var graph = new GraphModel(Substitute.For <IGraphType>()); var node1 = new NodeModel(Substitute.For <INodeType>()); var node2 = new NodeModel(Substitute.For <INodeType>()); var port1 = PortModel.Create <string>("Out1", PortDirection.Output); var port2 = PortModel.Create <string>("Out2", PortDirection.Output); var port3 = PortModel.Create <string>("In1", PortDirection.Input); var port4 = PortModel.Create <string>("In2", PortDirection.Input); node1.AddPort(port1); node1.AddPort(port2); node2.AddPort(port3); node2.AddPort(port4); graph.AddNode(node1); graph.AddNode(node2); var connection1 = graph.Connect(port1, port3); var connection2 = graph.Connect(port2, port4); IReadOnlyList <ConnectionModel> removedConnections = null; graph.GraphChanged += (an, rn, ac, rc) => { removedConnections = rc; }; using (graph.BeginChangeSet()) { graph.Disconnect(connection1); graph.Disconnect(connection2); var connection3 = graph.Connect(port1, port3); Assert.That(removedConnections, Is.Null); Assert.That(connection3, Is.SameAs(connection1)); } Assert.That(removedConnections, Is.Not.Null); Assert.That(removedConnections, Is.EquivalentTo(new[] { connection2 })); }
public void Disconnect_Should_Succeed() { var graph = new GraphModel(GraphTypeWithConnections); var nodeType = Substitute.For <INodeType>(); var node1 = new NodeModel(nodeType); var node2 = new NodeModel(nodeType); var port1 = PortModel.Create <string>("Out", PortDirection.Output); var port2 = PortModel.Create <string>("In", PortDirection.Input); node1.AddPort(port1); node2.AddPort(port2); graph.AddNode(node1); graph.AddNode(node2); var connection = graph.Connect(port1, port2); IReadOnlyList <ConnectionModel> list = null; graph.GraphChanged += (an, rn, ac, rc) => { list = rc; }; graph.Disconnect(connection); Assert.That(graph.Connections, Does.Not.Contains(connection)); Assert.That(port1.Connections, Does.Not.Contains(connection)); Assert.That(port2.Connections, Does.Not.Contains(connection)); Assert.That(connection.From, Is.Null); Assert.That(connection.To, Is.Null); Assert.That(list, Is.Not.Null); Assert.That(list.Count, Is.EqualTo(1)); Assert.That(list, Does.Contain(connection)); }
public void Disconnect_Should_Throw_WhenNullConnection() { var graph = new GraphModel(GraphTypeWithConnections); Assert.That(() => graph.Disconnect(null), Throws.ArgumentNullException); }