11using System . Reflection ;
22using EPiServer ;
3- using EPiServer . Cms . Shell ;
4- using Microsoft . Extensions . Hosting ;
5- using Microsoft . Extensions . DependencyInjection ;
6- using EPiServer . Framework . Initialization ;
73using EPiServer . Core ;
8- using EPiServer . Data ;
94using EPiServer . DataAccess ;
10- using EPiServer . Framework ;
11- using EPiServer . Framework . Web ;
125using EPiServer . Security ;
136using EPiServer . Web ;
14- using EPiServer . Web . Templating ;
15- using Microsoft . AspNetCore . Hosting ;
16- using Optimizely . TestContainers ;
17- using Optimizely . TestContainers . Models ;
7+ using Microsoft . Extensions . DependencyInjection ;
188using Optimizely . TestContainers . Models . Pages ;
19- using OptimizelyTestContainers . Tests ;
20- using Testcontainers . MsSql ;
21-
22- public class NewsPageIntegrationTest : IAsyncLifetime
23- {
24- private IHost _host ;
25- private IServiceProvider _services ;
26- private MsSqlContainer _dbContainer ;
27-
28- public async Task InitializeAsync ( )
29- {
30- // Start SQL Server container
31- _dbContainer = new MsSqlBuilder ( )
32- . WithImage ( "mcr.microsoft.com/mssql/server:2022-latest" )
33- . WithPassword ( "yourStrong(!)Password" )
34- . Build ( ) ;
359
36- await _dbContainer . StartAsync ( ) ;
37-
38- // Build CMS host
39- _host = Host . CreateDefaultBuilder ( )
40- . ConfigureCmsDefaults ( )
41- . ConfigureWebHostDefaults ( webBuilder =>
42- {
43- webBuilder . ConfigureServices ( ( context , services ) =>
44- {
45- services . AddCms ( ) ;
46- services . AddCmsHost ( ) ;
47- services . AddCmsFrameworkWeb ( ) ;
48-
49- services . AddCmsCoreWeb ( ) ; // Adds core CMS services
50- services . AddCmsTemplating ( ) ;
51- services . AddCmsUI ( ) ;
52-
53- services . Configure < DataAccessOptions > ( opt =>
54- {
55- var cs = _dbContainer . GetConnectionString ( ) ;
56-
57- opt . SetConnectionString ( cs ) ;
58- } ) ;
59-
60- services . AddTransient < OptimizelyDataImporter > ( ) ;
61- } ) ;
62-
63- webBuilder . UseStartup < Startup > ( ) ;
64- } )
65- . Build ( ) ;
66-
67-
68-
69-
70- await _host . StartAsync ( ) ;
71-
72- // Run initialization engine (simulate application startup)
73- var initializer = _host . Services . GetRequiredService < InitializationEngine > ( ) ;
74- if ( initializer . InitializationState != InitializationState . Initialized )
75- initializer . Initialize ( ) ;
76-
77- _services = _host . Services ;
78- }
79-
80- public async Task DisposeAsync ( )
81- {
82- await _host . StopAsync ( ) ;
83- await _dbContainer . DisposeAsync ( ) ;
84- }
10+ namespace OptimizelyTestContainers . Tests ;
8511
12+ public class NewsPageIntegrationTest : OptimizelyIntegrationTestBase
13+ {
8614 [ Fact ]
8715 public void Can_Create_And_Read_NewsPage ( )
8816 {
8917 // Arrange
90- var repo = _services . GetRequiredService < IContentRepository > ( ) ;
18+ var repo = Services . GetRequiredService < IContentRepository > ( ) ;
9119
9220 // Import test data
9321 var basePath = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ! ;
9422 var episerverDataFile = Path . Combine ( basePath , "DefaultSiteContent.episerverdata" ) ;
9523
96- var dataImporter = _services . GetRequiredService < OptimizelyDataImporter > ( ) ;
24+ var dataImporter = Services . GetRequiredService < OptimizelyDataImporter > ( ) ;
9725 dataImporter . Import ( episerverDataFile ) ;
9826
9927
@@ -102,7 +30,7 @@ public void Can_Create_And_Read_NewsPage()
10230
10331 var startPage = repo . GetChildren < StartPage > ( ContentReference . RootPage ) . First ( ) ;
10432
105- var siteDefinitionRepo = _services . GetRequiredService < ISiteDefinitionRepository > ( ) ;
33+ var siteDefinitionRepo = Services . GetRequiredService < ISiteDefinitionRepository > ( ) ;
10634
10735 siteDefinitionRepo . Save ( new SiteDefinition ( )
10836 {
@@ -127,4 +55,4 @@ public void Can_Create_And_Read_NewsPage()
12755 Assert . NotNull ( loaded ) ;
12856 Assert . Equal ( "Martians Landed in Stockholm" , loaded . Title ) ;
12957 }
130- }
58+ }
0 commit comments