Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-903: Update to Orchard Core 2.1.0 #429

Merged
merged 8 commits into from
Dec 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore" Version="2.0.0" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore" Version="2.1.0" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="2.1.0" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions Lombiq.Tests.UI.Shortcuts/Lombiq.Tests.UI.Shortcuts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0" />
<PackageReference Include="OrchardCore.Tenants" Version="2.0.0" />
<PackageReference Include="OrchardCore.Themes" Version="2.0.0" />
<PackageReference Include="OrchardCore.Users" Version="2.0.0" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.Recipes.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.ResourceManagement.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.Workflows" Version="2.0.0" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.1.0" />
<PackageReference Include="OrchardCore.Tenants" Version="2.1.0" />
<PackageReference Include="OrchardCore.Themes" Version="2.1.0" />
<PackageReference Include="OrchardCore.Users" Version="2.1.0" />
<PackageReference Include="OrchardCore.Media.Abstractions" Version="2.1.0" />
<PackageReference Include="OrchardCore.Recipes.Abstractions" Version="2.1.0" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.1.0" />
<PackageReference Include="OrchardCore.ResourceManagement.Abstractions" Version="2.1.0" />
<PackageReference Include="OrchardCore.Workflows" Version="2.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static Task TestLogoutAsync(this UITestContext context) =>
/// <returns>The same <see cref="UITestContext"/> instance.</returns>
public static Task TestRegistrationAsync(this UITestContext context, UserRegistrationParameters parameters = null)
{
parameters ??= UserRegistrationParameters.CreateDefault();
parameters ??= UserRegistrationParameters.CreateTest();

return context.ExecuteTestAsync(
"Test registration",
Expand Down Expand Up @@ -440,7 +440,7 @@ public static Task TestRegistrationWithAlreadyRegisteredEmailAsync(
this UITestContext context,
UserRegistrationParameters parameters = null)
{
parameters ??= UserRegistrationParameters.CreateDefault();
parameters ??= UserRegistrationParameters.CreateTest();

return context.ExecuteTestAsync(
"Test registration with already registered email",
Expand Down
23 changes: 22 additions & 1 deletion Lombiq.Tests.UI/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Lombiq.Tests.UI.Extensions.IWebApplicationInstanceExtensions</Target>
<Left>lib/net8.0/Lombiq.Tests.UI.dll</Left>
<Right>lib/net8.0/Lombiq.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Lombiq.Tests.UI.Services.OrchardCoreUITestExecutorConfiguration.AssertAppLogsCanContainWarningsAndCacheFolderErrorsAsync</Target>
Expand All @@ -15,6 +22,20 @@
<Right>lib/net8.0/Lombiq.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Lombiq.Tests.UI.Extensions.ShortcutsUITestContextExtensions.CreateUserAsync(Lombiq.Tests.UI.Services.UITestContext,System.String,System.String,System.String,System.String,System.Boolean)</Target>
<Left>lib/net8.0/Lombiq.Tests.UI.dll</Left>
<Right>lib/net8.0/Lombiq.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Lombiq.Tests.UI.Extensions.ShortcutsUITestContextExtensions.SetUserRegistrationTypeAsync(Lombiq.Tests.UI.Services.UITestContext,OrchardCore.Users.Models.UserRegistrationType,System.String,System.Boolean)</Target>
<Left>lib/net8.0/Lombiq.Tests.UI.dll</Left>
<Right>lib/net8.0/Lombiq.Tests.UI.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Lombiq.Tests.UI.Extensions.WebApplicationInstanceExtensions.GetLogOutputAsync(Lombiq.Tests.UI.Services.IWebApplicationInstance,System.Threading.CancellationToken)</Target>
Expand Down
11 changes: 11 additions & 0 deletions Lombiq.Tests.UI/Constants/TestUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Lombiq.Tests.UI.Constants;

/// <summary>
/// Details of a user account that can be created during tests.
/// </summary>
public static class TestUser
{
public const string UserName = "TestUser"; // #spell-check-ignore-line
public const string Email = "[email protected]"; // #spell-check-ignore-line
public const string Password = DefaultUser.Password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void SwitchToBackend(this UITestContext context) =>
/// cref="FrontendOrchardCoreUITestExecutorConfigurationExtensions.GetFrontendAndBackendUris"/> and presents it as
/// switching to a tenant named <see cref="FrontendPseudoTenantName"/>. This is not a real Orchard Core tenant, so
/// this name can only be used for information (for example can't be used with <see
/// cref="IWebApplicationInstanceExtensions.UsingScopeAsync(IWebApplicationInstance,Func{ShellScope,Task},string,bool)"/>).
/// cref="UsingScopeWebApplicationInstanceExtensions.UsingScopeAsync(IWebApplicationInstance,Func{ShellScope,Task},string,bool)"/>).
/// </summary>
public static void SwitchToFrontend(this UITestContext context) =>
context.SwitchCurrentTenant(
Expand Down
47 changes: 14 additions & 33 deletions Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using OrchardCore.Admin;
using OrchardCore.Data;
using OrchardCore.DisplayManagement.Extensions;
using OrchardCore.Entities;
using OrchardCore.Environment.Extensions;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Models;
Expand All @@ -24,7 +23,6 @@
using OrchardCore.Recipes.Services;
using OrchardCore.Security;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using OrchardCore.Setup.Services;
using OrchardCore.Themes.Services;
using OrchardCore.Users;
Expand Down Expand Up @@ -123,50 +121,30 @@ public static async Task<string> GetCurrentUserNameAsync(this UITestContext cont
return userNameContainer["UserName: ".Length..];
}

/// <summary>
/// Sets the registration type in site settings.
/// </summary>
public static Task SetUserRegistrationTypeAsync(
this UITestContext context,
UserRegistrationType type,
string tenant = null,
bool activateShell = true) =>
UsingScopeAsync(
context,
async serviceProvider =>
{
var siteService = serviceProvider.GetRequiredService<ISiteService>();
var settings = await siteService.LoadSiteSettingsAsync();

settings.Alter<RegistrationSettings>(
nameof(RegistrationSettings),
registrationSettings => registrationSettings.UsersCanRegister = type);

await siteService.UpdateSiteSettingsAsync(settings);
},
tenant,
activateShell);

/// <summary>
/// Creates a user with the given parameters.
/// </summary>
/// <exception cref="CreateUserFailedException">
/// If creating the user with the given parameters was not successful.
/// </exception>
public static Task CreateUserAsync(
/// <returns>The <see cref="IUser"/> instance of the user just created.</returns>
public static async Task<IUser> CreateUserAsync(
this UITestContext context,
string userName,
string password,
string email,
string userName = TestUser.UserName,
string password = TestUser.Password,
string email = TestUser.Email,
string tenant = null,
bool activateShell = true) =>
UsingScopeAsync(
bool activateShell = true)
{
IUser user = null;

await UsingScopeAsync(
context,
async serviceProvider =>
{
var userService = serviceProvider.GetRequiredService<IUserService>();
var errors = new Dictionary<string, string>();
var user = await userService.CreateUserAsync(
user = await userService.CreateUserAsync(
new User
{
UserName = userName,
Expand All @@ -189,6 +167,9 @@ public static Task CreateUserAsync(
tenant,
activateShell);

return user;
}

/// <summary>
/// Adds a user to a role.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Lombiq.Tests.UI.Extensions;

public static class IWebApplicationInstanceExtensions
public static class UsingScopeWebApplicationInstanceExtensions
{
/// <summary>
/// Executes a delegate using the shell scope given by <paramref name="tenant"/> in an isolated async flow, while
Expand Down
56 changes: 43 additions & 13 deletions Lombiq.Tests.UI/Extensions/WebApplicationInstanceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public static class WebApplicationInstanceExtensions
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> or <see
/// cref="GetLogEntriesFromAllLogsAsync(IWebApplicationInstance, CancellationToken)"/> instead. Alternatively, set
/// log filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
Expand All @@ -40,8 +41,9 @@ public static async Task LogsShouldBeEmptyAsync(
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> or <see
/// cref="GetLogEntriesFromAllLogsAsync(IWebApplicationInstance, CancellationToken)"/> instead. Alternatively, set
/// log filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
Expand All @@ -62,8 +64,9 @@ public static Task LogsShouldContainAsync(
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> or <see
/// cref="GetLogEntriesFromAllLogsAsync(IWebApplicationInstance, CancellationToken)"/> instead. Alternatively, set
/// log filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
Expand All @@ -84,8 +87,9 @@ public static Task LogsShouldNotContainErrorsAsync(
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> or <see
/// cref="GetLogEntriesFromAllLogsAsync(IWebApplicationInstance, CancellationToken)"/> instead. Alternatively, set
/// log filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
Expand All @@ -105,19 +109,35 @@ public static Task LogsShouldNotContainAsync(
/// <remarks>
/// <para>
/// If you want to inspect the logs in a more structured way, message by message, consider using <see
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> directly instead. Alternatively, set log
/// filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// cref="IWebApplicationInstance.GetLogsAsync(CancellationToken)"/> or <see
/// cref="GetLogEntriesFromAllLogsAsync(IWebApplicationInstance, CancellationToken)"/> instead. Alternatively, set
/// log filtering options to not log unwanted messages in first place with the standard Logging:LogLevel app
/// configuration (see the samples).
/// </para>
/// </remarks>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can cancel the log retrieval.</param>
public static async Task<string> GetLogContentsAsync(
this IWebApplicationInstance webApplicationInstance,
CancellationToken cancellationToken = default) =>
await (await webApplicationInstance.GetLogsAsync(cancellationToken)).ToFormattedStringAsync();

/// <summary>
/// Retrieves the log entries from all application logs.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can cancel the log retrieval.</param>
public static async Task<IEnumerable<IApplicationLogEntry>> GetLogEntriesFromAllLogsAsync(
this IWebApplicationInstance webApplicationInstance,
CancellationToken cancellationToken = default)
{
if (cancellationToken == default) cancellationToken = CancellationToken.None;
var logs = await webApplicationInstance.GetLogsAsync(cancellationToken);
var logEntries = new List<IApplicationLogEntry>();

foreach (var log in logs)
{
logEntries.AddRange(await log.GetEntriesAsync());
}

return await (await webApplicationInstance.GetLogsAsync(cancellationToken)).ToFormattedStringAsync();
return logEntries;
}

/// <summary>
Expand All @@ -131,17 +151,27 @@ public static async Task<string> GetLogContentsAsync(
public static TService GetRequiredService<TService>(this IWebApplicationInstance webApplicationInstance) =>
webApplicationInstance.Services.GetRequiredService<TService>();

/// <summary>
/// Restarts, i.e. pauses and resumes, the web application instance.
/// </summary>
public static async Task RestartAsync(this IWebApplicationInstance webApplicationInstance)
{
await webApplicationInstance.PauseAsync();
await webApplicationInstance.ResumeAsync();
}

private static async Task AssertLogsAsync(
IWebApplicationInstance webApplicationInstance,
Expression<Func<IApplicationLogEntry, bool>> logEntryPredicate,
Action<IEnumerable<IApplicationLogEntry>, Expression<Func<IApplicationLogEntry, bool>>, string> shouldlyMethod, // #spell-check-ignore-line
CancellationToken cancellationToken = default)
{
var logs = await webApplicationInstance.GetLogsAsync(cancellationToken);
var logContents = await logs.ToFormattedStringAsync();

foreach (var log in logs)
{
shouldlyMethod(await log.GetEntriesAsync(), logEntryPredicate, await logs.ToFormattedStringAsync()); // #spell-check-ignore-line
shouldlyMethod(await log.GetEntriesAsync(), logEntryPredicate, logContents); // #spell-check-ignore-line
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Lombiq.Tests.UI.Services;
using System.Threading.Tasks;

namespace Lombiq.Tests.UI.Extensions;

public static class WebApplicationInstanceUITestContextExtensions
{
/// <summary>
/// Restarts the application and refreshes the current page to warm it up.
/// </summary>
public static async Task RestartAndWarmUpApplicationAsync(this UITestContext context)
{
await context.Application.RestartAsync();
context.Refresh();
}
}
8 changes: 4 additions & 4 deletions Lombiq.Tests.UI/Lombiq.Tests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
<PackageReference Include="Microsoft.SqlServer.DACFx" Version="162.2.111" />
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="171.30.0" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.0.0" />
<PackageReference Include="OrchardCore.Logging.NLog" Version="2.0.0" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.0.0" />
<PackageReference Include="OrchardCore.Recipes.Core" Version="2.0.0" />
<PackageReference Include="OrchardCore.ContentFields" Version="2.1.0" />
<PackageReference Include="OrchardCore.Logging.NLog" Version="2.1.0" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.1.0" />
<PackageReference Include="OrchardCore.Recipes.Core" Version="2.1.0" />
<PackageReference Include="Sarif.Sdk" Version="4.5.4" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<!-- Needed only because Microsoft.SqlServer.DACFx depends on a vulnerable older version of it. -->
Expand Down
11 changes: 11 additions & 0 deletions Lombiq.Tests.UI/Models/UserRegistrationParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Lombiq.Tests.UI.Constants;
using System;

namespace Lombiq.Tests.UI.Models;

Expand All @@ -9,6 +10,7 @@ public class UserRegistrationParameters
public string Password { get; set; }
public string ConfirmPassword { get; set; }

[Obsolete("Use CreateTest() instead.")]
public static UserRegistrationParameters CreateDefault() =>
new()
{
Expand All @@ -17,4 +19,13 @@ public static UserRegistrationParameters CreateDefault() =>
Password = DefaultUser.Password,
ConfirmPassword = DefaultUser.Password,
};

public static UserRegistrationParameters CreateTest() =>
new()
{
UserName = TestUser.UserName,
Email = TestUser.Email,
Password = TestUser.Password,
ConfirmPassword = TestUser.Password,
};
}
Loading