コード例 #1
0
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Request 2 ping sensors. We instead return 2 "pong" logs
                Assert.AreEqual(UnitRequest.Logs("count=2&start=1&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(new MessageItem("Ping"), new MessageItem("Pong2")));

            case 2:     //We're going to have to stream. Request how many objects exist
                Assert.AreEqual(UnitRequest.Logs("count=1&columns=objid,name&filter_name=ping", null), address);
                return(new MessageResponse(Enumerable.Range(0, 2).Select(i => new MessageItem()).ToArray()));

            case 3:     //Request the 1 remaining log
                Assert.AreEqual(UnitRequest.Logs("count=1&start=3&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(
                           new MessageItem("Ping"),       //Skipped by BaseResponse
                           new MessageItem("Pong2 Again") //Skipped by BaseResponse
                           )
                {
                    Stream = true
                });

            default:
                throw UnknownRequest(address);
            }
        }
コード例 #2
0
        public void QueryFilter_LogProperties_DateTime_BackwardsAndForwards()
        {
            var url = new[] { UnitRequest.Logs($"count=500&start=1&filter_dend={Time.TodayStr}", UrlFlag.Columns) };

            ExecuteClient(c => c.QueryLogs().Where(l => l.DateTime < Time.Today), url, l => l.ToList());
            ExecuteClient(c => c.QueryLogs().Where(l => Time.Today > l.DateTime), url, l => l.ToList());
        }
コード例 #3
0
 public void Log_Watch_SpecifiesAStartDate()
 {
     Execute(
         c => c.WatchLogs(startDate: new DateTime(2000, 10, 2, 12, 10, 5, DateTimeKind.Utc)).Take(1).ToList(),
         UnitRequest.Logs("start=1&filter_dstart=2000-10-02-12-10-05")
         );
 }
コード例 #4
0
        protected void ExecuteUnsupportedInternal <TSource, TResult>(
            Func <PrtgClient, IQueryable <TSource> > query,
            Func <IQueryable <TSource>, IQueryable <TResult> > illegalAction,
            string message,
            Func <IQueryable <TSource>, IEnumerable <TResult> > legalAction,
            string legalUrl,
            Action <List <TResult> > legalValidator
            )
        {
            AssertEx.Throws <NotSupportedException>(
                () => ExecuteClient(c => illegalAction(query(c)), new string[] { }, s => s.ToList()),
                message
                );

            var flags = UnitRequest.DefaultObjectFlags & ~UrlFlag.Count;

            if (!legalUrl.Contains("count"))
            {
                legalUrl = "count=500" + (string.IsNullOrEmpty(legalUrl) ? legalUrl : $"&{legalUrl}");
            }

            var urls = new[]
            {
                typeof(TSource) == typeof(Log) ? UnitRequest.Logs(legalUrl, flags) : UnitRequest.Sensors(legalUrl, flags)
            };

            ExecuteClient(c => legalAction(query(c)), urls, s => legalValidator(s.ToList()));
        }
コード例 #5
0
        //One stream
        private void QueryLog(
            System.Linq.Expressions.Expression <Func <Log, bool> > predicate,
            Func <PrtgClient, IEnumerable <Log> > stream,
            string[] url,
            Enum[] streamOrder = null)
        {
            var urls = url.SelectMany(s =>
            {
                if (!s.Contains("count"))
                {
                    s = $"count=500&{s}";
                }

                return(new[]
                {
                    UnitRequest.Logs(s, UrlFlag.Columns)
                });
            }).ToArray();

            ExecuteClient(c => c.QueryLogs(predicate), urls, s => s.ToList());

            if (streamOrder != null)
            {
                urls = GetStreamLogUrls(urls, streamOrder);
            }

            ExecuteClient(stream, urls, s => s.ToList());
        }
コード例 #6
0
 public void Query_Where_SplitRequests_Logs_Select_SingleSet_ReduceParameters()
 {
     ExecuteClient(
         c => c.QueryLogs().Where(l => l.Id == 1001).Select(l => l.Name),
         new[] { UnitRequest.Logs("columns=objid,name&count=500&start=1&id=1001", null) },
         l => l.ToList()
         );
 }
コード例 #7
0
 public void Query_Where_SplitRequests_Logs_Select_MultipleSets_AllParameters()
 {
     ExecuteClient(
         c => c.QueryLogs().Where(l => l.Id == 1001 || l.Id == 1002).Select(l => l.Name),
         new[] { UnitRequest.Logs("count=500&start=1&id=1001", UrlFlag.Columns), UnitRequest.Logs("count=500&start=1&id=1002", UrlFlag.Columns) },
         l => l.ToList()
         );
 }
コード例 #8
0
ファイル: SkipTests.cs プロジェクト: vijaydairyf/PrtgAPI
 public void Query_Skip_Logs()
 {
     ExecuteClient(
         c => c.QueryLogs().Skip(1),
         new[] {
         UnitRequest.LogCount,
         UnitRequest.Logs("count=4&start=2", UrlFlag.Columns)
     },
         s => Assert.AreEqual(4, s.Count())
         );
 }
コード例 #9
0
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Request how many objects exist
                Assert.AreEqual(UnitRequest.Logs("count=1&columns=objid,name&filter_name=ping", null), address);
                return(new MessageResponse(Enumerable.Range(0, 0).Select(i => new MessageItem()).ToArray()));

            default:
                throw UnknownRequest(address);
            }
        }
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Logs("count=2&start=1", UrlFlag.Columns), address);
                return(new MessageResponse(new MessageItem()));

            default:
                throw UnknownRequest(address);
            }
        }
コード例 #11
0
        private void StreamLogs(LogParameters parameters, string[] address, int count = 10)
        {
            var url = new List <string>();

            url.Add(UnitRequest.Logs($"count=1&columns=objid,name", null));
            url.AddRange(address.Select(a => UnitRequest.Logs(a, UrlFlag.Columns)));

            Execute(
                c => c.StreamLogs(parameters).ToList(),
                url.ToArray(),
                new Dictionary <Content, int>
            {
                [Content.Logs] = count
            }
                );
        }
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:
                Assert.AreEqual(UnitRequest.Logs("count=1&columns=objid,name&filter_name=ping", null), address);
                return(GetTotalLogsResponse());

            case 2:
                Assert.AreEqual(UnitRequest.Logs("count=2&start=1&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(new MessageItem("Ping"), new MessageItem("Ping"), new MessageItem("Ping")));

            default:
                throw UnknownRequest(address);
            }
        }
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Request how many objects exist
                Assert.AreEqual(UnitRequest.Logs("count=1&columns=objid,name&filter_name=ping", null), address);
                return(new MessageResponse(Enumerable.Range(0, 600).Select(i => new MessageItem()).ToArray()));

            case 2:     //Request 2 ping logs. We instead return 2 "pong" logs
                Assert.AreEqual(UnitRequest.Logs("count=2&start=1&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(new MessageItem("Pong1"), new MessageItem("Pong1")));

            case 3:     //Request the next 2 sensors
                Assert.AreEqual(UnitRequest.Logs("count=2&start=3&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(
                           new MessageItem("Pong1"), //Skipped by BaseResponse
                           new MessageItem("Pong2"), //Skipped by BaseResponse
                           new MessageItem("Pong3"),
                           new MessageItem("Pong4")
                           ));

            case 4:     //Still haven't gotten all the sensors we want. Ask for 500 sensors then
                Assert.AreEqual(UnitRequest.Logs("count=500&start=5&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(Enumerable.Range(0, 504).Select(i =>
                {
                    if (i == 500)
                    {
                        return new MessageItem("Ping");
                    }

                    return new MessageItem();
                }).ToArray()));

            case 5:     //Still haven't gotten all the sensors we want. Ask for the remaining 96
                Assert.AreEqual(UnitRequest.Logs("count=96&start=505&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(Enumerable.Range(0, 600).Select(i => new MessageItem()).ToArray()));

            default:
                throw UnknownRequest(address);
            }
        }
        protected override IWebResponse GetResponse(string address, Content content)
        {
            switch (requestNum)
            {
            case 1:     //Request how many objects exist
                Assert.AreEqual(UnitRequest.Logs("count=1&columns=objid,name&filter_name=ping", null), address);
                return(new MessageResponse(Enumerable.Range(0, 1).Select(i => new MessageItem()).ToArray()));

            case 2:     //Request the 1 remaining log
                Assert.AreEqual(UnitRequest.Logs("count=1&start=1&filter_name=ping", UrlFlag.Columns), address);
                return(new MessageResponse(
                           new MessageItem("Ping"),
                           new MessageItem("Pong")
                           )
                {
                    Stream = true
                });

            default:
                throw UnknownRequest(address);
            }
        }
コード例 #15
0
        public void Log_Stream_WithCorrectPageSize()
        {
            var urls = new[]
            {
                UnitRequest.Logs("count=500&start=1&filter_drel=7days", UrlFlag.Columns),
                UnitRequest.Logs("count=500&start=501&filter_drel=7days", UrlFlag.Columns),
                UnitRequest.Logs("count=500&start=1001&filter_drel=7days", UrlFlag.Columns),
                UnitRequest.Logs("count=100&start=1501&filter_drel=7days", UrlFlag.Columns)
            };

            Execute(
                c => {
                var items = c.StreamLogs(serial: true).ToList();

                Assert.AreEqual(1600, items.Count);
            },
                urls,
                new Dictionary <Content, int>
            {
                [Content.Logs] = 1600
            }
                );
        }
コード例 #16
0
 public void QueryFilter_Log_WithTake()
 {
     ExecuteClient(c => c.QueryLogs(), new[] { UnitRequest.Logs("count=500&start=1", UrlFlag.Columns) }, s => s.ToList());
     ExecuteClient(c => c.QueryLogs().Take(3), new[] { UnitRequest.Logs("count=3&start=1", UrlFlag.Columns) }, s => s.ToList());
 }
 protected override void AssertThird(string address)
 {
     //We did a client side filter for the second item after request 2, so the latest Current is the second item, not the third
     Assert.AreEqual(UnitRequest.Logs($"{filters}&filter_dstart={LogDate(startDate.AddHours(1).AddMinutes(1))}"), address);
 }
コード例 #18
0
 protected virtual void AssertFifth(string address)
 {
     Assert.AreEqual(UnitRequest.Logs($"{filters}&filter_dstart={LogDate(startDate.AddHours(1).AddMinutes(6))}"), address);
 }
コード例 #19
0
 protected virtual void AssertFirst(string address)
 {
     Assert.AreEqual(UnitRequest.Logs($"{filters}&filter_dstart={LogDate(startDate)}"), address);
 }