public void OnMouseMove_NotCrossCursor() { //Arrange var eventArgs = new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0); var connector = new Connector(_control); _CurrentContectorField.SetValue(_control, connector); //Act _control.OnMouseMove(null, eventArgs); //Assert Assert.IsTrue(connector.LineShape.EndPoint.IsEmpty); }
public void StopNodeConnector() { //Arrange var nodeControl = new NodeControl(); nodeControl.ConnectingNodes = true; _control.Controls.Add(nodeControl); _control.Controls.Add(new TextBox()); var connector = new Connector(_control); _CurrentContectorField.SetValue(_control, connector); //Act _control.StopNodeConnector(); //Assert Assert.IsFalse(nodeControl.ConnectingNodes); Assert.IsNull(_CurrentContectorField.GetValue(_control)); Assert.AreEqual(Cursors.Default, _control.Cursor); }
public void OnConnectorDelete_WithConnectionRemovedHandler() { //Arrange var sourceNode = Guid.NewGuid(); var targetNode = Guid.NewGuid(); var sourceNodeControl = new Mock<INodeControlView>(); sourceNodeControl.SetupGet(n => n.NodeId).Returns(sourceNode); sourceNodeControl.SetupGet(n => n.CenterPosition).Returns(new Point()); var targetNodeControl = new Mock<INodeControlView>(); targetNodeControl.SetupGet(n => n.NodeId).Returns(targetNode); targetNodeControl.SetupGet(n => n.CenterPosition).Returns(new Point()); var connector = new Connector(_control); connector.SetSourceNode(sourceNodeControl.Object); connector.SetTargetNode(targetNodeControl.Object); NodeConnectionEventArgs eventArgs = null; _control.ConnectionRemoved += (sender, args) => eventArgs = args; //Act _control.OnConnectorDelete(connector, EventArgs.Empty); //Assert Assert.IsNotNull(eventArgs); Assert.AreEqual(sourceNode, eventArgs.SourceNodeId); Assert.AreEqual(targetNode, eventArgs.TargetNodeId); }
public void StopNodeConnector() { Cursor = Cursors.Default; foreach (var control in Controls) { var nodeControl = control as NodeControl; if (nodeControl != null) nodeControl.ConnectingNodes = false; } if (_CurrentConnector != null) { if (!_CurrentConnector.IsConnected) _CurrentConnector.Dispose(); _CurrentConnector = null; } }
//TODO: create unit tests public void OnNodeConnect(object sender, EventArgs e) { var nodeControl = (NodeControl) sender; if (_CurrentConnector == null) { _CurrentConnector = new Connector(this); _CurrentConnector.Delete += OnConnectorDelete; _CurrentConnector.SetSourceNode(nodeControl); } else { _CurrentConnector.SetTargetNode(nodeControl); Controls.Add(_CurrentConnector); if (ConnectionAdded != null) { var eventArgs = new NodeConnectionEventArgs { SourceNodeId = _CurrentConnector.SourceNodeId, TargetNodeId = _CurrentConnector.TargetNodeId }; ConnectionAdded(this, eventArgs); } StopNodeConnector(); } }
public void DataBind(NetworkMapModel model) { if (model == null || model.Nodes == null) return; var nodeControls = new List<NodeControl>(); foreach (var node in model.Nodes) { var nodeControl = CreateNodeControl(node); nodeControls.Add(nodeControl); Controls.Add(nodeControl); } if (model.Connections == null) return; foreach (var connection in model.Connections) { var sourceControl = nodeControls.FirstOrDefault(n => n.NodeId == connection.SourceNodeId); var targetControl = nodeControls.FirstOrDefault(n => n.NodeId == connection.TargetNodeId); if (sourceControl == null || targetControl == null) continue; var connector = new Connector(this); connector.SetSourceNode(sourceControl); connector.SetTargetNode(targetControl); connector.Delete += OnConnectorDelete; Controls.Add(connector); } }
public void SetUp() { _mapControl = new MapControl(); _connector = new Connector(_mapControl); }