diff --git a/Lombiq.Tests.UI.Samples/Tests/EmailTests.cs b/Lombiq.Tests.UI.Samples/Tests/EmailTests.cs index 928170eb6..33afd9c14 100644 --- a/Lombiq.Tests.UI.Samples/Tests/EmailTests.cs +++ b/Lombiq.Tests.UI.Samples/Tests/EmailTests.cs @@ -23,9 +23,6 @@ public Task SendingTestEmailShouldWork() => // A shortcut to sign in without going through (and thus testing) the login screen. await context.SignInDirectlyAsync(); - // Set up the SMTP port. This is a dynamic value unique to each UI test so it can't come from a recipe. - await context.ConfigureSmtpPortAsync(); - // Let's go to the "Test settings" option of the e-mail admin page and send a basic e-mail. The default // sender is configured in the test recipe so we can use the test feature. await context.GoToEmailTestAsync(); @@ -39,8 +36,8 @@ public Task SendingTestEmailShouldWork() => // If the e-mail we've sent exists then it's all good. context.Exists(ByHelper.SmtpInboxRow("Test message")); }, - // UseSmtpService = true automatically enables the Email module too so you don't have to enable it in a - // recipe. + // UseSmtpService = true automatically enables the Email module so you don't have to enable it in a recipe, + // and it configures the module too. configuration => configuration.UseSmtpService = true); } diff --git a/Lombiq.Tests.UI/Extensions/EmailUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/EmailUITestContextExtensions.cs index a937b81b3..a900e3f4a 100644 --- a/Lombiq.Tests.UI/Extensions/EmailUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/EmailUITestContextExtensions.cs @@ -92,14 +92,25 @@ public static async Task FillEmailTestFormAsync( public static Task FillEmailTestFormAsync(this UITestContext context, string subject) => context.FillEmailTestFormAsync("recipient@example.com", subject, "Hi, this is a test."); + [Obsolete("Use ConfigureSmtpSettingsAsync() instead.")] + public static Task ConfigureSmtpPortAsync(this UITestContext context, int? port = null, bool publish = true) => + throw new NotSupportedException("Use ConfigureSmtpSettingsAsync() instead."); + /// - /// Goes to the Email settings and sets the SMTP port to the value of . If it's then the value in the current configuration (in ) is used instead. - /// The OrchardCore.Email.Smtp feature must be enabled, but if the SMTP provider is not turned on, this will - /// automatically do it as well. + /// Goes to the SMTP settings page and configures the provided settings. The OrchardCore.Email.Smtp feature + /// must be enabled, but if the SMTP provider is not turned on, this will automatically do it as well. /// - public static async Task ConfigureSmtpPortAsync(this UITestContext context, int? port = null, bool publish = true) + /// The SMTP host to use. + /// The SMTP port to use. If it's then the value in the current + /// configuration (in ) is used + /// instead. + /// Whether to save the settings after configuring them. + public static async Task ConfigureSmtpSettingsAsync( + this UITestContext context, + string defaultSender, + string host, + int? port = null, + bool save = true) { await context.GoToEmailSettingsAsync(); await context.ClickReliablyOnAsync(By.CssSelector("a[href='#tab-s-m-t-p']")); @@ -117,12 +128,13 @@ public static async Task ConfigureSmtpPortAsync(this UITestContext context, int? "The SMTP port configuration is missing. Did you forget to include \"configuration.UseSmtpService = true\"?"); } - await context.ClickAndFillInWithRetriesAsync(By.Id("ISite_SmtpSettings_Host"), "localhost"); + await context.ClickAndFillInWithRetriesAsync(By.Id("ISite_SmtpSettings_DefaultSender"), defaultSender); + await context.ClickAndFillInWithRetriesAsync(By.Id("ISite_SmtpSettings_Host"), host); var smtpPort = port.Value.ToTechnicalString(); await context.ClickAndFillInWithRetriesAsync(By.Id("ISite_SmtpSettings_Port"), smtpPort); - if (publish) + if (save) { await context.ClickReliablyOnAsync(By.ClassName("save")); context.Get(By.ClassName("validation-summary-errors").Safely())?.Text?.Trim().ShouldBeNullOrEmpty(); diff --git a/Lombiq.Tests.UI/Extensions/OrchardCoreBuilderExtensions.cs b/Lombiq.Tests.UI/Extensions/OrchardCoreBuilderExtensions.cs index b8696cd0f..21ab2e486 100644 --- a/Lombiq.Tests.UI/Extensions/OrchardCoreBuilderExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/OrchardCoreBuilderExtensions.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; -using OrchardCore.Email; using OrchardCore.Modules; using System.Linq; @@ -38,18 +37,14 @@ public static OrchardCoreBuilder ConfigureUITesting( if (enableShortcutsDuringUITesting) builder.AddTenantFeatures("Lombiq.Tests.UI.Shortcuts"); - var smtpPort = configuration.GetValue("Lombiq_Tests_UI:SmtpSettings:Port"); - - if (!string.IsNullOrEmpty(smtpPort)) builder.AddTenantFeatures("OrchardCore.Email.Smtp"); + var enableSmtp = configuration.GetValue("Lombiq_Tests_UI:EnableSmtpFeature"); + if (enableSmtp) builder.AddTenantFeatures("OrchardCore.Email.Smtp"); if (configuration.GetValue("Lombiq_Tests_UI:UseAzureBlobStorage")) { builder.AddTenantFeatures("OrchardCore.Media.Azure.Storage"); } - return builder.ConfigureServices( - services => services - .PostConfigure(settings => - configuration.GetSection("Lombiq_Tests_UI:SmtpSettings").Bind(settings))); + return builder; } } diff --git a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs index 11ae1054f..81053f60a 100644 --- a/Lombiq.Tests.UI/Services/UITestExecutionSession.cs +++ b/Lombiq.Tests.UI/Services/UITestExecutionSession.cs @@ -747,8 +747,12 @@ Task SmtpServiceBeforeAppStartHandlerAsync(string contentRootPath, InstanceComma { _configuration.OrchardCoreConfiguration.BeforeAppStart -= SmtpServiceBeforeAppStartHandlerAsync; arguments - .AddWithValue("Lombiq_Tests_UI:SmtpSettings:Port", value: smtpContext.Port) - .AddWithValue("Lombiq_Tests_UI:SmtpSettings:Host", value: "localhost"); + .AddWithValue("Lombiq_Tests_UI:EnableSmtpFeature", value: true) + .AddWithValue("OrchardCore:OrchardCore_Email_Smtp:EnableSmtp", value: true) + .AddWithValue("OrchardCore:OrchardCore_Email_Smtp:Host", value: "localhost") + .AddWithValue("OrchardCore:OrchardCore_Email_Smtp:RequireCredentials", value: false) + .AddWithValue("OrchardCore:OrchardCore_Email_Smtp:Port", value: smtpContext.Port) + .AddWithValue("OrchardCore:OrchardCore_Email_Smtp:DefaultSender", value: "sender@example.com"); return Task.CompletedTask; }