Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<ItemGroup>
<!-- Third-party packages -->
<PackageVersion Include="AutoFixture.AutoMoq" Version="4.18.1" />
<PackageVersion Include="AutoFixture.NUnit4" Version="4.19.0" />
<PackageVersion Include="AutoFixture.NUnit3" Version="4.18.1" />
<PackageVersion Include="Bogus" Version="35.6.5" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NUnit" Version="4.5.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.1.0" PrivateAssets="all" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" PrivateAssets="all" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion tests/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="AutoFixture.AutoMoq" />
<PackageReference Include="AutoFixture.NUnit4" />
<PackageReference Include="AutoFixture.NUnit3" />
<PackageReference Include="Moq" />
<PackageReference Include="NUnit" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand All @@ -16,7 +17,6 @@
using Umbraco.Cms.Persistence.Sqlite;
using Umbraco.Cms.Persistence.SqlServer;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.DependencyInjection;
using Umbraco.Cms.Tests.Integration.Testing;

namespace Umbraco.Cms.Tests.Integration.TestServerTest;
Expand Down Expand Up @@ -54,14 +54,14 @@ private static string GetTestContentRoot()
var directory = new DirectoryInfo(Path.GetDirectoryName(assemblyLocation)
?? throw new InvalidOperationException("Could not determine assembly directory."));

// Walk up parent directories until we're no longer in a bin or obj folder.
// Walk up parent directories until we're no longer in a bin or obj folder
while (directory.Parent is not null)
{
var name = directory.Name;
if (name.Equals("bin", StringComparison.OrdinalIgnoreCase) ||
name.Equals("obj", StringComparison.OrdinalIgnoreCase))
{
// Found bin/obj folder, return its parent (the project directory).
// Found bin/obj folder, return its parent (the project directory)
return directory.Parent.FullName;
}

Expand All @@ -73,19 +73,21 @@ private static string GetTestContentRoot()
?? throw new InvalidOperationException("Could not determine content root directory.");
}

private UmbracoWebApplicationFactory<CoreConfigurationHttpTests> CreateFactory(
private WebApplicationFactory<CoreConfigurationHttpTests> CreateFactory(
Action<IUmbracoBuilder> configureUmbraco,
Action<IApplicationBuilder> configureApp)
{
// Disable ModelsBuilder to avoid BootFailedException requiring Umbraco.Cms.DevelopmentMode.Backoffice package.
InMemoryConfiguration["Umbraco:CMS:ModelsBuilder:ModelsMode"] = "Nothing";
var contentRoot = GetTestContentRoot();

return new UmbracoWebApplicationFactory<CoreConfigurationHttpTests>(
() => CreateHostBuilder(configureUmbraco, configureApp))

{
ContentRoot = GetTestContentRoot(),
};
return new UmbracoWebApplicationFactory<CoreConfigurationHttpTests>(() => CreateHostBuilder(configureUmbraco, configureApp))
.WithWebHostBuilder(builder =>
{
builder.UseContentRoot(contentRoot);
Comment thread
andr317c marked this conversation as resolved.
builder.ConfigureTestServices(services =>
{
services.AddSingleton<IWebProfilerRepository, TestWebProfilerRepository>();
});
});
}

private IHostBuilder CreateHostBuilder(
Expand All @@ -110,7 +112,6 @@ private IHostBuilder CreateHostBuilder(
context.HostingEnvironment = TestHelper.GetWebHostEnvironment();
ConfigureServices(services, configureUmbraco);
services.AddUnique(CreateLoggerFactory());
services.AddSingleton<IWebProfilerRepository, TestWebProfilerRepository>();
});

builder.Configure(app => configureApp(app));
Expand Down Expand Up @@ -149,11 +150,6 @@ private void ConfigureServices(IServiceCollection services, Action<IUmbracoBuild
// Let the test configure Umbraco
configureUmbraco(builder);

// Provide test doubles for infrastructure services (MainDom, ServerMessenger, etc.)
// that would otherwise hang or fail in test contexts. This matches what
// UmbracoTestServerTestBase does via AddTestServices.
builder.AddTestServices(TestHelper);

builder.Build();
}

Expand All @@ -164,7 +160,7 @@ private void ConfigureServices(IServiceCollection services, Action<IUmbracoBuild
public async Task FullConfiguration_BootsSuccessfully()
{
// Arrange
await using var factory = CreateFactory(
using var factory = CreateFactory(
configureUmbraco: builder =>
{
builder
Expand Down Expand Up @@ -212,7 +208,7 @@ public async Task FullConfiguration_BootsSuccessfully()
public async Task CoreWithWebsite_BootsSuccessfully()
{
// Arrange
await using var factory = CreateFactory(
using var factory = CreateFactory(
configureUmbraco: builder =>
{
builder
Expand Down Expand Up @@ -260,7 +256,7 @@ public async Task CoreWithWebsite_BootsSuccessfully()
public async Task CoreWithDeliveryApi_BootsSuccessfully()
{
// Arrange
await using var factory = CreateFactory(
using var factory = CreateFactory(
configureUmbraco: builder =>
{
builder
Expand Down Expand Up @@ -362,7 +358,7 @@ public async Task CoreWithDeliveryApi_UserServiceReadMethodsDoNotThrow()
public async Task DeliveryOnlyScenario_BootsSuccessfully()
{
// Arrange
await using var factory = CreateFactory(
using var factory = CreateFactory(
configureUmbraco: builder =>
{
builder
Expand Down Expand Up @@ -412,7 +408,7 @@ public async Task DeliveryOnlyScenario_BootsSuccessfully()
public async Task BackOfficeWithWebsite_BootsSuccessfully()
{
// Arrange
await using var factory = CreateFactory(
using var factory = CreateFactory(
configureUmbraco: builder =>
{
builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Hosting;

Expand All @@ -14,40 +13,23 @@ public class UmbracoWebApplicationFactory<TStartup> : WebApplicationFactory<TSta
private IHost _host;

/// <summary>
/// Gets or sets the content root path. When set, overrides the default content root
/// that WebApplicationFactory resolves from the TStartup assembly.
/// </summary>
/// <remarks>
/// This is applied in <see cref="ConfigureWebHost"/> which runs after the factory's
/// own SetContentRoot, ensuring our value takes precedence.
/// </remarks>
public string? ContentRoot { get; set; }

/// <summary>
/// Constructor to create a new WebApplicationFactory.
/// Constructor to create a new WebApplicationFactory
/// </summary>
/// <param name="createHostBuilder">Method to create the IHostBuilder</param>
public UmbracoWebApplicationFactory(Func<IHostBuilder> createHostBuilder) => _createHostBuilder = createHostBuilder;

protected override IHostBuilder CreateHostBuilder() => _createHostBuilder();

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
if (ContentRoot is not null)
{
builder.UseContentRoot(ContentRoot);
}
}

protected override IHost CreateHost(IHostBuilder builder)
{
_host = builder.Build();

// Use Task.Run to avoid deadlocking with NUnit 4's SynchronizationContext.
Task.Run(() => _host.StartAsync()).GetAwaiter().GetResult();
_host.Start();

return _host;
}

public void ClearHost() => Task.Run(() => _host.StopAsync()).GetAwaiter().GetResult();
public void ClearHost()
{
_host.StopAsync().GetAwaiter().GetResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public async Task Structure_Can_Rebuild(int numberOfRebuilds)

// Verify that we have the same items as in the original built state of DocumentNavigationService
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
Assert.That( childrenKeysFromRebuild, Is.EquivalentTo(originalChildrenKeys));
Assert.That(descendantsKeysFromRebuild, Is.EquivalentTo(originalDescendantsKeys));
Assert.That(ancestorsKeysFromRebuild, Is.EquivalentTo(originalAncestorsKeys));
Assert.That(siblingsKeysFromRebuild, Is.EquivalentTo(originalSiblingsKeys));
Assert.That(routeKeysFromRebuild, Is.EquivalentTo(originalRouteKeys));
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalRouteKeys, routeKeysFromRebuild);
});
}

Expand Down Expand Up @@ -110,11 +110,11 @@ public async Task Bin_Structure_Can_Rebuild(int numberOfRebuilds)

// Verify that we have the same items as in the original built state of DocumentNavigationService
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
Assert.That(childrenKeysFromRebuild, Is.EquivalentTo(originalChildrenKeys));
Assert.That(descendantsKeysFromRebuild, Is.EquivalentTo(originalDescendantsKeys));
Assert.That(ancestorsKeysFromRebuild, Is.EquivalentTo(originalAncestorsKeys));
Assert.That(siblingsKeysFromRebuild, Is.EquivalentTo(originalSiblingsKeys));
Assert.That(routeKeysFromRebuild, Is.EquivalentTo(originalRouteKeys));
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalRouteKeys, routeKeysFromRebuild);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public async Task Structure_Does_Not_Update_When_Updating_Content()

// Verify that nothing's changed
Assert.AreEqual(initialParentKey, updatedParentKey);
Assert.That(childrenKeysAfterUpdate, Is.EquivalentTo(initialChildrenKeys));
Assert.That(descendantsKeysAfterUpdate, Is.EquivalentTo(initialDescendantsKeys));
Assert.That(ancestorsKeysAfterUpdate, Is.EquivalentTo(initialAncestorsKeys));
Assert.That(siblingsKeysAfterUpdate, Is.EquivalentTo(initialSiblingsKeys));
CollectionAssert.AreEquivalent(initialChildrenKeys, childrenKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialDescendantsKeys, descendantsKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialAncestorsKeys, ancestorsKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialSiblingsKeys, siblingsKeysAfterUpdate);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public async Task GetDynamicRootsAsync_NearestAncestorOrSelfFilterOfOwnDocType_R
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(startNodeSelector.Context.CurrentKey.Value));
CollectionAssert.Contains(result, startNodeSelector.Context.CurrentKey.Value);
});
}

Expand Down Expand Up @@ -328,7 +328,7 @@ public async Task GetDynamicRootsAsync_NearestDescendantOrSelf_FindsOnlyNearest(
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(ContentActs2022.Key));
CollectionAssert.Contains(result, ContentActs2022.Key);
});
}

Expand Down Expand Up @@ -377,7 +377,7 @@ public async Task GetDynamicRootsAsync_FurthestDescendantOrSelf_FindsOnlyFurthes
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(contentNewActs.Key));
CollectionAssert.Contains(result, contentNewActs.Key);
});
}

Expand Down Expand Up @@ -416,7 +416,7 @@ public async Task GetDynamicRootsAsync_MultipleQuerySteps_ReturnsExpectedNodes()
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(ContentStages2022.Key));
CollectionAssert.Contains(result, ContentStages2022.Key);
});
}

Expand Down Expand Up @@ -449,7 +449,7 @@ public async Task GetDynamicRootsAsync_NearestDescendantOrSelfFilterOfOwnDocType
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(startNodeSelector.Context.CurrentKey.Value));
CollectionAssert.Contains(result, startNodeSelector.Context.CurrentKey.Value);
});
}

Expand All @@ -475,7 +475,7 @@ public async Task GetDynamicRootsAsync_NoQuerySteps_ReturnsOrigin()
Assert.Multiple(() =>
{
Assert.AreEqual(1, result.Count());
Assert.That(result, Has.Member(startNodeSelector.Context.ParentKey));
CollectionAssert.Contains(result, startNodeSelector.Context.ParentKey);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public async Task Structure_Can_Rebuild()

// Verify that we have the same items as in the original built state of MediaNavigationService
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
Assert.That(childrenKeysFromRebuild, Is.EquivalentTo(originalChildrenKeys));
Assert.That(descendantsKeysFromRebuild, Is.EquivalentTo(originalDescendantsKeys));
Assert.That(ancestorsKeysFromRebuild, Is.EquivalentTo(originalAncestorsKeys));
Assert.That(siblingsKeysFromRebuild, Is.EquivalentTo(originalSiblingsKeys));
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
});
}

Expand Down Expand Up @@ -97,10 +97,10 @@ public async Task Bin_Structure_Can_Rebuild()

// Verify that we have the same items as in the original built state of MediaNavigationService
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
Assert.That(childrenKeysFromRebuild, Is.EquivalentTo(originalChildrenKeys));
Assert.That(descendantsKeysFromRebuild, Is.EquivalentTo(originalDescendantsKeys));
Assert.That(ancestorsKeysFromRebuild, Is.EquivalentTo(originalAncestorsKeys));
Assert.That(siblingsKeysFromRebuild, Is.EquivalentTo(originalSiblingsKeys));
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public async Task Structure_Does_Not_Update_When_Updating_Media()

// Verify that nothing's changed
Assert.AreEqual(initialParentKey, updatedParentKey);
Assert.That(childrenKeysAfterUpdate, Is.EquivalentTo(initialChildrenKeys));
Assert.That(descendantsKeysAfterUpdate, Is.EquivalentTo(initialDescendantsKeys));
Assert.That(ancestorsKeysAfterUpdate, Is.EquivalentTo(initialAncestorsKeys));
Assert.That(siblingsKeysAfterUpdate, Is.EquivalentTo(initialSiblingsKeys));
CollectionAssert.AreEquivalent(initialChildrenKeys, childrenKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialDescendantsKeys, descendantsKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialAncestorsKeys, ancestorsKeysAfterUpdate);
CollectionAssert.AreEquivalent(initialSiblingsKeys, siblingsKeysAfterUpdate);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;

Expand All @@ -14,6 +15,8 @@ internal sealed class UserGroupServiceTests : UmbracoIntegrationTest
{
private IUserGroupService UserGroupService => GetRequiredService<IUserGroupService>();

private IShortStringHelper ShortStringHelper => GetRequiredService<IShortStringHelper>();

[Test]
public async Task Can_Create_User_Group()
{
Expand Down Expand Up @@ -43,8 +46,8 @@ public async Task Can_Create_User_Group()
Assert.AreEqual(userGroup.Description, createdUserGroup.Description);
Assert.AreEqual(userGroup.Icon, createdUserGroup.Icon);
Assert.AreEqual(userGroup.HasAccessToAllLanguages, createdUserGroup.HasAccessToAllLanguages);
Assert.That(createdUserGroup.Permissions, Is.EquivalentTo(userGroup.Permissions));
Assert.That(createdUserGroup.AllowedSections, Is.EquivalentTo(userGroup.AllowedSections));
CollectionAssert.AreEquivalent(userGroup.Permissions, createdUserGroup.Permissions);
CollectionAssert.AreEquivalent(userGroup.AllowedSections, createdUserGroup.AllowedSections);
}

[Test]
Expand Down Expand Up @@ -89,8 +92,8 @@ public async Task Can_Update_User_Group()
Assert.AreEqual(createdUserGroup.Description, updatedUserGroup.Description);
Assert.AreEqual(createdUserGroup.Icon, updatedUserGroup.Icon);
Assert.AreEqual(createdUserGroup.HasAccessToAllLanguages, updatedUserGroup.HasAccessToAllLanguages);
Assert.That(updatedUserGroup.Permissions, Is.EquivalentTo(createdUserGroup.Permissions));
Assert.That(updatedUserGroup.AllowedSections, Is.EquivalentTo(createdUserGroup.AllowedSections));
CollectionAssert.AreEquivalent(createdUserGroup.Permissions, updatedUserGroup.Permissions);
CollectionAssert.AreEquivalent(createdUserGroup.AllowedSections, updatedUserGroup.AllowedSections);
}

[Test]
Expand Down
Loading
Loading