public void AddNode_Depends_AddCycle_Fail()
        {
            // Empty tree
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            InstallMethods.AddNode(tree, "NodeC", new List <string>()
            {
                "NodeA"
            });
            InstallMethods.AddNode(tree, "NodeB", new List <string>()
            {
                "NodeC"
            });
            var r3 = InstallMethods.AddNode(tree, "NodeA", new List <string>()
            {
                "NodeB"
            });

            Assert.IsFalse(r3.Success == true);
            Assert.IsTrue(r3.Tree.Nodes.Count() == 3);
            Assert.IsTrue(r3.Tree.Nodes["NodeA"].Dependents.Count() == 1);
            Assert.IsTrue(r3.Tree.Nodes["NodeB"].Dependents.Count() == 0);
            Assert.IsTrue(r3.Tree.Nodes["NodeC"].Dependents.Count() == 1);
        }
        public void DetectDepends_None_False()
        {
            var NodeA = new InstallNode("NodeA");
            var NodeB = new InstallNode("NodeB");
            var NodeC = new InstallNode("NodeC");

            NodeA.DependsOn.Add(NodeC);
            NodeB.DependsOn.Add(NodeC);
            var resp = InstallMethods.DetectDepends(NodeA, NodeB);

            Assert.IsFalse(resp);
        }
        public void DetectDepends_True()
        {
            var NodeA = new InstallNode("NodeA");
            var NodeB = new InstallNode("NodeB");

            NodeA.DependsOn.Add(NodeB);
            NodeB.DependsOn.Add(NodeA);

            var resp = InstallMethods.DetectDepends(NodeA, NodeB);

            Assert.IsTrue(resp);
        }
        public void InstallNode_Name_NotExist_Fail()
        {
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            InstallMethods.AddNode(tree, "NodeC", new List <string>()
            {
                "NodeA"
            });
            var resp = InstallMethods.InstallNodeInTree(tree, "notexist");

            Assert.IsFalse(resp.Success);
        }
        public void AddNode_NewNode_DependsNew()
        {
            // Empty tree
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            string dependName        = "testChild";
            string dependNotExisting = "notExist";
            var    r3 = InstallMethods.AddNode(tree, dependName, new List <string> {
                dependNotExisting
            });

            Assert.IsTrue(r3.Success == true);
            Assert.IsTrue(r3.Tree.Nodes.Count() == 2);
            Assert.IsTrue(r3.Tree.Nodes[dependNotExisting].Dependents.Count() == 1);
            Assert.AreSame(r3.Tree.Nodes[dependNotExisting].Dependents[0], r3.Tree.Nodes[dependName]);
        }
        public void AddNode_Existing_Node()
        {
            string name = "testNode";
            // Empty tree
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            var response = InstallMethods.AddNode(tree, name, null);
            var r2       = InstallMethods.AddNode(tree, name, null);

            var firstNode = response.Tree.Nodes.FirstOrDefault();

            Assert.IsTrue(firstNode.Value.Name == name);
            Assert.IsTrue(r2.Success == true);
            Assert.IsTrue(r2.Tree.Nodes.Count() == 1);
            Assert.IsTrue(firstNode.Value.Dependents.Count() == 0);
        }
        public void AddNode_NewNode_DependsExisting()
        {
            string name = "testNode";
            // Empty tree
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            var response = InstallMethods.AddNode(tree, name, null);

            string dependName = "testChild";
            var    r3         = InstallMethods.AddNode(tree, dependName, new List <string> {
                name
            });

            Assert.IsTrue(r3.Success == true);
            Assert.IsTrue(r3.Tree.Nodes.Count() == 2);
            Assert.IsTrue(r3.Tree.Nodes[name].Dependents.Count() == 1);
            Assert.AreSame(r3.Tree.Nodes[name].Dependents[0], r3.Tree.Nodes[dependName]);
        }
        public void InstallTest()
        {
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            InstallMethods.AddNode(tree, "Http", new List <string>()
            {
                "TCP"
            });
            InstallMethods.AddNode(tree, "Https", new List <string>()
            {
                "TCP"
            });
            InstallMethods.AddNode(tree, "Chrome", new List <string>()
            {
                "Http", "Https", "GLib"
            });
            var resp = InstallMethods.InstallNodeInTree(tree, "Chrome");

            Assert.IsTrue(resp.Success);
        }
        public void UninstallTest()
        {
            var tree = new InstallTree {
                Nodes = new Dictionary <string, InstallNode>()
            };

            InstallMethods.AddNode(tree, "Http", new List <string>()
            {
                "TCP"
            });
            InstallMethods.AddNode(tree, "Https", new List <string>()
            {
                "TCP"
            });
            InstallMethods.AddNode(tree, "Chrome", new List <string>()
            {
                "Http", "Https", "GLib"
            });
            var resp = InstallMethods.InstallNodeInTree(tree, "Chrome");
            var r2   = InstallMethods.UnInstallNodeInTree(tree, "Http");
            var r3   = InstallMethods.UnInstallNodeInTree(tree, "Chrome");
            var r4   = InstallMethods.UnInstallNodeInTree(tree, "TCP");
        }
        public void AddNode_NullTreeError()
        {
            var response = InstallMethods.AddNode(null, "test", null);

            Assert.IsFalse(response.Success);
        }