public void CreateNetworkNode()
        {
            //Arrange
            var node = new NetworkNode();
            var nodes = new List<NetworkNode>();
            _mockNetworkMapProvider.SetupGet(p => p.Nodes).Returns(nodes);

            //Act
            _presenter.CreateNetworkNode(node);

            //Assert
            Assert.IsTrue(node.Id != Guid.Empty);
            Assert.AreEqual(1, nodes.Count);
        }
示例#2
0
        public void CreateConfig_CreateDirectory()
        {
            var node = new NetworkNode { HostName = "TestNode" };
            const string fileDirectory = "SomeDirectory";
            var filePath = String.Format("{0}\\SomeFile.txt", fileDirectory);
            const string deails = "Node hostname = {0}";
            _configTemplate.Details = string.Format(deails, ConfigTemplate.HostNamePattern);
            _mockFileSystemHelper.Setup(f => f.DirectoryExists(fileDirectory)).Returns(false);

            //Act
            _configTemplate.CreateConfig(node, new NetworkAddress[0], filePath);

            //Assert
            _mockFileSystemHelper.Verify(f => f.CreateDirectory(fileDirectory));
        }
示例#3
0
        public void CreateConfig_HostNameReplacement()
        {
            //Arrange
            var node = new NetworkNode {HostName = "TestNode"};
            const string filePath = "SomeFile.txt";
            const string deails = "Node hostname = {0}";
            _configTemplate.Details = string.Format(deails, ConfigTemplate.HostNamePattern);
            var output = string.Empty;
            _mockFileSystemHelper.Setup(f => f.SaveFileText(filePath, It.IsAny<string>()))
                                 .Callback((string p, string o) => output = o);

            //Act
            _configTemplate.CreateConfig(node, new NetworkAddress[0], filePath);

            //Assert
            Assert.AreEqual(string.Format(deails, node.HostName), output);
        }
示例#4
0
        public void CreateConfig_CredentialsReplacement()
        {
            //Arrange
            var node = new NetworkNode { HostName = "TestNode", Credentials = new NodeCredentials{ UserName = "******", Password = "******" } };
            const string filePath = "SomeFile.txt";
            const string deails = "username:{0} password: {1}";
            _configTemplate.Details = string.Format(deails, ConfigTemplate.UserNamePatthern, ConfigTemplate.PasswordPattern);
            var output = string.Empty;
            _mockFileSystemHelper.Setup(f => f.SaveFileText(filePath, It.IsAny<string>()))
                                 .Callback((string p, string o) => output = o);

            //Act
            _configTemplate.CreateConfig(node, new NetworkAddress[0], filePath);

            //Assert
            Assert.AreEqual(string.Format(deails, node.Credentials.UserName, node.Credentials.Password), output);
        }
示例#5
0
        public void CreateConfig_AddressReplacement()
        {
            //Arrange
            var node = new NetworkNode { HostName ="TestNode", Address = new NetworkAddress { IpAddress = "172.0.0.1", SubnetMask = "255.255.255.0"} };
            const string filePath = "SomeFile.txt";
            const string deails = "node address: {0} {1}";
            _configTemplate.Details = string.Format(deails, ConfigTemplate.SourceIpAddressPattern, ConfigTemplate.SourceSubnetMaskPatthern);
            var output = string.Empty;
            _mockFileSystemHelper.Setup(f => f.SaveFileText(filePath, It.IsAny<string>()))
                                 .Callback((string p, string o) => output = o);

            //Act
            _configTemplate.CreateConfig(node, new NetworkAddress[0], filePath);

            //Assert
            Assert.AreEqual(string.Format(deails, node.Address.IpAddress, node.Address.SubnetMask), output);
        }
示例#6
0
        public void CreateConfig(NetworkNode networkNode, IEnumerable<NetworkAddress> connections, string outputFile)
        {
            var output = Details;

            output = Regex.Replace(output, HostNamePattern, networkNode.HostName, RegexOptions.IgnoreCase);
            if (networkNode.Address != null)
            {
                output = Regex.Replace(output, SourceIpAddressPattern, networkNode.Address.IpAddress,
                                       RegexOptions.IgnoreCase);
                output = Regex.Replace(output, SourceSubnetMaskPatthern, networkNode.Address.SubnetMask,
                                       RegexOptions.IgnoreCase);
            }
            if (networkNode.Credentials != null)
            {
                output = Regex.Replace(output, UserNamePatthern, networkNode.Credentials.UserName, RegexOptions.IgnoreCase);
                output = Regex.Replace(output, PasswordPattern, networkNode.Credentials.Password, RegexOptions.IgnoreCase);
            }

            var routeIdentifier = string.Concat(RouteIdentifier, " (.*)");
            var routeMatch = Regex.Match(output, routeIdentifier, RegexOptions.IgnoreCase);
            if (routeMatch.Groups.Count == 2)
            {
                var routes = new StringBuilder();
                var routePattern = routeMatch.Groups[1].Value;

                if (connections != null)
                {
                    foreach (var remoteAddress in connections)
                    {
                        var route = Regex.Replace(routePattern, DestIpAddressPattern, remoteAddress.IpAddress);
                        route = Regex.Replace(route, DestSubnetMaskPattern, remoteAddress.SubnetMask);
                        routes.Append(route);
                    }
                }
                output = Regex.Replace(output, routeIdentifier, routes.ToString(), RegexOptions.IgnoreCase);
            }

            var outputDirectory = System.IO.Path.GetDirectoryName(outputFile);
            if (!_fileHelper.DirectoryExists(outputDirectory))
                _fileHelper.CreateDirectory(outputDirectory);

            _fileHelper.SaveFileText(outputFile, output);
        }
        public void NodeMovedOnMap()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            const int x = 100;
            const int y = 100;
            var node = new NetworkNode { Id = nodeId };
            _mockNetworkMapProvider.Setup(p => p.FindNode(nodeId)).Returns(node);

            //Act
            _presenter.NodeMovedOnMap(nodeId, x, y);

            //Assert
            Assert.IsTrue(_presenter.IsDirty);
            Assert.AreEqual(x, node.Position.X);
            Assert.AreEqual(y, node.Position.Y);
        }
        public void GetNodeModel_NodeModelReturned()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            const string nodeName = "Test Node";
            var node = new NetworkNode {Id = nodeId, HostName = nodeName};
            _mockNetworkMapProvider
                .Setup(p => p.FindNode(nodeId))
                .Returns(node)
                .Verifiable();

            //Act
            var result = _presenter.GetNodeModel(nodeId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(nodeId, result.NodeId);
            Assert.AreEqual(nodeName, result.Name);
            _mockNetworkMapProvider.Verify();
        }
        public void GetNetworkNode()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var node = new NetworkNode {Id = nodeId};
            _mockNetworkMapProvider
                .Setup(p => p.FindNode(nodeId))
                .Returns(node)
                .Verifiable();

            //Act
            var result = _presenter.GetNetworkNode(nodeId);

            //Assert
            Assert.AreEqual(node,result);
            _mockNetworkMapProvider.Verify();
        }
示例#10
0
        public void GenerateConfig_Successfull()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var node = new NetworkNode { Id = nodeId, HostName = "SomeNode" };
            _mockNetworkMapProvider
                .Setup(p => p.FindNode(nodeId))
                .Returns(node)
                .Verifiable();
            var addresses = new[] {new NetworkAddress()};
            _mockNetworkMapProvider
                .Setup(p => p.GetNodeDestinationAddresses(nodeId))
                .Returns(addresses)
                .Verifiable();
            const string configTemplateName = "SomeConfig.txt";
            _mockSettings
                .SetupGet(s => s.ConfigTemplateFile)
                .Returns(configTemplateName)
                .Verifiable();
            var configTemplate = new Mock<IConfigTemplate>();
            _mockNetworkConfigurationProvider
                .Setup(p => p.OpenConfigTemplate(configTemplateName))
                .Returns(configTemplate.Object)
                .Verifiable();
            const string configExtension = "txt";
            _mockSettings
                .SetupGet(s => s.ConfigFileExtension)
                .Returns(configExtension)
                .Verifiable();
            const string defaultConfigOutput = "TestConfig";
            _mockSettings
                .SetupGet(s => s.DefaultConfigFileOutputDirectory)
                .Returns(defaultConfigOutput)
                .Verifiable();
            var outputPath = System.IO.Path.Combine(defaultConfigOutput,
                                                    string.Format("{0}.{1}", node.HostName, configExtension));

            //Act
            _presenter.GenerateConfig(nodeId);

            //Assert
            _mockNetworkMapProvider.Verify();
            _mockSettings.Verify();
            _mockNetworkConfigurationProvider.Verify();
            configTemplate.Verify(c => c.CreateConfig(node, addresses, outputPath));
        }
示例#11
0
        public void GenerateConfig_ConfigTemplateNotFound()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var node = new NetworkNode {Id = nodeId};
            _mockNetworkMapProvider
                .Setup(p => p.FindNode(nodeId))
                .Returns(node)
                .Verifiable();
            const string configTemplateName = "SomeConfig.txt";
            _mockSettings
                .SetupGet(s => s.ConfigTemplateFile)
                .Returns(configTemplateName)
                .Verifiable();
            _mockNetworkConfigurationProvider
                .Setup(p => p.OpenConfigTemplate(configTemplateName))
                .Returns(() => null)
                .Verifiable();

            //Act
            _presenter.GenerateConfig(nodeId);

            //Assert
            _mockNetworkMapProvider.Verify();
            _mockSettings.Verify();
            _mockNetworkConfigurationProvider.Verify();
            _mockSettings.VerifyGet(s => s.ConfigFileExtension, Times.Never());
            _mockSettings.VerifyGet(s => s.DefaultConfigFileOutputDirectory, Times.Never());
        }
示例#12
0
 public void ShowNodeForm(NetworkNode node)
 {
     var nodeForm = new NodeForm();
     nodeForm.OkClicked += OnNodeFormOkClicked;
     nodeForm.NodeId = node.Id;
     nodeForm.HostName = node.HostName;
     nodeForm.Description = node.Description;
     nodeForm.Address = node.Address;
     nodeForm.Credentials = node.Credentials;
     _formInteractionHelper.ShowForm(nodeForm, this);
 }
示例#13
0
        public void UpdateNetworkNode_NodeNotFound()
        {
            //Arrange
            var node = new NetworkNode {Id = Guid.NewGuid()};
            var nodes = new List<NetworkNode>();
            _mockNetworkMapProvider.SetupGet(p => p.Nodes).Returns(nodes);
            _mockNetworkMapProvider.Setup(p => p.FindNodeIndex(node.Id)).Returns(-1);

            //Act
            _presenter.UpdateNetworkNode(node);

            //Assert
            Assert.AreEqual(1, nodes.Count);
            Assert.IsTrue(_presenter.IsDirty);
        }
示例#14
0
        public void CreateConfig_RouteReplacement()
        {
            //Arrange
            var node = new NetworkNode { HostName = "TestNode" };
            var addresses = new[]
                {
                    new NetworkAddress {IpAddress = "172.0.0.1", SubnetMask = "255.255.255.0"},
                    new NetworkAddress {IpAddress = "172.0.0.2", SubnetMask = "255.255.255.1"}
                };
            const string filePath = "SomeFile.txt";
            const string deails = "{0} ip route {1} {2}\r\n";
            _configTemplate.Details = string.Format(deails, ConfigTemplate.RouteIdentifier, ConfigTemplate.DestIpAddressPattern, ConfigTemplate.DestSubnetMaskPattern);
            var output = string.Empty;
            _mockFileSystemHelper.Setup(f => f.SaveFileText(filePath, It.IsAny<string>()))
                                 .Callback((string p, string o) => output = o);

            //Act
            _configTemplate.CreateConfig(node, addresses, filePath);

            //Assert
            foreach (var networkAddress in addresses)
            {
                var route = string.Format("ip route {0} {1}", networkAddress.IpAddress, networkAddress.SubnetMask);
                Assert.IsTrue(output.Contains(route));
            }
        }
示例#15
0
        public void DeleteNetworkNode()
        {
            //Arrange
            var node = new NetworkNode { Id = Guid.NewGuid() };
            var nodes = new List<NetworkNode> { node };
            _mockNetworkMapProvider.SetupGet(p => p.Nodes).Returns(nodes);
            _mockNetworkMapProvider.Setup(p => p.FindNodeIndex(node.Id)).Returns(0);

            //Act
            _presenter.DeleteNetworkNode(node.Id);

            //Assert
            Assert.AreEqual(0, nodes.Count);
            Assert.IsTrue(_presenter.IsDirty);
        }
示例#16
0
        public void OnEditNode_NodeFormShown()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var eventArgs = new NodeEventArgs { NodeId = nodeId };
            var networkNode = new NetworkNode {Id = nodeId};
            _mockPresenter.Setup(p => p.GetNetworkNode(nodeId)).Returns(networkNode);

            //Act
            _form.OnEditNode(null, eventArgs);

            //Assert
            _mockPresenter.Verify(p => p.GetNetworkNode(nodeId));
            _mockFormInteractionHelper.Verify(f => f.ShowForm(It.IsAny<NodeForm>(), _form));
        }
示例#17
0
 public void UpdateNetworkNode(NetworkNode node)
 {
     var nodeIndex = _mapProvider.FindNodeIndex(node.Id);
     if (nodeIndex < 0)
     {
         _mapProvider.Nodes.Add(node);
     }
     else
     {
         if (node.Position.IsEmpty)
         {
             var currentNode = _mapProvider.Nodes[nodeIndex];
             node.Position = currentNode.Position;
         }
         _mapProvider.Nodes[nodeIndex] = node;
     }
     IsDirty = true;
 }
示例#18
0
 public void CreateNetworkNode(NetworkNode node)
 {
     node.Id = Guid.NewGuid();
     _mapProvider.Nodes.Add(node);
     IsDirty = true;
 }
示例#19
0
 public NodeModel(NetworkNode node)
 {
     NodeId = node.Id;
     Name = node.HostName;
 }
示例#20
0
        public void NodeRemovedFromMap()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var node = new NetworkNode { Id = nodeId };
            var connections = new List<NodeConnection>
                {
                    new NodeConnection {SourceNodeId = node.Id, TargetNodeId = Guid.NewGuid()}
                };
            _mockNetworkMapProvider.Setup(p => p.FindNode(nodeId)).Returns(node);
            _mockNetworkMapProvider.SetupGet(p => p.Connections).Returns(connections);

            //Act
            _presenter.NodeRemovedFromMap(nodeId);

            //Assert
            Assert.IsTrue(_presenter.IsDirty);
            Assert.IsTrue(node.Position.IsEmpty);
            Assert.IsEmpty(connections);
        }
        public void GetNodeDestinationAddresses_TargetIsTarget()
        {
            //Arrange
            var nodeId = Guid.NewGuid();
            var targetNode = new NetworkNode
                {
                    Id = Guid.NewGuid(),
                    Address = new NetworkAddress { IpAddress = "172.0.0.1", SubnetMask = "255.255.255.0" }
                };
            var connection = new NodeConnection { SourceNodeId = nodeId, TargetNodeId = targetNode.Id };
            _networkMapProvider.Connections.Add(connection);
            _networkMapProvider.Nodes.Add(targetNode);

            //Act
            var results = _networkMapProvider.GetNodeDestinationAddresses(nodeId);

            //Assert
            Assert.AreEqual(1, results.Count());
            var resultAddress = results.First();
            Assert.AreEqual(targetNode.Address.IpAddress, resultAddress.IpAddress);
            Assert.AreEqual(targetNode.Address.SubnetMask, resultAddress.SubnetMask);
        }
示例#22
0
        public void UpdateNetworkNode()
        {
            //Arrange
            var node = new NetworkNode { Id = Guid.NewGuid(), HostName = "Test" };
            var nodes = new List<NetworkNode> { new NetworkNode() };
            _mockNetworkMapProvider.SetupGet(p => p.Nodes).Returns(nodes);
            _mockNetworkMapProvider.Setup(p => p.FindNodeIndex(node.Id)).Returns(0);

            //Act
            _presenter.UpdateNetworkNode(node);

            //Assert
            Assert.AreEqual(node, nodes[0]);
            Assert.IsTrue(_presenter.IsDirty);
        }
        public void NodesTest()
        {
            //Arrange
            var node = new NetworkNode();

            //Act
            _networkMapProvider.Nodes.Add(node);

            //Assert
            Assert.AreEqual(1, _networkMapProvider.Nodes.Count);
            Assert.AreEqual(node, _networkMapProvider.Nodes[0]);
        }
        public void FindNodeIndex_NodeFound()
        {
            //Arrange
            var node = new NetworkNode { Id = Guid.NewGuid() };
            _networkMapProvider.Nodes.Add(node);

            //Act
            var result = _networkMapProvider.FindNodeIndex(node.Id);

            //Assert
            Assert.AreEqual(0, result);
        }
示例#25
0
        public void OnNodeFormOkClicked(object sender, EventArgs eventArgs)
        {
            var nodeForm = sender as NodeForm;

            if (nodeForm == null)
                return;

            var node = new NetworkNode
                {
                    Id = nodeForm.NodeId,
                    HostName = nodeForm.HostName,
                    Description = nodeForm.Description,
                    Address = nodeForm.Address,
                    Credentials = nodeForm.Credentials
                };

            if (node.Id == Guid.Empty)
            {
                _presenter.CreateNetworkNode(node);
                NodeListControl.AddNode(new NodeModel(node));
            }
            else
            {
                _presenter.UpdateNetworkNode(node);
                NodeListControl.UpdateNode(new NodeModel(node));
                MapControl.UpdateNode(new NodeModel(node));
            }

            _formInteractionHelper.CloseForm(nodeForm);
        }
示例#26
0
 public MapNodeModel(NetworkNode node)
     : base(node)
 {
     Position = node.Position;
 }
        public void FindNode_NodeReturned()
        {
            //Arrange
            var node = new NetworkNode {Id = Guid.NewGuid()};
            _networkMapProvider.Nodes.Add(node);

            //Act
            var results = _networkMapProvider.FindNode(node.Id);

            //Assert
            Assert.AreEqual(node,results);
        }