Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task PollActionWithEmptyState()
        {
            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);
            });

            foreach (var state in new[] { null, new PollingDto() })
            {
                var action = await trigger.PollAsAction(state, new HttpContextAccessor
                {
                    HttpContext = new DefaultHttpContext()
                });

                if (action is ObjectResult o)
                {
                    Assert.Equal(202, o.StatusCode);
                }
                else
                {
                    Assert.False(true);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task AsyncPollingAsAction(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 action = await trigger.PollAsAction(new PollingDto()
            {
                Timestamp = DateTime.Parse(dateTime)
            }, new HttpContextAccessor()
            {
                HttpContext = new DefaultHttpContext()
            });

            if (action is ObjectResult o)
            {
                Assert.Equal(expectedStatusCode, o.StatusCode);
            }
            else
            {
                Assert.False(true);
            }
        }
Ejemplo n.º 4
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);
        }