-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathNavigationRootTests.cs
More file actions
90 lines (77 loc) · 4.2 KB
/
NavigationRootTests.cs
File metadata and controls
90 lines (77 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using AngleSharp;
using AwesomeAssertions;
using Documentation.Builder;
using Elastic.Documentation;
using Elastic.Documentation.Assembler;
using Elastic.Documentation.Assembler.Sourcing;
using Elastic.Documentation.Configuration;
using Elastic.Documentation.Configuration.Assembler;
using Elastic.Documentation.Configuration.Toc;
using Elastic.Documentation.Navigation;
using Elastic.Documentation.Navigation.Assembler;
using Elastic.Documentation.Navigation.Isolated;
using Elastic.Documentation.Navigation.Isolated.Leaf;
using Elastic.Documentation.ServiceDefaults;
using Elastic.Documentation.Site.Navigation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Nullean.ScopedFileSystem;
using RazorSlices;
namespace Elastic.Documentation.IntegrationTests;
public class NavigationRootTests(DocumentationFixture fixture, ITestOutputHelper output) : IAsyncLifetime
{
[Fact(Skip = "Assert.SkipWhen not working on CI")]
public async Task AssertRealNavigation()
{
//Skipping on CI since this relies on checking out private repositories
Assert.SkipWhen(!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CI")), "Skipping in CI");
var builder = Host.CreateApplicationBuilder()
.AddDocumentationServiceDefaults((s, p) =>
{
_ = s.AddSingleton(AssemblyConfiguration.Create(p));
})
.AddDocumentationToolingDefaults();
var host = builder.Build();
var configurationContext = host.Services.GetRequiredService<IConfigurationContext>();
var assemblyConfiguration = AssemblyConfiguration.Create(configurationContext.ConfigurationFileProvider);
var collector = new TestDiagnosticsCollector(TestContext.Current.TestOutputHelper);
var fs = new FileSystem();
var assembleContext = new AssembleContext(assemblyConfiguration, configurationContext, "dev", collector, FileSystemFactory.ScopeCurrentWorkingDirectory(fs), FileSystemFactory.ScopeCurrentWorkingDirectory(new MockFileSystem()), null, null);
var logFactory = new TestLoggerFactory(TestContext.Current.TestOutputHelper);
var cloner = new AssemblerRepositorySourcer(logFactory, assembleContext);
var checkoutResult = cloner.GetAll();
var checkouts = checkoutResult.Checkouts.ToArray();
_ = collector.StartAsync(TestContext.Current.CancellationToken);
if (checkouts.Length == 0)
throw new Exception("No checkouts found");
var ctx = TestContext.Current.CancellationToken;
var assembleSources = await AssembleSources.AssembleAsync(logFactory, assembleContext, checkouts, configurationContext, new HashSet<Exporter>(), ctx);
var navigationFileInfo = configurationContext.ConfigurationFileProvider.NavigationFile;
var siteNavigationFile = SiteNavigationFile.Deserialize(await fs.File.ReadAllTextAsync(navigationFileInfo.FullName, ctx));
var documentationSets = assembleSources.AssembleSets.Values.Select(s => s.DocumentationSet.Navigation).ToArray();
var navigation = new SiteNavigation(siteNavigationFile, assembleContext, documentationSets, assembleContext.Environment.PathPrefix);
var allowedRoots = navigation.TopLevelItems.Concat([navigation]).ToHashSet();
foreach (var item in ((INavigationTraversable)navigation).YieldAll())
item.NavigationRoot.Should().BeOneOf(allowedRoots, "Navigation for '{0}' has bad root '{1}'", item.Url, item.NavigationRoot.Identifier);
foreach (var item in ((INavigationTraversable)navigation).NavigationIndexedByOrder.Values)
item.NavigationRoot.Should().BeOneOf(allowedRoots, "Navigation for '{0}' has bad root '{1}' indexed by order {2}", item.Url, item.NavigationRoot.Identifier, item.NavigationIndex);
collector.Errors.Should().Be(0);
}
/// <inheritdoc />
public ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
if (TestContext.Current.TestState?.Result is not TestResult.Failed)
return default;
foreach (var resource in fixture.InMemoryLogger.RecordedLogs)
output.WriteLine(resource.Message);
return default;
}
/// <inheritdoc />
public ValueTask InitializeAsync() => default;
}