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>"
            }
                );
        }
Beispiel #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>"
            });
        }
        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);
        }
Beispiel #4
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"
            });
        }
Beispiel #5
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>"
            }
                );
        }
        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);
        }
        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);
        }
Beispiel #8
0
        public void Tree_NodeList_InsertRange_EmptyList()
        {
            var probe = PrtgNode.Probe(Probe());

            var newList = probe.Children.InsertRange(0, Enumerable.Empty <PrtgNode>());

            Assert.AreEqual(probe.Children, newList);
        }
Beispiel #9
0
        public void Tree_NodeList_InsertRange_Null_Throws()
        {
            var probe = PrtgNode.Probe(Probe());

            AssertEx.Throws <ArgumentNullException>(
                () => probe.Children.InsertRange(0, null),
                "Value cannot be null"
                );
        }
Beispiel #10
0
        public void Tree_Compare_SingleNode()
        {
            var first  = PrtgNode.Probe(Probe());
            var second = PrtgNode.Probe(Probe());

            Validate(first, second, new[]
            {
                new Validation(TreeNodeDifference.None, c => c.Difference)
            });
        }
        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);
        }
Beispiel #12
0
        public void Tree_NodeList_Item_InBounds()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            var device = probe.Children[0];

            Assert.IsNotNull(device);
        }
Beispiel #13
0
        public void Tree_NodeList_Remove_Null_Throws()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            AssertEx.Throws <ArgumentNullException>(
                () => probe.Children.Remove(null),
                "Value cannot be null"
                );
        }
        public void Tree_Compare_Reduce_Root_NoDifference()
        {
            var node = PrtgNode.Probe(Probe(),
                                      PrtgNode.Device(Device()),
                                      PrtgNode.Device(Device("exch-1")
                                                      ));

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

            Assert.IsNull(comparison);
        }
Beispiel #15
0
        public void Tree_NodeList_ReplaceRange_OldNode_Null_Throws()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            AssertEx.Throws <ArgumentNullException>(
                () => probe.Children.ReplaceRange(null, Enumerable.Empty <PrtgNode>()),
                "Value cannot be null"
                );
        }
Beispiel #16
0
        public void Tree_NodeList_ReplaceRange_NewNodes_Null_Throws()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            AssertEx.Throws <ArgumentNullException>(
                () => probe.Children.ReplaceRange(probe["dc-1"], null),
                "Value cannot be null"
                );
        }
Beispiel #17
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");
        }
        public void Tree_PrettyPrint_SingleChild()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.Group(Group())
                                      );

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

            Validate(tree, expected);
        }
Beispiel #19
0
        public void Tree_NodeList_InsertRange_InvalidIndex_Throws()
        {
            var probe = PrtgNode.Probe(Probe());

            AssertEx.Throws <ArgumentOutOfRangeException>(
                () => probe.Children.InsertRange(-1, new[] { PrtgNode.Device(Device()) }),
                "Specified argument was out of the range of valid values"
                );

            AssertEx.Throws <ArgumentOutOfRangeException>(
                () => probe.Children.InsertRange(1, new[] { PrtgNode.Device(Device()) }),
                "Specified argument was out of the range of valid values"
                );
        }
Beispiel #20
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);
        }
        public void Tree_PrettyPrint_SingleChildCollection()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger()))
                                      );

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

            Validate(tree, expected);
        }
Beispiel #22
0
        public void Tree_NodeList_Add_NoExistingChildren()
        {
            var probe = PrtgNode.Probe(Probe());

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

            Assert.AreNotEqual(probe.Children, newList);

            //The list is standalone until it's added as the child
            Assert.IsNull(newList[0].Parent);

            var newProbe = probe.WithChildren(newList);

            Assert.IsNotNull(newProbe.Children[0].Parent);
        }
Beispiel #23
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>",
            });
        }
        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);
        }
Beispiel #25
0
        public void Tree_NodeList_Item_OutOfBounds()
        {
            var probe = PrtgNode.Probe(Probe(),
                                       PrtgNode.Device(Device())
                                       );

            AssertEx.Throws <ArgumentOutOfRangeException>(
                () => Console.WriteLine(probe.Children[-1]),
                "Specified argument was out of the range of valid values"
                );

            AssertEx.Throws <ArgumentOutOfRangeException>(
                () => Console.WriteLine(probe.Children[1]),
                "Specified argument was out of the range of valid values"
                );
        }
Beispiel #26
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));
        }
        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));
        }
Beispiel #28
0
        public void Tree_Compare_Different_SingleNode()
        {
            var first  = PrtgNode.Probe(Probe());
            var second = PrtgNode.Probe(Probe("New York"));

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

            ValidatePretty(first, second, new[]
            {
                "<Yellow>Local Probe (Renamed 'New York')</Yellow>"
            }, new[]
            {
                "<Yellow>New York (Renamed 'Local Probe')</Yellow>"
            });
        }
        public void Tree_PrettyPrint_TwoCollectionChildren()
        {
            var tree = PrtgNode.Probe(Probe(),
                                      PrtgNode.TriggerCollection(
                                          PrtgNode.Trigger(Trigger()),
                                          PrtgNode.Trigger(Trigger("Ticket Notification"))
                                          )
                                      );

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

            Validate(tree, expected);
        }
        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);
        }