示例#1
0
        public async Task <XDocument> GetSitemap(CancellationToken cancellationToken)
        {
            XElement[] normalSitemapEntries =
                new[]
            {
                GetUrlSitemapEntry(new Uri("/", UriKind.Relative), "always", 1.0m),
                GetUrlSitemapEntry(new Uri("/privacy-policy", UriKind.Relative), "monthly", 0.1m),
                GetUrlSitemapEntry(new Uri("/about", UriKind.Relative), "monthly", 0.3m),
                GetUrlSitemapEntry(new Uri("/donate", UriKind.Relative), "monthly", 0.3m),
                GetUrlSitemapEntry(new Uri("/find", UriKind.Relative), "always", 0.3m)
            };

            List <Crowdaction> crowdactions =
                await crowdactionService
                .SearchCrowdactions(null, SearchCrowdactionStatus.Active)
                .Include(c => c.BannerImage)
                .ToListAsync(cancellationToken)
                .ConfigureAwait(false);

            IEnumerable <XElement> crowdactionEntries = crowdactions.Select(GetCrowdactionSitemapEntry);

            return(new XDocument(
                       new XDeclaration("1.0", "utf-8", "yes"),
                       new XElement(
                           SitemapSchema + "urlset",
                           normalSitemapEntries.Cast <object>()
                           .Concat(crowdactionEntries)
                           .Concat(ExtraNamespaces)
                           .ToArray())));
        }
示例#2
0
        public async Task InitializeDatabase()
        {
            logger.LogInformation("Migrating database");
            await context.Database.MigrateAsync().ConfigureAwait(false);

            logger.LogInformation("Creating admin user if absent");
            ApplicationUser admin = await CreateAdminRoleAndUser().ConfigureAwait(false);

            if (seedOptions.SeedTestData && !(await crowdactionService.SearchCrowdactions(null, null).AnyAsync().ConfigureAwait(false)))
            {
                logger.LogInformation("Seeding database");
                jobClient.Enqueue(() => SeedTestData(admin.Id, CancellationToken.None));
            }
        }
示例#3
0
        public async Task TestCrowdactionSearch()
        {
            Random   r = new Random();
            Category searchCategory = (Category)r.Next(7);

            for (int i = 0; i < r.Next(10, 30); i++)
            {
                var         newCrowdaction = new NewCrowdactionInternal("test" + Guid.NewGuid(), 100, "test", "test", "test", null, DateTime.UtcNow.AddDays(r.Next(-20, 20)), DateTime.UtcNow.AddDays(r.Next(21, 50)), null, null, null, null, new[] { searchCategory }, Array.Empty <string>(), CrowdactionDisplayPriority.Bottom, (CrowdactionStatus)r.Next(3), 0, null);
                Crowdaction crowdaction    = await crowdactionService.CreateCrowdactionInternal(newCrowdaction, CancellationToken.None);
            }

            Assert.True(await crowdactionService.SearchCrowdactions(null, null).AnyAsync());

            Assert.True(await crowdactionService.SearchCrowdactions(searchCategory, null).Include(c => c.Categories).AllAsync(c => c.Categories.Any(pc => pc.Category == searchCategory)));
            Assert.True(await crowdactionService.SearchCrowdactions(null, SearchCrowdactionStatus.Closed).AllAsync(c => c.End < DateTime.UtcNow));
            Assert.True(await crowdactionService.SearchCrowdactions(searchCategory, SearchCrowdactionStatus.Closed).AllAsync(c => c.End < DateTime.UtcNow));
            Assert.True(await crowdactionService.SearchCrowdactions(null, SearchCrowdactionStatus.ComingSoon).AllAsync(c => c.Start > DateTime.UtcNow && c.Status == CrowdactionStatus.Running));
            Assert.True(await crowdactionService.SearchCrowdactions(searchCategory, SearchCrowdactionStatus.ComingSoon).AllAsync(c => c.Start > DateTime.UtcNow && c.Status == CrowdactionStatus.Running));
            Assert.True(await crowdactionService.SearchCrowdactions(null, SearchCrowdactionStatus.Open).AllAsync(c => c.Start <= DateTime.UtcNow && c.End >= DateTime.UtcNow && c.Status == CrowdactionStatus.Running));
            Assert.True(await crowdactionService.SearchCrowdactions(searchCategory, SearchCrowdactionStatus.Open).AllAsync(c => c.Start <= DateTime.UtcNow && c.End >= DateTime.UtcNow && c.Status == CrowdactionStatus.Running));
        }