22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
44
5- using System . Collections . ObjectModel ;
6- using System . IO . Abstractions ;
5+ using Aspire . Hosting ;
76using Aspire . Hosting . Testing ;
8- using Documentation . Assembler ;
9- using Documentation . Assembler . Building ;
10- using Documentation . Assembler . Legacy ;
11- using Documentation . Assembler . Navigation ;
12- using Documentation . Assembler . Sourcing ;
13- using Documentation . Builder . Http ;
14- using Elastic . Documentation . Configuration ;
15- using Elastic . Documentation . Configuration . Assembler ;
16- using Elastic . Documentation . Configuration . Versions ;
17- using Elastic . Documentation . LegacyDocs ;
18- using Elastic . Documentation . Tooling ;
19- using Elastic . Documentation . Tooling . Diagnostics . Console ;
20- using Microsoft . Extensions . Logging ;
217using FluentAssertions ;
22- using Xunit ;
238
249[ assembly: CaptureConsole , AssemblyFixture ( typeof ( Elastic . Assembler . IntegrationTests . AssembleFixture ) ) ]
2510
@@ -28,85 +13,37 @@ namespace Elastic.Assembler.IntegrationTests;
2813
2914public class AssembleFixture : IAsyncLifetime
3015{
31- private static IFileSystem FileSystem { get ; } = new FileSystem ( ) ;
32- public ConfigurationFileProvider ConfigurationFileProvider { get ; } = new ( FileSystem ) ;
33- public StaticWebHost WebsiteHost { get ; private set ; } = null ! ;
34- public Task WebsiteRunning { get ; private set ; } = null ! ;
16+ public DistributedApplication DistributedApplication { get ; private set ; } = null ! ;
3517
3618 /// <inheritdoc />
37- public async ValueTask DisposeAsync ( )
19+ public async ValueTask InitializeAsync ( )
3820 {
39- GC . SuppressFinalize ( this ) ;
40- await WebsiteHost . StopAsync ( TestContext . Current . CancellationToken ) ;
21+ var builder = await DistributedApplicationTestingBuilder . CreateAsync < Projects . Elastic_Documentation_Aspire > ( ) ;
22+ DistributedApplication = await builder . BuildAsync ( ) ;
23+ await DistributedApplication . StartAsync ( ) ;
4124 }
4225
4326 /// <inheritdoc />
44- public async ValueTask InitializeAsync ( )
27+ public async ValueTask DisposeAsync ( )
4528 {
46- //var builder = await DistributedApplicationTestingBuilder.CreateAsync([]);
47- var ctx = TestContext . Current . CancellationToken ;
48- var logFactory = LoggerFactory . Create ( builder =>
49- {
50- _ = builder . AddConsole ( ) ;
51- } ) ;
52- await using var collector = new ConsoleDiagnosticsCollector ( logFactory , null ) . StartAsync ( ctx ) ;
53-
54- var assemblyConfiguration = AssemblyConfiguration . Create ( ConfigurationFileProvider ) ;
55- var versionsConfig = ConfigurationFileProvider . CreateVersionConfiguration ( ) ;
56-
57- var assembleContext = new AssembleContext ( assemblyConfiguration , ConfigurationFileProvider , "dev" , collector , FileSystem , FileSystem , null , null ) ;
58- var cloner = new AssemblerRepositorySourcer ( logFactory , assembleContext ) ;
59-
60- _ = await cloner . CloneAll ( false , ctx ) ;
61-
62- _ = GlobalNavigationFile . ValidatePathPrefixes ( assembleContext ) ;
63-
64- var checkoutResult = cloner . GetAll ( ) ;
65- var checkouts = checkoutResult . Checkouts . ToArray ( ) ;
66-
67- if ( checkouts . Length == 0 )
68- throw new Exception ( "No checkouts found" ) ;
69-
70- var assembleSources = await AssembleSources . AssembleAsync ( logFactory , assembleContext , checkouts , versionsConfig , ctx ) ;
71- var navigationFile = new GlobalNavigationFile ( assembleContext , assembleSources ) ;
72-
73- var navigation = new GlobalNavigation ( assembleSources , navigationFile ) ;
74-
75- var pathProvider = new GlobalNavigationPathProvider ( navigationFile , assembleSources , assembleContext ) ;
76- var htmlWriter = new GlobalNavigationHtmlWriter ( logFactory , navigation , collector ) ;
77- var legacyPageChecker = new LegacyPageChecker ( ) ;
78- var historyMapper = new PageLegacyUrlMapper ( legacyPageChecker , assembleSources . HistoryMappings ) ;
79-
80- var exporters = new HashSet < ExportOption > ( [ ExportOption . Html , ExportOption . Configuration ] ) ;
81- var builder = new AssemblerBuilder ( logFactory , assembleContext , navigation , htmlWriter , pathProvider , historyMapper ) ;
82- await builder . BuildAllAsync ( assembleSources . AssembleSets , exporters , ctx ) ;
83-
84- await cloner . WriteLinkRegistrySnapshot ( checkoutResult . LinkRegistrySnapshot , ctx ) ;
85-
86- var redirectsPath = Path . Combine ( assembleContext . OutputDirectory . FullName , "redirects.json" ) ;
87-
88- var sitemapBuilder = new SitemapBuilder ( navigation . NavigationItems , assembleContext . WriteFileSystem , assembleContext . OutputDirectory ) ;
89- sitemapBuilder . Generate ( ) ;
90-
91- await collector . StopAsync ( ctx ) ;
92-
93- WebsiteHost = new StaticWebHost ( 4001 ) ;
94- WebsiteRunning = WebsiteHost . RunAsync ( ctx ) ;
95- _ = await WebsiteHost . WaitForAppStartup ( ctx ) ;
29+ await DistributedApplication . StopAsync ( ) ;
30+ await DistributedApplication . DisposeAsync ( ) ;
31+ GC . SuppressFinalize ( this ) ;
9632 }
9733
34+
9835}
9936
10037public class DatabaseTestClass1 ( AssembleFixture fixture )
10138{
10239 [ Fact ]
10340 public async Task X ( )
10441 {
105- using var client = new HttpClient { BaseAddress = new Uri ( "http://localhost:4001" ) } ;
42+ _ = await fixture . DistributedApplication . ResourceNotifications
43+ . WaitForResourceHealthyAsync ( "DocsBuilderServeStatic" , cancellationToken : TestContext . Current . CancellationToken ) ;
44+ var client = fixture . DistributedApplication . CreateHttpClient ( "DocsBuilderServeStatic" , "http" ) ;
10645 var root = await client . GetStringAsync ( "/" , TestContext . Current . CancellationToken ) ;
107- Console . WriteLine ( root ) ;
108-
109- fixture . Should ( ) . NotBeNull ( ) ;
46+ _ = root . Should ( ) . NotBeNullOrEmpty ( ) ;
11047 }
11148
11249
0 commit comments