D_Inventor
02/23/2025, 3:41 PMD_Inventor
02/23/2025, 3:42 PMcsharp
[Fact]
public async Task HomepageDirectLinkRedirectsToRootAsync()
{
// arrange
await PrepareAsync(); //<-- make sure site is booted, make sure indexes are built-up
IUmbracoContextFactory umbracoContextFactory = ServiceProvider.GetRequiredService<IUmbracoContextFactory>();
var documentNavigationService = this.ServiceProvider.GetRequiredService<IDocumentNavigationQueryService>();
using Umbraco.Cms.Core.UmbracoContextReference cref = umbracoContextFactory.EnsureUmbracoContext();
documentNavigationService.TryGetRootKeysOfType(WebsiteRoot.ModelTypeAlias, out var websiteKeys);
documentNavigationService.TryGetChildrenKeysOfType(websiteKeys.First(), HomePage.ModelTypeAlias, out var homepageKeys);
WebsiteRoot? root = await cref.UmbracoContext.Content.GetByIdAsync(websiteKeys.First()) as WebsiteRoot;
HomePage? homepage = await cref.UmbracoContext.Content.GetByIdAsync(homepageKeys.First()) as HomePage;
HttpClient nonRedirectClient = WebsiteFactory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
// act
HttpResponseMessage response = await nonRedirectClient.GetAsync(homepage!.Url());
// assert
response.StatusCode.ShouldBe(HttpStatusCode.MovedPermanently);
response.Headers.Location.ShouldNotBeNull();
response.Headers.Location.ShouldBe(new Uri(root!.Url(), UriKind.RelativeOrAbsolute));
}
D_Inventor
02/23/2025, 3:52 PMD_Inventor
02/24/2025, 7:28 PM