-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ljfio/feature/integration-tests
Multiple Domain Fixes (and Integration Tests)
- Loading branch information
Showing
99 changed files
with
3,753 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
appsettings*.json |
44 changes: 44 additions & 0 deletions
44
src/Our.Umbraco.InvisibleNodes.Tests.Integration/Core/TestWebApplicationFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 Luke Fisher | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Microsoft.Data.Sqlite; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Our.Umbraco.InvisibleNodes.Tests.Integration.Core; | ||
|
||
[Collection("Web")] | ||
public class TestWebApplicationFactory : WebApplicationFactory<Program> | ||
{ | ||
private readonly string _connectionString = "Data Source=InMemory;Mode=Memory;Cache=Shared;Pooling=True"; | ||
private readonly SqliteConnection _sharedConnection; | ||
|
||
public TestWebApplicationFactory() | ||
{ | ||
_sharedConnection = new SqliteConnection(_connectionString); | ||
_sharedConnection.Open(); | ||
} | ||
|
||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
builder.ConfigureAppConfiguration(config => | ||
{ | ||
var inlineConfig = new Dictionary<string, string?>() | ||
{ | ||
{ "ConnectionStrings:umbracoDbDSN", _connectionString }, | ||
}; | ||
|
||
config.AddInMemoryCollection(inlineConfig); | ||
}); | ||
|
||
builder.UseEnvironment("Development"); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
_sharedConnection.Dispose(); | ||
base.Dispose(disposing); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Our.Umbraco.InvisibleNodes.Tests.Integration/Core/TestWebApplicationFactoryCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2023 Luke Fisher | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace Our.Umbraco.InvisibleNodes.Tests.Integration.Core; | ||
|
||
[CollectionDefinition("Web")] | ||
public class TestWebApplicationFactoryCollection : ICollectionFixture<TestWebApplicationFactory> | ||
{ | ||
} |
1 change: 1 addition & 0 deletions
1
src/Our.Umbraco.InvisibleNodes.Tests.Integration/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
29 changes: 29 additions & 0 deletions
29
...raco.InvisibleNodes.Tests.Integration/Our.Umbraco.InvisibleNodes.Tests.Integration.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/> | ||
<PackageReference Include="xunit" Version="2.4.2"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UmbracoExampleWeb\UmbracoExampleWeb.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
178 changes: 178 additions & 0 deletions
178
src/Our.Umbraco.InvisibleNodes.Tests.Integration/Tests/DomainTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Copyright 2023 Luke Fisher | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Our.Umbraco.InvisibleNodes.Tests.Integration.Core; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Core.Models; | ||
using Umbraco.Cms.Core.Models.PublishedContent; | ||
using Umbraco.Cms.Core.Routing; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core.Web; | ||
using Umbraco.Cms.Web.Common.PublishedModels; | ||
|
||
namespace Our.Umbraco.InvisibleNodes.Tests.Integration.Tests; | ||
|
||
[Collection("Web")] | ||
public class DomainTests : IDisposable | ||
{ | ||
private readonly TestWebApplicationFactory _factory; | ||
|
||
public DomainTests(TestWebApplicationFactory factory) | ||
{ | ||
_factory = factory; | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Nested() | ||
{ | ||
var contextFactory = _factory.Services.GetRequiredService<IUmbracoContextFactory>(); | ||
using var context = contextFactory.EnsureUmbracoContext(); | ||
|
||
var contentService = _factory.Services.GetRequiredService<IContentService>(); | ||
var domainService = _factory.Services.GetRequiredService<IDomainService>(); | ||
var localizationService = _factory.Services.GetRequiredService<ILocalizationService>(); | ||
var urlProvider = _factory.Services.GetRequiredService<IPublishedUrlProvider>(); | ||
|
||
// Content | ||
var homeNode = contentService.Create("Home", Constants.System.Root, HomePage.ModelTypeAlias); | ||
var homePublishResult = contentService.SaveAndPublish(homeNode); | ||
|
||
homePublishResult.Success.Should().BeTrue(); | ||
|
||
var contentNode = contentService.Create("Content", homeNode, ContentPage.ModelTypeAlias); | ||
var contentPublishResult = contentService.SaveAndPublish(contentNode); | ||
|
||
contentPublishResult.Success.Should().BeTrue(); | ||
|
||
var nestedNode = contentService.Create("Nested", contentNode, ContentPage.ModelTypeAlias); | ||
var nestedPublishResult = contentService.SaveAndPublish(nestedNode); | ||
|
||
nestedPublishResult.Success.Should().BeTrue(); | ||
|
||
// Languages | ||
var englishLanguage = localizationService.GetLanguageByIsoCode("en-US")!; | ||
var danishLanguage = localizationService.GetLanguageByIsoCode("da-DK")!; | ||
|
||
// Domains | ||
var englishDomain = new UmbracoDomain("https://example.org/en") | ||
{ | ||
RootContentId = homeNode.Id, | ||
LanguageId = englishLanguage.Id, | ||
}; | ||
var englishDomainResult = domainService.Save(englishDomain); | ||
|
||
englishDomainResult.Success.Should().BeTrue(); | ||
|
||
var danishDomain = new UmbracoDomain("https://example.org/da") | ||
{ | ||
RootContentId = homeNode.Id, | ||
LanguageId = danishLanguage.Id, | ||
}; | ||
var danishDomainResult = domainService.Save(danishDomain); | ||
|
||
danishDomainResult.Success.Should().BeTrue(); | ||
|
||
var assigned = domainService.GetAssignedDomains(homeNode.Id, true); | ||
|
||
assigned.Should().HaveCount(2); | ||
|
||
var publishedAssigned = context.UmbracoContext.Domains!.GetAssigned(homeNode.Id, true); | ||
|
||
publishedAssigned.Should().HaveCount(2); | ||
|
||
// Check pages | ||
var currentUri = new Uri("https://example.org/"); | ||
|
||
var publishedNode = context.UmbracoContext.Content!.GetById(nestedNode.Id); | ||
publishedNode.Should().NotBeNull(); | ||
|
||
var url = urlProvider.GetUrl(publishedNode!, UrlMode.Absolute, "da-DK", currentUri); | ||
url.Should().Be("https://example.org/da/content/nested/"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Unique_HostNames() | ||
{ | ||
var contextFactory = _factory.Services.GetRequiredService<IUmbracoContextFactory>(); | ||
using var context = contextFactory.EnsureUmbracoContext(); | ||
|
||
var contentService = _factory.Services.GetRequiredService<IContentService>(); | ||
var domainService = _factory.Services.GetRequiredService<IDomainService>(); | ||
var localizationService = _factory.Services.GetRequiredService<ILocalizationService>(); | ||
var urlProvider = _factory.Services.GetRequiredService<IPublishedUrlProvider>(); | ||
|
||
// Content | ||
var homeNode = contentService.Create("Home", Constants.System.Root, HomePage.ModelTypeAlias); | ||
var homePublishResult = contentService.SaveAndPublish(homeNode); | ||
|
||
homePublishResult.Success.Should().BeTrue(); | ||
|
||
var contentNode = contentService.Create("Content", homeNode, ContentPage.ModelTypeAlias); | ||
var contentPublishResult = contentService.SaveAndPublish(contentNode); | ||
|
||
contentPublishResult.Success.Should().BeTrue(); | ||
|
||
var nestedNode = contentService.Create("Nested", contentNode, ContentPage.ModelTypeAlias); | ||
var nestedPublishResult = contentService.SaveAndPublish(nestedNode); | ||
|
||
nestedPublishResult.Success.Should().BeTrue(); | ||
|
||
// Languages | ||
var englishLanguage = localizationService.GetLanguageByIsoCode("en-US")!; | ||
var danishLanguage = localizationService.GetLanguageByIsoCode("da-DK")!; | ||
|
||
// Domains | ||
var englishDomain = new UmbracoDomain("https://en.example.org/") | ||
{ | ||
RootContentId = homeNode.Id, | ||
LanguageId = englishLanguage.Id, | ||
}; | ||
var englishDomainResult = domainService.Save(englishDomain); | ||
|
||
englishDomainResult.Success.Should().BeTrue(); | ||
|
||
var danishDomain = new UmbracoDomain("https://da.example.org/") | ||
{ | ||
RootContentId = homeNode.Id, | ||
LanguageId = danishLanguage.Id, | ||
}; | ||
var danishDomainResult = domainService.Save(danishDomain); | ||
|
||
danishDomainResult.Success.Should().BeTrue(); | ||
|
||
var assigned = domainService.GetAssignedDomains(homeNode.Id, true); | ||
|
||
assigned.Should().HaveCount(2); | ||
|
||
var publishedAssigned = context.UmbracoContext.Domains!.GetAssigned(homeNode.Id, true); | ||
|
||
publishedAssigned.Should().HaveCount(2); | ||
|
||
// Check pages | ||
var currentUri = new Uri("https://en.example.org/"); | ||
|
||
var publishedNode = context.UmbracoContext.Content!.GetById(nestedNode.Id); | ||
publishedNode.Should().NotBeNull(); | ||
|
||
var url = urlProvider.GetUrl(publishedNode!, UrlMode.Absolute, "da-DK", currentUri); | ||
url.Should().Be("https://da.example.org/content/nested/"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// Delete all content | ||
var contentService = _factory.Services.GetRequiredService<IContentService>(); | ||
|
||
foreach (var content in contentService.GetRootContent()) | ||
contentService.Delete(content); | ||
|
||
// Delete all domains | ||
var domainService = _factory.Services.GetRequiredService<IDomainService>(); | ||
|
||
foreach (var domain in domainService.GetAll(true)) | ||
domainService.Delete(domain); | ||
} | ||
} |
Oops, something went wrong.