13
13
14
14
namespace Documentation . Assembler . Tests ;
15
15
16
- #pragma warning disable xUnit1004
17
-
18
16
public class GlobalNavigationPathProviderTests
19
17
{
18
+ private DiagnosticsCollector Collector { get ; }
19
+ private AssembleContext Context { get ; }
20
+ private FileSystem FileSystem { get ; }
21
+ private IDirectoryInfo CheckoutDirectory { get ; set ; }
22
+
23
+ private bool HasCheckouts ( ) => CheckoutDirectory . Exists ;
24
+
25
+ public GlobalNavigationPathProviderTests ( )
26
+ {
27
+ FileSystem = new FileSystem ( ) ;
28
+ CheckoutDirectory = FileSystem . DirectoryInfo . New (
29
+ FileSystem . Path . Combine ( Paths . GetSolutionDirectory ( ) ! . FullName , ".artifacts" , "checkouts" )
30
+ ) ;
31
+ Collector = new DiagnosticsCollector ( [ ] ) ;
32
+ Context = new AssembleContext ( "dev" , Collector , FileSystem , FileSystem , CheckoutDirectory . FullName , null ) ;
33
+ }
34
+
35
+ private Checkout CreateCheckout ( IFileSystem fs , string name ) =>
36
+ new ( )
37
+ {
38
+ Repository = new Repository
39
+ {
40
+ Name = name ,
41
+ Origin = $ "elastic/{ name } "
42
+ } ,
43
+ HeadReference = Guid . NewGuid ( ) . ToString ( ) ,
44
+ Directory = fs . DirectoryInfo . New ( fs . Path . Combine ( Path . Combine ( CheckoutDirectory . FullName , name ) ) )
45
+ } ;
46
+
47
+ private async Task < AssembleSources > Setup ( )
48
+ {
49
+ _ = Collector . StartAsync ( TestContext . Current . CancellationToken ) ;
50
+
51
+ string [ ] nar = [ NarrativeRepository . RepositoryName ] ;
52
+ var repos = nar . Concat ( Context . Configuration . ReferenceRepositories
53
+ . Where ( kv => ! kv . Value . Skip )
54
+ . Select ( kv => kv . Value . Name )
55
+ )
56
+ . ToArray ( ) ;
57
+ var checkouts = repos . Select ( r => CreateCheckout ( FileSystem , r ) ) . ToArray ( ) ;
58
+
59
+ var assembleSources = await AssembleSources . AssembleAsync ( Context , checkouts , TestContext . Current . CancellationToken ) ;
60
+ return assembleSources ;
61
+ }
20
62
21
- [ Fact ( Skip = "Requires local checkout folder" ) ]
63
+ [ Fact ]
22
64
public async Task ParsesReferences ( )
23
65
{
66
+ Assert . SkipUnless ( HasCheckouts ( ) , $ "Requires local checkout folder: { CheckoutDirectory . FullName } ") ;
67
+
24
68
var expectedRoot = new Uri ( "docs-content://reference/" ) ;
25
- var expectedParent = new Uri ( "docs-content://reference/ingestion-tools/ apm/ agents/" ) ;
69
+ var expectedParent = new Uri ( "docs-content://reference/apm- agents/" ) ;
26
70
var sut = new Uri ( "apm-agent-dotnet://reference/" ) ;
27
71
var clients = new Uri ( "docs-content://reference/elasticsearch-clients/" ) ;
28
- var fs = new FileSystem ( ) ;
29
- var ( assembleContext , assembleSources ) = await Setup ( fs ) ;
72
+ var assembleSources = await Setup ( ) ;
30
73
31
74
assembleSources . TocTopLevelMappings . Should ( ) . NotBeEmpty ( ) . And . ContainKey ( sut ) ;
32
75
assembleSources . TocTopLevelMappings [ sut ] . TopLevelSource . Should ( ) . Be ( expectedRoot ) ;
33
76
assembleSources . TocTopLevelMappings . Should ( ) . NotBeEmpty ( ) . And . ContainKey ( expectedRoot ) ;
34
77
assembleSources . TocTopLevelMappings [ sut ] . ParentSource . Should ( ) . Be ( expectedParent ) ;
35
78
36
- var navigationFile = new GlobalNavigationFile ( assembleContext , assembleSources ) ;
79
+ var navigationFile = new GlobalNavigationFile ( Context , assembleSources ) ;
37
80
var referenceToc = navigationFile . TableOfContents . FirstOrDefault ( t => t . Source == expectedRoot ) ;
38
81
referenceToc . Should ( ) . NotBeNull ( ) ;
39
82
referenceToc ! . TocReferences . Should ( ) . NotContainKey ( clients ) ;
@@ -54,6 +97,9 @@ public async Task ParsesReferences()
54
97
var referenceNav = navigation . NavigationLookup [ expectedRoot ] ;
55
98
navigation . NavigationItems . Should ( ) . HaveSameCount ( navigation . NavigationLookup ) ;
56
99
100
+ var referenceOrder = referenceNav . Group . NavigationItems . OfType < TocNavigationItem > ( )
101
+ . Last ( ) . Source . Should ( ) . Be ( new Uri ( "docs-content://reference/glossary/" ) ) ;
102
+
57
103
referenceNav . Should ( ) . NotBeNull ( ) ;
58
104
referenceNav . NavigationLookup . Should ( ) . NotContainKey ( clients ) ;
59
105
referenceNav . Group . NavigationItems . OfType < TocNavigationItem > ( )
@@ -84,14 +130,15 @@ public async Task ParsesReferences()
84
130
85
131
86
132
87
- [ Fact ( Skip = "Requires local checkout folder" ) ]
133
+ [ Fact ]
88
134
public async Task ParsesGlobalNavigation ( )
89
135
{
136
+ Assert . SkipUnless ( HasCheckouts ( ) , $ "Requires local checkout folder: { CheckoutDirectory . FullName } ") ;
137
+
90
138
var expectedRoot = new Uri ( "docs-content://extend" ) ;
91
139
var kibanaExtendMoniker = new Uri ( "kibana://extend/" ) ;
92
- var fs = new FileSystem ( ) ;
93
140
94
- var ( assembleContext , assembleSources ) = await Setup ( fs ) ;
141
+ var assembleSources = await Setup ( ) ;
95
142
assembleSources . TocTopLevelMappings . Should ( ) . NotBeEmpty ( ) . And . ContainKey ( kibanaExtendMoniker ) ;
96
143
assembleSources . TocTopLevelMappings [ kibanaExtendMoniker ] . TopLevelSource . Should ( ) . Be ( expectedRoot ) ;
97
144
assembleSources . TocTopLevelMappings . Should ( ) . NotBeEmpty ( ) . And . ContainKey ( new Uri ( "docs-content://reference/apm/" ) ) ;
@@ -112,7 +159,7 @@ public async Task ParsesGlobalNavigation()
112
159
kibanaConfigMapping . TableOfContentsConfiguration . Should ( ) . NotBeNull ( ) ;
113
160
assembleSources . TocConfigurationMapping [ kibanaExtendMoniker ] . Should ( ) . NotBeNull ( ) ;
114
161
115
- var navigationFile = new GlobalNavigationFile ( assembleContext , assembleSources ) ;
162
+ var navigationFile = new GlobalNavigationFile ( Context , assembleSources ) ;
116
163
navigationFile . TableOfContents . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) ;
117
164
navigationFile . TableOfContents . Count . Should ( ) . BeLessThan ( 20 ) ;
118
165
@@ -122,40 +169,11 @@ public async Task ParsesGlobalNavigation()
122
169
resolved . Should ( ) . NotBeNull ( ) ;
123
170
}
124
171
125
- private static async Task < ( AssembleContext assembleContext , AssembleSources assembleSources ) > Setup ( FileSystem fs )
126
- {
127
- await using var collector = new DiagnosticsCollector ( [ ] ) ;
128
- _ = collector . StartAsync ( TestContext . Current . CancellationToken ) ;
129
-
130
- var assembleContext = new AssembleContext ( "dev" , collector , fs , fs , null , null ) ;
131
-
132
- string [ ] nar = [ NarrativeRepository . RepositoryName ] ;
133
- var repos = nar . Concat ( assembleContext . Configuration . ReferenceRepositories
134
- . Where ( kv => ! kv . Value . Skip )
135
- . Select ( kv => kv . Value . Name )
136
- )
137
- . ToArray ( ) ;
138
- var checkouts = repos . Select ( r => CreateCheckout ( fs , r ) ) . ToArray ( ) ;
139
-
140
- var assembleSources = await AssembleSources . AssembleAsync ( assembleContext , checkouts , TestContext . Current . CancellationToken ) ;
141
- return ( assembleContext , assembleSources ) ;
142
- }
143
-
144
- private static Checkout CreateCheckout ( IFileSystem fs , string name ) =>
145
- new ( )
146
- {
147
- Repository = new Repository
148
- {
149
- Name = name ,
150
- Origin = $ "elastic/{ name } "
151
- } ,
152
- HeadReference = Guid . NewGuid ( ) . ToString ( ) ,
153
- Directory = fs . DirectoryInfo . New ( fs . Path . Combine ( Paths . GetSolutionDirectory ( ) ! . FullName , ".artifacts" , "checkouts" , name ) )
154
- } ;
155
-
156
- [ Fact ( Skip = "Requires local checkout folder" ) ]
172
+ [ Fact ]
157
173
public async Task UriResolving ( )
158
174
{
175
+ Assert . SkipUnless ( HasCheckouts ( ) , $ "Requires local checkout folder: { CheckoutDirectory . FullName } ") ;
176
+
159
177
await using var collector = new DiagnosticsCollector ( [ ] ) ;
160
178
_ = collector . StartAsync ( TestContext . Current . CancellationToken ) ;
161
179
0 commit comments