Exemplo n.º 1
0
        public void Tree_Lazy_Child_ResolvesOnlyOnce()
        {
            var client = BaseTest.Initialize_Client(new TreeRequestResponse(TreeRequestScenario.MultiLevelContainer));

            var validator = new EventValidator(client, new[]
            {
                //Get Object
                UnitRequest.Objects("filter_objid=1001"),

                //Get Probe
                UnitRequest.Probes("filter_objid=1001&filter_parentid=0"),

                //Probe -> Devices/Groups
                UnitRequest.Devices("filter_parentid=1001"),
                UnitRequest.Groups("filter_parentid=1001"),

                //Probe -> Device -> Sensors
                UnitRequest.Sensors("filter_parentid=3001")
            });

            validator.MoveNext(2);
            var tree = client.GetTreeLazy(1001);

            validator.MoveNext(2);
            var child      = tree.Children[0];
            var childAgain = tree.Children[0];

            validator.MoveNext();
            var grandChild      = child.Children[0];
            var grandChildAgain = child.Children[0];
        }
Exemplo n.º 2
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Groups("count=1", UrlFlag.Columns), address);
                return(new BasicResponse(standardResponse.GetResponseText(ref address)));

            case 2:
                Assert.AreEqual(UnitRequest.Groups("filter_objid=9999"), address);
                return(new GroupResponse(new GroupItem(objid: "2000", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            //Tree

            case 3:
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2000"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001"), new DeviceItem(objid: "3002")));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001")));

            case 5:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3002"), address);
                return(new SensorResponse(new SensorItem(objid: "4002")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 3
0
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Get a group
                Assert.AreEqual(UnitRequest.Groups("count=1", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(objid: "2000")));

            case 2:     //Are there any other groups called "Windows Infrastructure"?
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_name=Windows+Infrastructure", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(objid: "2000"), new GroupItem(objid: "2050")));

            case 3:     //Get all devices under the group "Windows Infrastructure" that we're piping from
                Assert.AreEqual(UnitRequest.Devices("count=*&filter_parentid=2000", UrlFlag.Columns), address);
                return(new DeviceResponse(new DeviceItem(name: "Device1", objid: "3000"), new DeviceItem(name: "Device2", objid: "3001")));

            case 4:     //Get all sensors from the child devices
                Assert.AreEqual(UnitRequest.Sensors("count=*&filter_name=@sub(ping)&filter_parentid=3000&filter_parentid=3001", UrlFlag.Columns), address);
                return(new SensorResponse(new SensorItem(name: "Ping", objid: "4000"), new SensorItem(name: "Pong2", objid: "4001")));

            case 5:     //Get all child groups under "Windows Infrastructure
                Assert.AreEqual(UnitRequest.Groups("count=*&filter_parentid=2000", UrlFlag.Columns), address);
                return(new GroupResponse(new GroupItem(name: "Child Group", objid: "2001", totalsens: "0")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 4
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(address, UnitRequest.Objects("filter_objid=1001"));
                return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe")));

            case 2:
                Assert.AreEqual(address, UnitRequest.Probes("filter_objid=1001&filter_parentid=0"));
                return(new ProbeResponse(new ProbeItem(objid: "1001", name: "Local Probe")));

            //Probe -> Devices
            case 3:
                Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=1001"));
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", name: "dc-1", position: "10", positionRaw: "10"),
                           new DeviceItem(objid: "3002", name: "dc-2", position: "20", positionRaw: "20")
                           ));

            //Probe -> Groups
            case 4:
                Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=1001"));
                return(new GroupResponse(new GroupItem(objid: "2001", name: "Servers", position: "30", positionRaw: "30")));

            //Probe -> Triggers
            case 5:
                Assert.AreEqual(address, UnitRequest.Triggers(1001));
                return(new NotificationTriggerResponse(
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "300|Trigger1", parentId: "1001"),
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "301|Trigger2", parentId: "1001"),
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "302|Trigger3", parentId: "1001")
                           ));

            //Probe -> Devices -> Sensors
            case 6:
                Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3001"));
                return(new SensorResponse(
                           new SensorItem(name: "Sensor2", objid: "4002", position: "20", positionRaw: "20"),
                           new SensorItem(name: "Sensor1", objid: "4001", position: "10", positionRaw: "10")
                           ));

            case 7:
                Assert.AreEqual(address, UnitRequest.Sensors("filter_parentid=3002"));
                return(new SensorResponse());

            //Probe -> Groups -> Devices
            case 8:
                Assert.AreEqual(address, UnitRequest.Devices("filter_parentid=2001"));
                return(new DeviceResponse());

            //Probe -> Groups -> Groups
            case 9:
                Assert.AreEqual(address, UnitRequest.Groups("filter_parentid=2001"));
                return(new GroupResponse());

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 5
0
        public void Query_Where_Sensors_MatchAnyDevices()
        {
            var urls = new List <string>
            {
                UnitRequest.Sensors("count=500", UrlFlag.Columns)
            };

            var filters = new[]
            {
                "filter_objid=3000",
                "filter_objid=3001",
                "filter_objid=3002"
            };

            urls.AddRange(filters.SelectMany(f => new[]
            {
                UnitRequest.Devices($"count=500&{f}", UrlFlag.Columns)
            }
                                             ));

            var client = GetClient(urls.ToArray());

            var sensors = client.Item1.QuerySensors().Where(s => client.Item1.QueryDevices().Any(d => d.Id == s.Id - 1000)).ToList();

            Assert.AreEqual(3, sensors.Count);

            client.Item2.AssertFinished();
        }
Exemplo n.º 6
0
 private void QueryDevice(System.Linq.Expressions.Expression <Func <Device, bool> > predicate, string url)
 {
     ExecuteClient(c => c.QueryDevices(predicate), new[]
     {
         UnitRequest.Devices($"count=500" + (string.IsNullOrEmpty(url) ? url : $"&{url}"), UrlFlag.Columns)
     }, s => s.ToList());
 }
Exemplo n.º 7
0
 public void Query_Skip_ThreeTimes()
 {
     ExecuteClient(
         q => q.QueryDevices().Skip(1).Skip(1).Skip(1),
         new[] {
         UnitRequest.DeviceCount,
         UnitRequest.Devices("count=1&start=3", UrlFlag.Columns)
     },
         s => Assert.AreEqual(1, s.Count())
         );
 }
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Groups("filter_objid=0"), address);
                return(new GroupResponse(new GroupItem(objid: "0", name: "Root")));

            case 2:
                Assert.AreEqual(UnitRequest.Devices(), address);
                return(new DeviceResponse(new DeviceItem(objid: "2001", parentId: "1001")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 9
0
        public void Query_Select_AnotherSelectQuery()
        {
            var urls = new[]
            {
                UnitRequest.Sensors("count=500", UrlFlag.Columns),

                UnitRequest.Devices("columns=favorite&count=500", null),
                UnitRequest.Devices("columns=favorite&count=500", null),
                UnitRequest.Devices("columns=favorite&count=500", null)
            };

            ExecuteClient(
                c => c.QuerySensors().Select(s => c.QueryDevices().Select(d => d.Favorite)).SelectMany(s => s).ToList(),
                urls,
                d => Assert.AreEqual(12, d.Count)
                );
        }
Exemplo n.º 10
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:     //Resolve Object
                Assert.AreEqual(UnitRequest.Objects("filter_objid=1001"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            case 2:
                Assert.AreEqual(UnitRequest.Probes("filter_objid=1001&filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            case 3:
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=1001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001", totalsens: "0", totalsensRaw: "0")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 11
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Objects("filter_objid=3001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001")));

            case 2:
                Assert.AreEqual(UnitRequest.Devices("filter_objid=3001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001")));

            case 3:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001", parentId: "3001")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 12
0
        public void Query_Select_AnotherQuery_InAnAnonymousType()
        {
            var urls = new[]
            {
                UnitRequest.Sensors("columns=name&count=500", null),

                UnitRequest.Devices("count=500&filter_active=-1", UrlFlag.Columns),
                UnitRequest.Devices("count=500&filter_active=-1", UrlFlag.Columns),
                UnitRequest.Devices("count=500&filter_active=-1", UrlFlag.Columns),
            };

            ExecuteClient(
                c => c.QuerySensors().Select(s => new
            {
                First   = s.Name,
                Devices = c.QueryDevices().Any(d => d.Active)
            }).ToList(),
                urls,
                d => Assert.AreEqual(3, d.Count)
                );
        }
Exemplo n.º 13
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Groups("filter_objid=0"), address);
                return(new GroupResponse(new GroupItem(objid: "0", name: "Root")));

            case 2:
                Assert.AreEqual(UnitRequest.Probes("filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3")));

            case 3:
                Assert.AreEqual(UnitRequest.Groups(), address);
                return(new GroupResponse(
                           new GroupItem(objid: "0", parentId: "-1000", name: "Root"),
                           new GroupItem(objid: "2001", parentId: "1001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2"),
                           new GroupItem(objid: "2002", parentId: "2001", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")
                           ));

            case 4:
                Assert.AreEqual(UnitRequest.Devices(), address);
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", parentId: "1001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3002", parentId: "2001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3003", parentId: "2002", totalsens: "2", totalsensRaw: "2")
                           ));

            case 5:
                Assert.AreEqual(UnitRequest.Sensors(), address);
                return(new SensorResponse(
                           new SensorItem(objid: "4001", parentId: "3001"),
                           new SensorItem(objid: "4002", parentId: "3002"),
                           new SensorItem(objid: "4003", parentId: "3003")
                           ));

            default:
                throw UnknownRequest(address);
            }
        }
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Probes("count=1&filter_parentid=0", UrlFlag.Columns), address);
                return(new BasicResponse(standardResponse.GetResponseText(ref address)));

            //Probe 1

            case 2:
                Assert.AreEqual(UnitRequest.Groups("filter_probe=127.0.0.10"), address);
                return(new BasicResponse(standardResponse.GetResponseText(ref address)));

            //Tree

            case 3:
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2000"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3000", totalsens: "1", totalsensRaw: "1")));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3000"), address);
                return(new SensorResponse(new SensorItem(objid: "4000")));

            case 5:
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001", totalsens: "1", totalsensRaw: "1")));

            case 6:
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001")));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 15
0
 protected void AssertDeviceRequest(string address, Content content, string request)
 {
     Assert.AreEqual(Content.Devices, content);
     Assert.AreEqual(UnitRequest.Devices(request), address);
 }
Exemplo n.º 16
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:     //Resolve Object
                Assert.AreEqual(UnitRequest.Objects("filter_objid=1001"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3")));

            case 2:     //Probes
                Assert.AreEqual(UnitRequest.Probes("filter_objid=1001&filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3", notifiesx: "Inherited 1 State")));

            case 3:     //Probe -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=1001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3001", totalsens: "2", totalsensRaw: "2")));

            case 4:     //Probe -> Group
                Assert.AreEqual(UnitRequest.Groups("filter_parentid=1001"), address);
                return(new GroupResponse(new GroupItem(objid: "2001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2")));

            case 5:     //Probe -> Device -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3001"), address);
                return(new SensorResponse(new SensorItem(objid: "4001")));

            case 6:     //Probe -> Group -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2001"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3002", totalsens: "2", totalsensRaw: "2")));

            case 7:     //Probe -> Group -> Group
                Assert.AreEqual(UnitRequest.Groups("filter_parentid=2001"), address);
                return(new GroupResponse(new GroupItem(objid: "2002", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")));

            case 8:     //Probe -> Group -> Device -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3002"), address);
                return(new SensorResponse(new SensorItem(objid: "4002")));

            case 9:     //Probe -> Group -> Group -> Device
                Assert.AreEqual(UnitRequest.Devices("filter_parentid=2002"), address);
                return(new DeviceResponse(new DeviceItem(objid: "3003", totalsens: "2", totalsensRaw: "2")));

            case 10:     //Probe -> Group -> Group -> Sensor
                Assert.AreEqual(UnitRequest.Sensors("filter_parentid=3003"), address);
                return(new SensorResponse(new SensorItem(objid: "4003")));

            case 11:
                Assert.AreEqual(UnitRequest.Triggers(1001), address);
                return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "1001")));

            case 12:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Notifications("filter_objid=301"), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 13:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.NotificationProperties(301), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 14:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Schedules(), address);
                return(new ScheduleResponse(new ScheduleItem()));

            case 15:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.ScheduleProperties(623), address);
                return(new ScheduleResponse(new ScheduleItem()));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 17
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Probes("filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3")));

            case 2:
                Assert.AreEqual(UnitRequest.Groups(), address);
                return(new GroupResponse(
                           new GroupItem(objid: "0", parentId: "-1000", name: "Root"),
                           new GroupItem(objid: "2001", parentId: "1001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2"),
                           new GroupItem(objid: "2002", parentId: "2001", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")
                           ));

            case 3:
                Assert.AreEqual(UnitRequest.Devices(), address);
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", parentId: "1001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3002", parentId: "2001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3003", parentId: "2002", totalsens: "2", totalsensRaw: "2")
                           ));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors(), address);
                return(new SensorResponse(
                           new SensorItem(objid: "4001", parentId: "3001"),
                           new SensorItem(objid: "4002", parentId: "3002"),
                           new SensorItem(objid: "4003", parentId: "3003")
                           ));

            case 5:
                Assert.AreEqual(UnitRequest.Triggers(1001), address);
                return(new NotificationTriggerResponse(NotificationTriggerItem.StateTrigger(parentId: "1001")));

            case 6:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Notifications("filter_objid=301"), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 7:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.NotificationProperties(301), address);
                return(new NotificationActionResponse(new NotificationActionItem()));

            case 8:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.Schedules(), address);
                return(new ScheduleResponse(new ScheduleItem()));

            case 9:
                if (!async)
                {
                    goto default;
                }
                Assert.AreEqual(UnitRequest.ScheduleProperties(623), address);
                return(new ScheduleResponse(new ScheduleItem()));

            default:
                throw UnknownRequest(address);
            }
        }
Exemplo n.º 18
0
        protected override IWebResponse GetResponse(string address)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Probes("filter_parentid=0"), address);
                return(new ProbeResponse(new ProbeItem(objid: "1001", groupnum: "2", groupnumRaw: "2", devicenum: "3", devicenumRaw: "3", notifiesx: "Inherited")));

            case 2:
                Assert.AreEqual(UnitRequest.Groups(), address);
                return(new GroupResponse(
                           new GroupItem(objid: "0", parentId: "-1000", name: "Root"),
                           new GroupItem(objid: "2001", parentId: "1001", groupnum: "1", groupnumRaw: "1", devicenum: "2", devicenumRaw: "2"),
                           new GroupItem(objid: "2002", parentId: "2001", name: "VMware", groupnum: "0", groupnumRaw: "0", devicenum: "1", devicenumRaw: "1")
                           ));

            case 3:
                Assert.AreEqual(UnitRequest.Devices(), address);
                return(new DeviceResponse(
                           new DeviceItem(objid: "3001", parentId: "1001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3002", parentId: "2001", totalsens: "2", totalsensRaw: "2"),
                           new DeviceItem(objid: "3003", parentId: "2002", totalsens: "2", totalsensRaw: "2")
                           ));

            case 4:
                Assert.AreEqual(UnitRequest.Sensors(), address);
                return(new SensorResponse(
                           new SensorItem(objid: "4001", parentId: "3001"),
                           new SensorItem(objid: "4002", parentId: "3002"),
                           new SensorItem(objid: "4003", parentId: "3003")
                           ));

            case 5:
                Assert.AreEqual(UnitRequest.RequestObjectData(4001), address);
                return(new SensorSettingsResponse());

            case 6:
                Assert.AreEqual(UnitRequest.RequestObjectData(3001), address);
                return(new SensorSettingsResponse());

            case 7:
                Assert.AreEqual(UnitRequest.RequestObjectData(4002), address);
                return(new SensorSettingsResponse());

            case 8:
                Assert.AreEqual(UnitRequest.RequestObjectData(3002), address);
                return(new SensorSettingsResponse());

            case 9:
                Assert.AreEqual(UnitRequest.RequestObjectData(4003), address);
                return(new SensorSettingsResponse());

            case 10:
                Assert.AreEqual(UnitRequest.RequestObjectData(3003), address);
                return(new SensorSettingsResponse());

            case 11:
                Assert.AreEqual(UnitRequest.RequestObjectData(2002), address);
                return(new SensorSettingsResponse());

            case 12:
                Assert.AreEqual(UnitRequest.RequestObjectData(2001), address);
                return(new SensorSettingsResponse());

            case 13:
                Assert.AreEqual(UnitRequest.RequestObjectData(1001), address);
                return(new SensorSettingsResponse());

            case 14:
                Assert.AreEqual(UnitRequest.RequestObjectData(0), address);
                return(new SensorSettingsResponse());

            default:
                throw UnknownRequest(address);
            }
        }