public AuthorizedTaskTestDataHelper(
     IServiceProvider serviceProvider,
     SeededEntities seededEntities
     )
 {
     _serviceProvider    = serviceProvider;
     _userTestDataHelper = new UserTestDataHelper(serviceProvider, seededEntities);
 }
 public UserTestDataHelper(
     IServiceProvider serviceProvider,
     SeededEntities seededEntities
     )
 {
     _serviceProvider = serviceProvider;
     _seededEntities  = seededEntities;
 }
 public UnstructuredDataTestDataHelper(
     IServiceProvider serviceProvider,
     SeededEntities seededEntities
     )
 {
     _serviceProvider = serviceProvider;
     _seededEntities  = seededEntities;
 }
 public TestDataHelper(
     IServiceProvider rootServiceProvider,
     SeededEntities seededEntities
     )
 {
     _rootServiceProvider  = rootServiceProvider;
     _seededEntities       = seededEntities;
     _permissionRepository = rootServiceProvider.GetRequiredService <IPermissionRepository>();
 }
Exemple #5
0
 public RoleTestDataHelper(
     IServiceProvider serviceProvider,
     SeededEntities seededEntities,
     IPermissionRepository permissionRepository
     )
 {
     _serviceProvider      = serviceProvider;
     _seededEntities       = seededEntities;
     _permissionRepository = permissionRepository;
 }
        /// <summary>
        /// Called by xUnit after the class has been created, this bootstraps
        /// the database at the start of the test session.
        /// </summary>
        /// <returns></returns>
        public virtual async Task InitializeAsync()
        {
            _serviceProvider = DbDependentTestApplicationServiceProviderFactory.CreateTestHostProvider();
            var dbInitializer = new TestDatabaseInitializer(_serviceProvider);
            await dbInitializer.InitializeCofoundry();

            await dbInitializer.DeleteTestData();

            _seededEntities = await dbInitializer.SeedGlobalEntities();
        }
 public DbDependentTestApplication(
     IServiceProvider serviceProvider,
     SeededEntities seededEntities
     )
 {
     _rootServiceProvider = serviceProvider;
     Services             = new TestApplicationServiceScope(_rootServiceProvider);
     SeededEntities       = seededEntities;
     TestData             = new TestDataHelper(_rootServiceProvider, SeededEntities);
     Mocks = new MockServicesHelper(Services);
 }
Exemple #8
0
        /// <summary>
        /// Initializes any static/global test data references. These references can
        /// be used for convenience in multiple tests as references but should not be altered.
        /// </summary>
        public async Task <SeededEntities> SeedGlobalEntities()
        {
            var seededEntities = new SeededEntities();

            using var scope = _serviceProvider.CreateScope();

            var contentRepository = scope
                                    .ServiceProvider
                                    .GetRequiredService <IAdvancedContentRepository>()
                                    .WithElevatedPermissions();

            var dbContext = scope.ServiceProvider.GetRequiredService <CofoundryDbContext>();

            // Setup

            var settings = await contentRepository.ExecuteQueryAsync(new GetSettingsQuery <InternalSettings>());

            if (!settings.IsSetup)
            {
                await contentRepository.ExecuteCommandAsync(new SetupCofoundryCommand()
                {
                    ApplicationName = "Test Site",
                    Email           = seededEntities.AdminUser.Username,
                    DisplayName     = "Test Admin",
                    Password        = seededEntities.AdminUser.Password
                });
            }

            // Users

            seededEntities.AdminUser.UserId = await dbContext
                                              .Users
                                              .AsNoTracking()
                                              .Where(u => u.Username == seededEntities.AdminUser.Username)
                                              .Select(u => u.UserId)
                                              .SingleAsync();

            // Page Templates

            var testTemplate = await dbContext
                               .PageTemplates
                               .AsNoTracking()
                               .Include(t => t.PageTemplateRegions)
                               .Where(t => t.FileName == "TestTemplate")
                               .SingleAsync();

            seededEntities.TestPageTemplate.PageTemplateId           = testTemplate.PageTemplateId;
            seededEntities.TestPageTemplate.BodyPageTemplateRegionId = testTemplate
                                                                       .PageTemplateRegions
                                                                       .Select(t => t.PageTemplateRegionId)
                                                                       .Single();

            var testCustomEntityPageTemplate = await dbContext
                                               .PageTemplates
                                               .AsNoTracking()
                                               .Include(t => t.PageTemplateRegions)
                                               .Where(t => t.FileName == "TestCustomEntityTemplate")
                                               .SingleAsync();

            seededEntities.TestCustomEntityPageTemplate.PageTemplateId           = testCustomEntityPageTemplate.PageTemplateId;
            seededEntities.TestCustomEntityPageTemplate.BodyPageTemplateRegionId = testCustomEntityPageTemplate
                                                                                   .PageTemplateRegions
                                                                                   .Where(t => !t.IsCustomEntityRegion)
                                                                                   .Select(t => t.PageTemplateRegionId)
                                                                                   .Single();
            seededEntities.TestCustomEntityPageTemplate.CustomEntityBodyPageTemplateRegionId = testCustomEntityPageTemplate
                                                                                               .PageTemplateRegions
                                                                                               .Where(t => t.IsCustomEntityRegion)
                                                                                               .Select(t => t.PageTemplateRegionId)
                                                                                               .Single();

            // Images

            var mockImageAssetFileService = scope.ServiceProvider.GetService <IImageAssetFileService>() as MockImageAssetFileService;

            mockImageAssetFileService.SaveFile       = false;
            mockImageAssetFileService.WidthInPixels  = 80;
            mockImageAssetFileService.HeightInPixels = 80;

            seededEntities.TestImageId = await contentRepository
                                         .ImageAssets()
                                         .AddAsync(new AddImageAssetCommand()
            {
                Title = "Test Image",
                File  = new EmbeddedResourceFileSource(this.GetType().Assembly, "Cofoundry.Domain.Tests.Integration.Shared.SeedData.Images", "Test jpg 80x80.jpg")
            });

            // Tags

            var testTag = new Tag()
            {
                TagText    = seededEntities.TestTag.TagText,
                CreateDate = DateTime.UtcNow
            };

            dbContext.Tags.Add(testTag);
            await dbContext.SaveChangesAsync();

            seededEntities.TestTag.TagId = testTag.TagId;

            // Directories

            seededEntities.RootDirectoryId = await dbContext
                                             .PageDirectories
                                             .AsNoTracking()
                                             .Where(d => !d.ParentPageDirectoryId.HasValue)
                                             .Select(d => d.PageDirectoryId)
                                             .SingleAsync();

            seededEntities.TestDirectory.PageDirectoryId = await contentRepository
                                                           .PageDirectories()
                                                           .AddAsync(new AddPageDirectoryCommand()
            {
                Name = "Test Directory",
                ParentPageDirectoryId = seededEntities.RootDirectoryId,
                UrlPath = seededEntities.TestDirectory.UrlPath
            });

            // Pages

            seededEntities.TestDirectory.GenericPage.PageId = await contentRepository
                                                              .Pages()
                                                              .AddAsync(new AddPageCommand()
            {
                Title           = seededEntities.TestDirectory.GenericPage.Title,
                PageType        = PageType.Generic,
                PageDirectoryId = seededEntities.TestDirectory.PageDirectoryId,
                UrlPath         = seededEntities.TestDirectory.GenericPage.UrlPath,
                PageTemplateId  = seededEntities.TestPageTemplate.PageTemplateId,
                Publish         = true
            });

            seededEntities.TestDirectory.CustomEntityPage.PageId = await contentRepository
                                                                   .Pages()
                                                                   .AddAsync(new AddPageCommand()
            {
                Title                   = seededEntities.TestDirectory.CustomEntityPage.Title,
                PageType                = PageType.CustomEntityDetails,
                PageDirectoryId         = seededEntities.TestDirectory.PageDirectoryId,
                CustomEntityRoutingRule = seededEntities.TestDirectory.CustomEntityPage.RoutingRule.RouteFormat,
                PageTemplateId          = seededEntities.TestCustomEntityPageTemplate.PageTemplateId,
                Publish                 = true
            });

            // Custom Entities
            await AddCustomEntity(seededEntities.TestCustomEntity, contentRepository);
            await AddCustomEntity(seededEntities.CustomEntityForUnstructuredDataTests, contentRepository);

            // User areas

            await InitUserAreaAsync(seededEntities.TestUserArea1, dbContext, contentRepository);
            await InitUserAreaAsync(seededEntities.TestUserArea2, dbContext, contentRepository);

            return(seededEntities);
        }