public async Task HostsStaticAssets(string path) { // Arrange await using var fixture = new StartupFilterTestFixture(services => { }); await fixture.InitializeAsync(); var resolvedPath = path.Replace("{version}", HtmlSnippets.GdsLibraryVersion); var request = new HttpRequestMessage(HttpMethod.Get, resolvedPath); // Act var response = await fixture.HttpClient.SendAsync(request); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public async Task AddImportsToHtmlIsTrue_AddsStyleAndScriptImportsToRazorViews() { // Arrange await using var fixture = new StartupFilterTestFixture(services => { services.Configure <GovUkFrontendAspNetCoreOptions>(options => options.AddImportsToHtml = true); }); await fixture.InitializeAsync(); var request = new HttpRequestMessage(HttpMethod.Get, "/Empty"); // Act var response = await fixture.HttpClient.SendAsync(request); // Assert response.EnsureSuccessStatusCode(); var html = await response.GetHtmlDocument(); var head = html.QuerySelector("head"); var linkTags = head.QuerySelectorAll("link"); Assert.Contains( $"/govuk-frontend-{HtmlSnippets.GdsLibraryVersion}.min.css", linkTags .Where(t => t.GetAttribute("rel") == "stylesheet") .Select(t => t.GetAttribute("href"))); var body = html.QuerySelector("body"); Assert.Contains("govuk-template__body", body.ClassList); var bodyScriptTags = body.QuerySelectorAll("script"); Assert.Contains( $"/govuk-frontend-{HtmlSnippets.GdsLibraryVersion}.min.js", bodyScriptTags.Select(t => t.GetAttribute("src"))); Assert.Contains( $"window.GOVUKFrontend.initAll()", bodyScriptTags.Select(t => t.InnerHtml)); }