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-795: Upgrade to latest OC preview to test System.Text.Json #117

Merged
merged 17 commits into from
May 15, 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 @@ -34,10 +34,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Tenants" Version="1.8.2" />
<PackageReference Include="OrchardCore.Users" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Tenants" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Users" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Tests.UI.Extensions;
Expand All @@ -23,18 +24,19 @@ public static async Task TestEmailQuotaManagementBehaviorAsync(
bool moduleShouldInterfere = true)
{
await context.SignInDirectlyAndGoToDashboardAsync();

context.Missing(By.XPath(DashboardExceededMessage));

await context.GoToAdminRelativeUrlAsync("/Settings/email");

await context.ConfigureSmtpPortAsync(publish: false);
CheckEmailsSentWarningMessage(context, exists: moduleShouldInterfere, maximumEmailQuota, 0);
await context.ClickReliablyOnAsync(By.ClassName("save"));

var warningEmails = new List<int>();
for (int i = 0; i < maximumEmailQuota; i++)
{
await SendTestEmailAsync(context, SuccessfulSubject);
await context.GoToEmailTestAsync();
await context.FillEmailTestFormAsync(SuccessfulSubject);
context.SuccessMessageExists();

CheckEmailsSentWarningMessage(context, exists: moduleShouldInterfere, maximumEmailQuota, i + 1);
var warningLevel = Convert.ToInt32(Math.Round((double)(i + 1) / maximumEmailQuota * 100, 0));

Expand Down Expand Up @@ -63,7 +65,8 @@ public static async Task TestEmailQuotaManagementBehaviorAsync(
}
}

await SendTestEmailAsync(context, UnSuccessfulSubject);
await context.GoToEmailTestAsync();
await context.FillEmailTestFormAsync(UnSuccessfulSubject);
await context.GoToSmtpWebUIAsync();
context.CheckExistence(ByHelper.SmtpInboxRow(SuccessfulSubject), exists: true);
context.CheckExistence(
Expand All @@ -88,31 +91,21 @@ private static void CheckMessageExistence(UITestContext context, string warningL
$"[contains(.,'It seems that your site sent out {warningLevel}% of e-mail')]"),
exists: true);

private static void CheckEmailsSentWarningMessage(UITestContext context, bool exists, int maximumEmailQuota, int currentEmailCount) =>
context.CheckExistence(
By.XPath($"//p[contains(@class,'alert-warning')][contains(.,'{currentEmailCount.ToTechnicalString()} emails" +
$" from the total of {maximumEmailQuota.ToTechnicalString()} this month.')]"),
exists);

private static async Task SendTestEmailAsync(UITestContext context, string subject)
private static void CheckEmailsSentWarningMessage(UITestContext context, bool exists, int maximumEmailQuota, int currentEmailCount)
{
await context.GoToAdminRelativeUrlAsync("/Email/Index");
await context.FillInWithRetriesAsync(By.Id("To"), "recipient@example.com");
await context.FillInWithRetriesAsync(By.Id("Subject"), subject);
await context.FillInWithRetriesAsync(By.Id("Body"), "Hi, this is a test.");
var by = By.CssSelector(".alert-warning[data-smtp-quota-max][data-smtp-quota-used]");

await ReliabilityHelper.DoWithRetriesOrFailAsync(
async () =>
{
try
{
await context.ClickReliablyOnAsync(By.Id("emailtestsend")); // #spell-check-ignore-line
return true;
}
catch (WebDriverException ex) when (ex.Message.Contains("move target out of bounds"))
{
return false;
}
});
if (!exists)
{
context.Missing(by);
return;
}

var element = context.Get(by);
var max = int.Parse(element.GetAttribute("data-smtp-quota-max"), CultureInfo.InvariantCulture);
var used = int.Parse(element.GetAttribute("data-smtp-quota-used"), CultureInfo.InvariantCulture);

max.ShouldBe(maximumEmailQuota);
used.ShouldBe(currentEmailCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Layout;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Queries.Controllers;
using System.Threading.Tasks;
using EmailAdminController = OrchardCore.Email.Controllers.AdminController;

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Filters;

Expand Down Expand Up @@ -33,17 +33,12 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE
return;
}

var actionRouteController = context.ActionDescriptor.RouteValues["Controller"];
var actionRouteArea = context.ActionDescriptor.RouteValues["Area"];
var actionRouteValue = context.ActionDescriptor.RouteValues["Action"];

if (actionRouteController == typeof(AdminController).ControllerName() &&
actionRouteArea == $"{nameof(OrchardCore)}.{nameof(OrchardCore.Settings)}" &&
actionRouteValue is nameof(AdminController.Index) &&
context.Result is ViewResult &&
context.RouteData.Values.TryGetValue("GroupId", out var groupId) &&
(string)groupId == "email" &&
_emailQuotaService.ShouldLimitEmails())
var isEmailTestPage = context.IsMvcRoute(
nameof(EmailAdminController.Test),
typeof(EmailAdminController).ControllerName(),
$"{nameof(OrchardCore)}.{nameof(OrchardCore.Email)}");

if ((isEmailTestPage || context.IsSiteSettingsPage("email")) && _emailQuotaService.ShouldLimitEmails())
{
var layout = await _layoutAccessor.GetLayoutAsync();
var contentZone = layout.Zones["Content"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Admin" Version="1.8.2" />
<PackageReference Include="OrchardCore.Email.Core" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.AdminDashboard" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Admin" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Email" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.AdminDashboard" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Email.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="Scrutor" Version="4.2.2" />
<PackageReference Include="YesSql.Abstractions" Version="4.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@

namespace Lombiq.Hosting.Tenants.EmailQuotaManagement.Services;

public class QuotaManagingSmtpServiceDecorator : ISmtpService
public class QuotaManagingSmtpServiceDecorator : IEmailService
{
private readonly IStringLocalizer<QuotaManagingSmtpServiceDecorator> T;
private readonly ISmtpService _smtpService;
private readonly IEmailService _emailService;
private readonly IEmailQuotaService _emailQuotaService;
private readonly ShellSettings _shellSettings;
private readonly IEmailTemplateService _emailTemplateService;
private readonly IEmailQuotaSubjectService _emailQuotaSubjectService;

public QuotaManagingSmtpServiceDecorator(
ISmtpService smtpService,
IEmailService emailService,
IStringLocalizer<QuotaManagingSmtpServiceDecorator> stringLocalizer,
IEmailQuotaService emailQuotaService,
ShellSettings shellSettings,
IEmailTemplateService emailTemplateService,
IEmailQuotaSubjectService emailQuotaSubjectService)
{
_smtpService = smtpService;
_emailService = emailService;
T = stringLocalizer;
_emailQuotaService = emailQuotaService;
_shellSettings = shellSettings;
_emailTemplateService = emailTemplateService;
_emailQuotaSubjectService = emailQuotaSubjectService;
}

public async Task<SmtpResult> SendAsync(MailMessage message)
public async Task<EmailResult> SendAsync(MailMessage message, string providerName = null)
{
if (!_emailQuotaService.ShouldLimitEmails())
{
return await _smtpService.SendAsync(message);
return await _emailService.SendAsync(message, providerName);
}

var isQuotaOverResult = await _emailQuotaService.IsQuotaOverTheLimitAsync();
Expand All @@ -48,14 +48,11 @@ public async Task<SmtpResult> SendAsync(MailMessage message)
// Should send the email if the quota is not over the limit.
if (isQuotaOverResult.IsOverQuota)
{
return SmtpResult.Failed(T["The email quota for the site has been exceeded."]);
return EmailResult.FailedResult(T["The email quota for the site has been exceeded."]);
}

var emailResult = await _smtpService.SendAsync(message);
if (emailResult == SmtpResult.Success)
{
await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota);
}
var emailResult = await _emailService.SendAsync(message, providerName);
if (emailResult.Succeeded) await _emailQuotaService.IncreaseEmailUsageAsync(isQuotaOverResult.EmailQuota);

return emailResult;
}
Expand Down Expand Up @@ -109,7 +106,7 @@ private Task SendQuotaEmailAsync(
});
// ISmtpService must be used within this class otherwise it won't call the original ISmtpService
// implementation, but loop back to here.
await _smtpService.SendAsync(emailMessage);
await _emailService.SendAsync(emailMessage);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Hosting.Tenants.EmailQuotaManagement/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IEmailQuotaService, EmailQuotaService>();
services.AddScoped<IEmailQuotaSubjectService, EmailQuotaSubjectService>();

services.Decorate<ISmtpService, QuotaManagingSmtpServiceDecorator>();
services.Decorate<IEmailService, QuotaManagingSmtpServiceDecorator>();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<p class="alert alert-warning">
@T["Unless you use your own SMTP server you have limited e-mails to send. " +
"You've sent {0} emails from the total of {1} this month.",
Model.CurrentEmailUsageCount,
Model.EmailQuotaPerMonth]
@{
int currentEmailUsageCount = Model.CurrentEmailUsageCount;
int emailQuotaPerMonth = Model.EmailQuotaPerMonth;
}

<p class="alert alert-warning"
data-smtp-quota-used="@currentEmailUsageCount.ToTechnicalString()"
data-smtp-quota-max=@emailQuotaPerMonth.ToTechnicalString()>
@T["Unless you use your own SMTP server you have limited e-mails to send."]
@T["You've sent {0} emails from the total of {1} this month.", currentEmailUsageCount, emailQuotaPerMonth]
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Infrastructure.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="OrchardCore.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Settings" Version="1.8.2" />
<PackageReference Include="OrchardCore.Users.Abstractions" Version="1.8.2" />
<PackageReference Include="OrchardCore.Users.Core" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ContentTypes.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Settings" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Users.Abstractions" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Users.Core" Version="2.0.0-preview-18200" />
<PackageReference Include="RandomNameGeneratorLibrary" Version="1.2.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium;
using Shouldly;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Lombiq.Hosting.Tenants.Management.Tests.UI.Extensions;
Expand Down Expand Up @@ -58,6 +58,6 @@ private static void CheckEditorValue(this UITestContext context, string keyToChe
var editorJson = string.IsNullOrEmpty(editorText) ? "{}" : editorText;

var editorValue = JObject.Parse(editorJson);
editorValue.SelectToken($"TestKey.TestSubKey.TestSubOptions.{keyToCheck}")?.ToString().ShouldBeAsString(expectedValue);
editorValue.SelectNode($"TestKey.TestSubKey.TestSubOptions.{keyToCheck}")?.ToString().ShouldBeAsString(expectedValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Tenants" Version="1.8.2" />
<PackageReference Include="OrchardCore" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Tenants" Version="2.0.0-preview-18200" />
<PackageReference Include="Scrutor" Version="4.2.2" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using Lombiq.Hosting.Tenants.Management.Controllers
@using Newtonsoft.Json
@using OrchardCore
@using OrchardCore.Mvc.Core.Utilities
@using static Lombiq.Hosting.Tenants.Management.Constants.FeatureNames
Expand Down Expand Up @@ -31,11 +30,11 @@
<script at="Foot" depends-on="monaco">
$(() => {
require(['vs/editor/editor.main'], () => {
const settings = @Html.Raw(JsonConvert.SerializeObject(
const settings = @Json.Serialize(
new {
automaticLayout = true,
language = "json",
}));
AutomaticLayout = true,
Language = "json",
});

const html = document.getElementsByTagName('html')[0];
const mutationObserver = new MutationObserver(setTheme);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.8.2" />
<PackageReference Include="OrchardCore.Media" Version="1.8.2" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.8.2" />
<PackageReference Include="OrchardCore.Module.Targets" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.Media" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.ResourceManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="2.0.0-preview-18200" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

Expand Down