Ejemplo n.º 1
0
        public void DataBind_NullMapModelNodes()
        {
            //Arrange
            var model = new NetworkMapModel();

            //Act
            _control.DataBind(model);

            //Assert
            Assert.IsEmpty(_control.Controls);
        }
Ejemplo n.º 2
0
        public void DataBind_WithNodesButNoConnectors()
        {
            //Arrange
            var model = new NetworkMapModel
                {
                    Nodes = new[]
                        {
                            new MapNodeModel(),
                            new MapNodeModel(),
                            new MapNodeModel(),
                        }
                };

            //Act
            _control.DataBind(model);

            //Assert
            Assert.AreEqual(3, _control.Controls.Count);
            var nodeControls = _control.Controls.Cast<Control>().Where(c => c is NodeControl);
            Assert.AreEqual(3, nodeControls.Count());
        }
Ejemplo n.º 3
0
        public void DataBind_WithConnectors()
        {
            //Arrange
            var nodeId1 = Guid.NewGuid();
            var nodeId2 = Guid.NewGuid();
            var nodeId3 = Guid.NewGuid();
            var model = new NetworkMapModel
            {
                Nodes = new[]
                        {
                            new MapNodeModel { NodeId = nodeId1},
                            new MapNodeModel { NodeId = nodeId2},
                            new MapNodeModel { NodeId = nodeId3},
                        },
                Connections = new[]
                    {
                        new NodeConnection { SourceNodeId = nodeId1, TargetNodeId = nodeId2},
                        new NodeConnection { SourceNodeId = nodeId1, TargetNodeId = nodeId3}
                    }
            };

            //Act
            _control.DataBind(model);

            //Assert
            Assert.AreEqual(5, _control.Controls.Count);
        }
Ejemplo n.º 4
0
        public void DataBind_NetworkMapNotNull()
        {
            //Arrange
            var networkMap = new NetworkMapModel();

            //Act
            _form.DataBind(null, networkMap);

            //Assert
            _mockNodeList.Verify(l => l.DataBind(It.IsAny<IEnumerable<NodeModel>>()), Times.Never());
            _mockMapControl.Verify(m => m.DataBind(networkMap));
        }
Ejemplo n.º 5
0
        public void OnLoad(object sender, EventArgs eventArgs)
        {
            if (string.IsNullOrEmpty(_view.FilePath))
                return;

            try
            {
                _mapProvider.Open(_view.FilePath);
            }
            catch (Exception ex)
            {
                throw new OpenNetworkMapException(_view.FilePath, ex);
            }

            if (_mapProvider.Nodes == null || _mapProvider.Nodes.Count == 0)
                return;

            var availableNodes = from n in _mapProvider.Nodes
                                 where n.Position.IsEmpty
                                 select new NodeModel(n);

            var mapModel = new NetworkMapModel
            {
                Connections = _mapProvider.Connections,
                Nodes = from n in _mapProvider.Nodes
                        where !n.Position.IsEmpty
                        select new MapNodeModel(n)
            };

            _view.DataBind(availableNodes, mapModel);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        public void DataBind(IEnumerable<NodeModel> availableNodes, NetworkMapModel model)
        {
            if (availableNodes != null)
                NodeListControl.DataBind(availableNodes);

            if (model != null)
                MapControl.DataBind(model);
        }