Пример #1
0
        public void Tree_Compare_Reduce_ParentTwoChildren_OneChildRemoved()
        {
            var first = PrtgNode.Probe(Probe("Parent"),
                                       PrtgNode.Group(Group("Child1")),
                                       PrtgNode.Group(Group("Child2"))
                                       );

            var second = PrtgNode.Probe(Probe("Parent"),
                                        PrtgNode.Group(Group("Child1"))
                                        );

            ValidateReduce(
                first, second,
                new[] { new Validation(TreeNodeDifference.NumberOfChildren, c => c.Difference) },
                new[]
            {
                "<Yellow>Parent</Yellow>",
                "└──<Red>Child2</Red>"
            },
                null,
                new[]
            {
                "<Yellow>Parent</Yellow>",
                "└──<Green>Child2</Green>"
            }
                );
        }
Пример #2
0
        public void Tree_Compare_HasMoreChildren()
        {
            var first = PrtgNode.Probe(Probe(),
                                       PrtgNode.Group(Group()),
                                       PrtgNode.Group(Group("Linux"))
                                       );

            var second = PrtgNode.Probe(Probe(),
                                        PrtgNode.Group(Group())
                                        );

            Validate(first, second, new[]
            {
                new Validation(TreeNodeDifference.NumberOfChildren, c => c.Difference),
                new Validation(TreeNodeDifference.Removed, c => c["Linux"].Difference)
            }, new[]
            {
                new Validation(TreeNodeDifference.NumberOfChildren, c => c.Difference),
                new Validation(TreeNodeDifference.Added, c => c["Linux"].Difference)
            });

            ValidatePretty(first, second, new[]
            {
                "<Yellow>Local Probe</Yellow>",
                "├──Servers",
                "└──<Red>Linux</Red>"
            }, new[]
            {
                "<Yellow>Local Probe</Yellow>",
                "├──Servers",
                "└──<Green>Linux</Green>"
            });
        }
Пример #3
0
        public void Tree_Compare_ChildHasDifference()
        {
            var first = PrtgNode.Probe(Probe(),
                                       PrtgNode.Group(Group())
                                       );

            var second = PrtgNode.Probe(Probe(),
                                        PrtgNode.Group(Group("Linux"))
                                        );

            Validate(
                first, second,
                new[] { new Validation(TreeNodeDifference.Name, c => c["Servers"].Difference) },
                new[] { new Validation(TreeNodeDifference.Name, c => c["Linux"].Difference) }
                );

            ValidatePretty(
                first, second,
                new[] {
                "Local Probe",
                "└──<Yellow>Servers (Renamed 'Linux')</Yellow>"
            },
                new[] {
                "Local Probe",
                "└──<Yellow>Linux (Renamed 'Servers')</Yellow>"
            }
                );
        }
Пример #4
0
        public void Tree_PrettyPrint_TwoChildren_OneHasTwoChildren_WithOneGrandChildCollectionEach()
        {
            var tree = PrtgNode.Group(Group("PRTG Network Monitor", 0),
                                      PrtgNode.Probe(Probe("Probe 1"),
                                                     PrtgNode.Group(Group(),
                                                                    PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger()))
                                                                    ),
                                                     PrtgNode.Group(Group("Linux"),
                                                                    PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger("Ticket Notification")))
                                                                    )
                                                     ),
                                      PrtgNode.Probe(Probe("Probe 2"))
                                      );

            var expected = new[]
            {
                "PRTG Network Monitor",
                "├──Probe 1",
                "│  ├──Servers",
                "│  │  └──Email to Admin",
                "│  └──Linux",
                "│     └──Ticket Notification",
                "└──Probe 2"
            };

            Validate(tree, expected);
        }
Пример #5
0
        public void Tree_PrettyPrint_TwoChildren_OneHasTwoChildren_WithOneGrandChildEach()
        {
            var tree = PrtgNode.Group(Group("PRTG Network Monitor", 0),
                                      PrtgNode.Probe(Probe("Probe 1"),
                                                     PrtgNode.Group(Group(),
                                                                    PrtgNode.Device(Device())
                                                                    ),
                                                     PrtgNode.Group(Group("Linux"),
                                                                    PrtgNode.Device(Device("arch-1"))
                                                                    )
                                                     ),
                                      PrtgNode.Probe(Probe("Probe 2"))
                                      );

            var expected = new[]
            {
                "PRTG Network Monitor",
                "├──Probe 1",
                "│  ├──Servers",
                "│  │  └──dc-1",
                "│  └──Linux",
                "│     └──arch-1",
                "└──Probe 2"
            };

            Validate(tree, expected);
        }
Пример #6
0
        public void Tree_Compare_Reduce_TreeDifference()
        {
            //We wanna make sure we're reducing on the TreeDifference, not the regular Difference.
            //If we're reducing on the regular Difference, dc-1/2 gets reduced to have no children, but
            //Servers doesn't have a difference so doesn't get replaced under Local Probe

            var first = PrtgNode.Probe(Probe("Local Probe"),
                                       PrtgNode.Group(Group("Servers"),
                                                      PrtgNode.Device(Device("dc-1", 3001),
                                                                      PrtgNode.Sensor(Sensor("Sensor1", 4001),
                                                                                      DefaultProperty
                                                                                      ),
                                                                      PrtgNode.Sensor(Sensor("Sensor2", 4002))
                                                                      )
                                                      )
                                       );

            var second = PrtgNode.Probe(Probe("Local Probe"),
                                        PrtgNode.Group(Group("Servers"),
                                                       PrtgNode.Device(Device("dc-2", 3001),
                                                                       PrtgNode.Sensor(Sensor("Sensor1", 4001),
                                                                                       DefaultProperty
                                                                                       ),
                                                                       PrtgNode.Sensor(Sensor("Sensor2", 4002))
                                                                       )
                                                       )
                                        );

            var comparison = first.CompareTo(second);
            var reduced    = comparison.Reduce();
            var list       = reduced.DescendantNodesAndSelf().ToList();

            Assert.AreEqual(3, list.Count);
        }
Пример #7
0
        public void Tree_Builds_OrdersChildPositions()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.TriggerCollection(
                                          PrtgNode.Trigger(Trigger("Trigger1")),
                                          PrtgNode.Trigger(Trigger("Trigger2"))
                                          ),
                                      PrtgNode.Group(Group("Servers", position: 3)),
                                      PrtgNode.Device(Device("dc-1", position: 1),
                                                      PrtgNode.Sensor(Sensor("Sensor2", position: 2)),
                                                      PrtgNode.Sensor(Sensor("Sensor1", position: 1))
                                                      ),
                                      PrtgNode.Trigger(Trigger("Trigger3")),
                                      PrtgNode.Device(Device("dc-2", position: 2))
                                      );

            TreePrettyPrintTests.Validate(tree, new[]
            {
                "Local Probe",
                "├──dc-1",
                "│  ├──Sensor1",
                "│  └──Sensor2",
                "├──dc-2",
                "├──Servers",
                "├──Trigger1",
                "├──Trigger2",
                "└──Trigger3"
            });
        }
Пример #8
0
        public void Tree_Compare_Reduce_NoDifference()
        {
            var node = PrtgNode.Probe(Probe("Parent"),
                                      PrtgNode.Group(Group("Child1"))
                                      );

            var comparison = node.CompareTo(node).Reduce();

            Assert.IsNull(comparison);
        }
Пример #9
0
        public void Tree_NodeList_RemoveAt()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device()),
                                       PrtgNode.Group(Group())
                                       );

            var newList = probe.Children.RemoveAt(0);

            Assert.AreEqual(1, newList.Count);

            Assert.AreEqual(newList[0].Name, "Servers");
        }
Пример #10
0
        public void Tree_PrettyPrint_SingleChild()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group())
                                      );

            var expected = new[]
            {
                "Local Probe",
                "└──Servers"
            };

            Validate(tree, expected);
        }
Пример #11
0
        public void Tree_NodeList_Replace()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            var newChild = PrtgNode.Group(Group());

            var newList = probe.Children.Replace(probe["dc-1"], newChild);

            Assert.AreNotEqual(probe.Children, newList);
            Assert.AreEqual(1, newList.Count);
            Assert.AreEqual("Servers", newList[0].Name);
        }
Пример #12
0
        public void Tree_Compare_ReplaceChildWithGrandChild_With_ChildWithGrandChild()
        {
            var first = PrtgNode.Probe(Probe(),
                                       PrtgNode.Group(Group()),
                                       PrtgNode.Group(Group("Windows"),
                                                      PrtgNode.Device(Device())
                                                      )
                                       );

            var second = PrtgNode.Probe(Probe(),
                                        PrtgNode.Group(Group()),
                                        PrtgNode.Group(Group("Linux", 2002),
                                                       PrtgNode.Device(Device("arch-1"))
                                                       )
                                        );

            Validate(first, second, new[]
            {
                new Validation(TreeNodeDifference.None, c => c.Difference),
                new Validation(TreeNodeDifference.Removed, c => c["Windows"].Difference),
                new Validation(TreeNodeDifference.Added, c => c["Linux"].Difference),
                new Validation(TreeNodeDifference.Added, c => c["Linux"]["arch-1"].Difference)
            }, new[]
            {
                new Validation(TreeNodeDifference.None, c => c.Difference),
                new Validation(TreeNodeDifference.Added, c => c["Windows"].Difference),
                new Validation(TreeNodeDifference.Removed, c => c["Linux"].Difference),
                new Validation(TreeNodeDifference.Removed, c => c["Linux"]["arch-1"].Difference)
            });

            ValidatePretty(first, second, new[]
            {
                "Local Probe",
                "├──Servers",
                "├──<Red>Windows</Red>",
                "│  └──<Red>dc-1</Red>",
                "└──<Green>Linux</Green>",
                "   └──<Green>arch-1</Green>"
            }, new[]
            {
                "Local Probe",
                "├──Servers",
                "├──<Red>Linux</Red>",
                "│  └──<Red>arch-1</Red>",
                "└──<Green>Windows</Green>",
                "   └──<Green>dc-1</Green>",
            });
        }
Пример #13
0
        public void Tree_NodeList_Add_ExistingChildren()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            var newList = probe.Children.Add(PrtgNode.Group(Group()));

            Assert.AreNotEqual(probe.Children, newList);

            Assert.IsTrue(newList.All(i => i.Parent == null));

            var newProbe = probe.WithChildren(newList);

            Assert.IsTrue(newProbe.Children.All(c => c != null));
        }
Пример #14
0
        public void Tree_PrettyPrint_TwoChildren()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group()),
                                      PrtgNode.Group(Group("Linux", 2002))
                                      );

            var expected = new[]
            {
                "Local Probe",
                "├──Servers",
                "└──Linux"
            };

            Validate(tree, expected);
        }
Пример #15
0
        public void Tree_Compare_Reduce_AlreadyReduced_ReturnsSameTree()
        {
            var first = PrtgNode.Probe(Probe("Parent"),
                                       PrtgNode.Group(Group("Child1")),
                                       PrtgNode.Group(Group("Child2"))
                                       );

            var second = PrtgNode.Probe(Probe("Parent"),
                                        PrtgNode.Group(Group("Child1"))
                                        );

            var reduced = first.CompareTo(second).Reduce();

            var reducedAgain = reduced.Reduce();

            Assert.IsTrue(ReferenceEquals(reduced, reducedAgain));
        }
Пример #16
0
        public void Tree_PrettyPrint_SingleGrandChildCollection()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group(),
                                                     PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger()))
                                                     )
                                      );

            var expected = new[]
            {
                "Local Probe",
                "└──Servers",
                "   └──Email to Admin"
            };

            Validate(tree, expected);
        }
Пример #17
0
        public void Tree_Compare_Include_Value()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001)),
                                       PrtgNode.Property(Property("host", "dc-1"))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 2", 4001)),
                                        PrtgNode.Property(Property("host", "dc-2"))
                                        );

            CompareCompared(first, second,
                            new[] { TreeNodeDifference.Value },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.Name, TreeNodeDifference.Value },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.None, TreeNodeDifference.Value }
                            );
        }
Пример #18
0
        public void Tree_Compare_Include_Position()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001)),
                                       PrtgNode.Device(Device("Device 3", 4003, position: 1))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 2", 4001)),
                                        PrtgNode.Device(Device("Device 3", 4003, position: 2))
                                        );

            CompareCompared(first, second,
                            new[] { TreeNodeDifference.Position },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.Name, TreeNodeDifference.Position },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.None, TreeNodeDifference.Position }
                            );
        }
Пример #19
0
        public void Tree_PrettyPrint_TwoTriggers()
        {
            var group = Group();

            var tree = PrtgNode.Group(group,
                                      PrtgNode.Trigger(Trigger()),
                                      PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger("Ticket Notification")))
                                      );

            var expected = new[]
            {
                "Servers",
                "├──Email to Admin",
                "└──Ticket Notification",
            };

            Validate(tree, expected);
        }
Пример #20
0
        public void Tree_Compare_Exclude_Single()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001)),
                                       PrtgNode.Device(Device("Device 3", 4003))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 2", 4001)),
                                        PrtgNode.Device(Device("Device 3", 4003, parentId: 2))
                                        );

            CompareCompared(first, second,
                            new[] { ~TreeNodeDifference.Name },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.Name, TreeNodeDifference.ParentId },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.None, TreeNodeDifference.ParentId }
                            );
        }
Пример #21
0
        public void Tree_Compare_Include_Type()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001)),
                                       PrtgNode.Device(Device("Device 3", 4003))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 2", 4001)),
                                        PrtgNode.Group(Group("Device 3", 4003, parentId: 3))
                                        );

            CompareCompared(first, second,
                            new[] { TreeNodeDifference.Type },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.Name, TreeNodeDifference.Type },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.None, TreeNodeDifference.Type }
                            );
        }
Пример #22
0
        public void Tree_NodeList_AddRange_NoExistingChildren()
        {
            var probe = PrtgNode.Probe(Probe());

            var newList = probe.Children.AddRange(new PrtgNode[]
            {
                PrtgNode.Device(Device()),
                PrtgNode.Group(Group())
            });

            Assert.AreNotEqual(probe.Children, newList);

            Assert.AreEqual(2, newList.Count);
            Assert.IsTrue(newList.All(v => v.Parent == null));

            var newProbe = probe.WithChildren(newList);

            Assert.IsTrue(newProbe.Children.All(v => v.Parent != null));
        }
Пример #23
0
        public void Tree_PrettyPrint_TwoGrandChildren()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group(),
                                                     PrtgNode.Device(Device()),
                                                     PrtgNode.Device(Device("dc-2", 3002))
                                                     )
                                      );

            var expected = new[]
            {
                "Local Probe",
                "└──Servers",
                "   ├──dc-1",
                "   └──dc-2"
            };

            Validate(tree, expected);
        }
Пример #24
0
        public void Tree_PrettyPrint_TwoChildrenOneGrandChildCollection()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group(),
                                                     PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger()))
                                                     ),
                                      PrtgNode.Group(Group("Linux", 2002))
                                      );

            var expected = new[]
            {
                "Local Probe",
                "├──Servers",
                "│  └──Email to Admin",
                "└──Linux"
            };

            Validate(tree, expected);
        }
Пример #25
0
        public void Tree_Compare_Include_HasChildren()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001),
                                                       PrtgNode.Sensor(Sensor())
                                                       ),
                                       PrtgNode.Device(Device("Device 3", 4003, position: 1))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 1", 4001)),
                                        PrtgNode.Device(Device("Device 3", 4003, position: 2))
                                        );

            CompareCompared(first, second,
                            new[] { TreeNodeDifference.HasChildren },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.HasChildren | TreeNodeDifference.NumberOfChildren, TreeNodeDifference.Removed, TreeNodeDifference.Position },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.HasChildren, TreeNodeDifference.None, TreeNodeDifference.None }
                            );
        }
Пример #26
0
        public void Tree_Compare_IncludeExclude_Conflicting()
        {
            var first = PrtgNode.Group(Group(),
                                       PrtgNode.Device(Device("Device 1", 4001, parentId: 2)),
                                       PrtgNode.Device(Device("Device 2", 4002)),
                                       PrtgNode.Device(Device("Device 3", 4003))
                                       );

            var second = PrtgNode.Group(Group(),
                                        PrtgNode.Device(Device("Device 1", 4001)),
                                        PrtgNode.Group(Group("Device 2", 4002, parentId: 3)),
                                        PrtgNode.Device(Device("Device 4", 4003))
                                        );

            CompareCompared(first, second,
                            new[] { TreeNodeDifference.Name, ~TreeNodeDifference.Name },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.ParentId, TreeNodeDifference.Type, TreeNodeDifference.Name },
                            new[] { TreeNodeDifference.None, TreeNodeDifference.ParentId, TreeNodeDifference.Type, TreeNodeDifference.Name }
                            );
        }
Пример #27
0
        public void Tree_Compare_HasChildren()
        {
            var first = PrtgNode.Probe(Probe(),
                                       PrtgNode.Group(Group())
                                       );

            var second = PrtgNode.Probe(Probe());

            Validate(first, second, new[]
            {
                new Validation(TreeNodeDifference.HasChildren | TreeNodeDifference.NumberOfChildren, c => c.Difference)
            });

            ValidatePretty(first, second, new[]
            {
                "<Yellow>Local Probe</Yellow>",
                "└──<Red>Servers</Red>"
            }, new[]
            {
                "<Yellow>Local Probe</Yellow>",
                "└──<Green>Servers</Green>"
            });
        }