Example #1
0
        public async Task AsyncPolling(string dateTime, int expectedStatusCode, int retryAfter, int expectedData)
        {
            var trigger = new FluentAsyncPollingTrigger <PollingDto, PollableDto>()
                          .SetPollingTask(async state => await Task.Run(() =>
            {
                var tmp = All().Where(x => state.Timestamp < x.Timestamp).OrderBy(x => x.Data)
                          .ToList();
                Assert.Equal(expectedData, tmp.Count);
                return(tmp);
            }))
                          .SetStateUpdate((state, polled) =>
            {
                state.Timestamp = polled.OrderBy(x => x.Timestamp).Last().Timestamp;
                return(state);
            });
            var model = await trigger.Poll(new PollingDto()
            {
                Timestamp = DateTime.Parse(dateTime)
            }, new HttpContextAccessor()
            {
                HttpContext = new DefaultHttpContext()
            });

            Assert.Equal(expectedStatusCode, (int)model.StatusCode);
            Assert.Equal(retryAfter, model.RetryAfter.TotalSeconds);
        }
Example #2
0
        public async Task PollWithEmptyState()
        {
            var trigger = new FluentAsyncPollingTrigger <PollingDto, PollableDto>()
                          .SetPollingTask(async state => await Task.Run(() =>
            {
                var tmp = All().Where(x => state.Timestamp < x.Timestamp).OrderBy(x => x.Data)
                          .ToList();
                return(tmp);
            }))
                          .SetStateUpdate((state, polled) =>
            {
                state.Timestamp = polled.OrderBy(x => x.Timestamp).Last().Timestamp;
                return(state);
            });

            var model = await trigger.Poll(null, new HttpContextAccessor
            {
                HttpContext = new DefaultHttpContext()
            });

            Assert.NotNull(model.State.Timestamp);
        }