예제 #1
0
        public async Task WpLzhLogEventsListTest()
        {
            var site      = await WpLzhSiteAsync;
            var generator = new LogEventsList(site)
            {
                PaginationSize = 100,
                LogType        = LogTypes.Move,
                LogAction      = LogActions.MoveOverRedirect,
                TimeAscending  = false,
                // Local time should be converted to UTC in Utility.ToWikiQueryValue
                StartTime = DateTime.Now - TimeSpan.FromDays(7)
            };
            var logs = await generator.EnumItemsAsync().Take(200).ToList();

            ShallowTrace(logs, 1);
            var lastTimestamp = generator.StartTime.Value;

            foreach (var log in logs)
            {
                Assert.True(log.TimeStamp <= lastTimestamp);
                lastTimestamp = log.TimeStamp;
                Assert.Equal(LogTypes.Move, log.Type);
                Assert.Equal(LogActions.MoveOverRedirect, log.Action);
            }
        }
예제 #2
0
        public async Task WikiaLogEventsListTest()
        {
            var site      = await WikiaTestSiteAsync;
            var generator = new LogEventsList(site)
            {
                PaginationSize = 100,
                LogType        = LogTypes.Move,
                TimeAscending  = false,
            };
            var logs = await generator.EnumItemsAsync().Take(200).ToList();

            ShallowTrace(logs, 1);
            var lastTimestamp = DateTime.MaxValue;

            foreach (var log in logs)
            {
                Assert.True(log.TimeStamp <= lastTimestamp);
                lastTimestamp = log.TimeStamp;
                Assert.Equal(LogTypes.Move, log.Type);
                Assert.Equal(LogActions.Move, log.Action);
                // Wikia doesn't have `params` node in the logevent content,
                // but LogEventsList should have taken care of it properly.
                Assert.NotNull(log.Params);
                Assert.NotNull(log.Params.TargetTitle);
                // Should not throw KeyNotFoundException
                var ns = log.Params.TargetNamespaceId;
            }
        }
예제 #3
0
        // The test will not hold since ruwarriorswiki has upgraded into MW 1.33
        // [Fact]
        internal async Task WikiaLogEventsListLoopTest()
        {
            // This is a known scenario. There are a lot of logs on ruwarriorswiki with the same timestamp.
            var site = await GetWikiSiteAsync(Endpoints.RuWarriorsWiki);

            var generator = new LogEventsList(site)
            {
                PaginationSize = 50,
                LogType        = LogTypes.Move,
                StartTime      = DateTime.Parse("2019-09-28T07:31:07Z", CultureInfo.InvariantCulture),
                EndTime        = DateTime.Parse("2019-10-03T15:29:10Z", CultureInfo.InvariantCulture),
                TimeAscending  = true,
            };
            // Take only first page, fine.
            var logs = await generator.EnumItemsAsync().Take(50).ToListAsync();

            Output.WriteLine("{0}", logs.FirstOrDefault());
            Output.WriteLine("{0}", logs.LastOrDefault());
            Assert.Equal("FANDOMbot", logs.First().UserName);
            Assert.Equal("FANDOMbot", logs.Last().UserName);
            // Take the second page, it throws.
            await Assert.ThrowsAsync <UnexpectedDataException>(() => generator.EnumItemsAsync().Take(51).ToListAsync());

            // Introduce some last-resorts.
            generator.CompatibilityOptions = new WikiListCompatibilityOptions
            {
                ContinuationLoopBehaviors = WikiListContinuationLoopBehaviors.FetchMore
            };
            var logs2 = await generator.EnumItemsAsync().Take(100).ToListAsync();

            Output.WriteLine("logs = {0}", string.Join(",", logs.Select(l => l.LogId)));
            Output.WriteLine("logs2 = {0}", string.Join(",", logs2.Select(l => l.LogId)));
            // The first 50 items should be the same.
            Assert.Equal(logs.Select(l => l.LogId), logs2.Take(50).Select(l => l.LogId));
            // The next 50 items should not be duplicate with the first 100 items.
            var logs2Id = logs2.Skip(50).Select(l => l.LogId).ToHashSet();

            foreach (var l in logs)
            {
                Assert.DoesNotContain(l.LogId, logs2Id);
            }
        }