diff --git a/Lombiq.Tests.UI.Samples/Tests/ShiftTimeTests.cs b/Lombiq.Tests.UI.Samples/Tests/ShiftTimeTests.cs index bafbc05c4..f96809215 100644 --- a/Lombiq.Tests.UI.Samples/Tests/ShiftTimeTests.cs +++ b/Lombiq.Tests.UI.Samples/Tests/ShiftTimeTests.cs @@ -11,8 +11,8 @@ namespace Lombiq.Tests.UI.Samples.Tests; // When you enable the "Shift Time - Shortcuts - Lombiq UI Testing Toolbox" feature, it replaces Orchard Core's stock -// ICLock implementation with the custom ShiftTimeClock class. You can use the -// ~/Lombiq.Tests.UI.Samples/ShiftTime/Set?days=... action to update the ShiftTimeClock.Shift property for the current +// ICLock implementation with the custom TimeShiftingClock class. You can use the +// ~/Lombiq.Tests.UI.Samples/TimeShift/Set?days=... action to update the TimeShiftingClock.Shift property for the current // tenant, which will trick any service that uses IClock into thinking you are in the future. This can be used to test // features that can expire, such as a limited-time product discount in a web store, without having to wait. public class ShiftTimeTests : UITestBase @@ -46,7 +46,7 @@ await context.FillInCodeMirrorEditorWithRetriesAsync( // This extension method navigates to the action which sets the time offset. You can set it in terms of // days or seconds. Both accept fractions and negative values. If both days and seconds are set, they // are added together. - await context.SetShiftTimeAsync(days: 10); + await context.SetTimeShiftAsync(TimeSpan.FromDays(10)); // Let's verify the date! var tenDaysFromNow = await GetNowAsync(context); diff --git a/Lombiq.Tests.UI.Shortcuts/Controllers/ShiftTimeController.cs b/Lombiq.Tests.UI.Shortcuts/Controllers/TimeShiftController.cs similarity index 76% rename from Lombiq.Tests.UI.Shortcuts/Controllers/ShiftTimeController.cs rename to Lombiq.Tests.UI.Shortcuts/Controllers/TimeShiftController.cs index 631b524b1..6fe3e6d1a 100644 --- a/Lombiq.Tests.UI.Shortcuts/Controllers/ShiftTimeController.cs +++ b/Lombiq.Tests.UI.Shortcuts/Controllers/TimeShiftController.cs @@ -7,11 +7,11 @@ namespace Lombiq.Tests.UI.Shortcuts.Controllers; [DevelopmentAndLocalhostOnly] -public class ShiftTimeController : Controller +public class TimeShiftController : Controller { private readonly IClock _clock; - public ShiftTimeController(IClock clock) => _clock = clock; + public TimeShiftController(IClock clock) => _clock = clock; public IActionResult Set(double days, double seconds) => SetInner(_ => TimeSpan.FromDays(days) + TimeSpan.FromSeconds(seconds)); @@ -20,7 +20,7 @@ public IActionResult Add(double days, double seconds) => SetInner(current => current + TimeSpan.FromDays(days) + TimeSpan.FromSeconds(seconds)); private IActionResult SetInner(Func edit) => - ShiftTimeClock.UpdateClock(_clock, edit) is { } totalSeconds + TimeShiftingClock.UpdateClock(_clock, edit) is { } totalSeconds ? Ok(totalSeconds) - : BadRequest($"The clock is {_clock.GetType().FullName} instead of {nameof(ShiftTimeClock)}."); + : BadRequest($"The clock is {_clock.GetType().FullName} instead of {nameof(TimeShiftingClock)}."); } diff --git a/Lombiq.Tests.UI.Shortcuts/Services/ShiftTimeClock.cs b/Lombiq.Tests.UI.Shortcuts/Services/TimeShiftingClock.cs similarity index 81% rename from Lombiq.Tests.UI.Shortcuts/Services/ShiftTimeClock.cs rename to Lombiq.Tests.UI.Shortcuts/Services/TimeShiftingClock.cs index d7e273a3e..3c9cd405d 100644 --- a/Lombiq.Tests.UI.Shortcuts/Services/ShiftTimeClock.cs +++ b/Lombiq.Tests.UI.Shortcuts/Services/TimeShiftingClock.cs @@ -10,7 +10,7 @@ namespace Lombiq.Tests.UI.Shortcuts.Services; /// cref="IClock"/> into believing it's the future or past. This service is registered as singleton, so setting will persist in the tenant across requests. /// -public class ShiftTimeClock : IClock +public class TimeShiftingClock : IClock { private readonly Clock _inner = new(); @@ -34,18 +34,18 @@ public DateTimeOffset ConvertToTimeZone(DateTimeOffset dateTimeOffset, ITimeZone /// Use this to safely update the value. /// /// - /// The injected service, if it's then its property is updated. + /// The injected service, if it's then its property is updated. /// /// Input is the current value of , output is the new value. /// /// The total seconds of the new value of , or if - /// is not . + /// is not . /// public static double? UpdateClock(IClock clock, Func edit) { - if (clock is not ShiftTimeClock shiftTimeClock) return null; + if (clock is not TimeShiftingClock timeShiftingClock) return null; - shiftTimeClock.Shift = edit(shiftTimeClock.Shift); - return shiftTimeClock.Shift.TotalSeconds; + timeShiftingClock.Shift = edit(timeShiftingClock.Shift); + return timeShiftingClock.Shift.TotalSeconds; } } diff --git a/Lombiq.Tests.UI.Shortcuts/ShortcutsFeatureIds.cs b/Lombiq.Tests.UI.Shortcuts/ShortcutsFeatureIds.cs index c38f31560..1f7532430 100644 --- a/Lombiq.Tests.UI.Shortcuts/ShortcutsFeatureIds.cs +++ b/Lombiq.Tests.UI.Shortcuts/ShortcutsFeatureIds.cs @@ -7,9 +7,9 @@ public static class ShortcutsFeatureIds public const string Area = "Lombiq.Tests.UI.Shortcuts"; public const string Default = Area; - public const string FeatureToggleTestBench = Default + ".FeatureToggleTestBench"; - public const string MediaCachePurge = Default + ".MediaCachePurge"; - public const string ShiftTime = Default + ".ShiftTime"; - public const string Swagger = Default + ".Swagger"; - public const string Workflows = Default + ".Workflows"; + public const string FeatureToggleTestBench = $"{Default}.{nameof(FeatureToggleTestBench)}"; + public const string MediaCachePurge = $"{Default}.{nameof(MediaCachePurge)}"; + public const string ShiftTime = $"{Default}.{nameof(ShiftTime)}"; + public const string Swagger = $"{Default}.{nameof(Swagger)}"; + public const string Workflows = $"{Default}.{nameof(Workflows)}"; } diff --git a/Lombiq.Tests.UI.Shortcuts/Startup.cs b/Lombiq.Tests.UI.Shortcuts/Startup.cs index 1e5179e6f..fbfe3cd81 100644 --- a/Lombiq.Tests.UI.Shortcuts/Startup.cs +++ b/Lombiq.Tests.UI.Shortcuts/Startup.cs @@ -44,6 +44,6 @@ public sealed class SetTimeStartup : StartupBase public override void ConfigureServices(IServiceCollection services) { services.RemoveImplementationsOf(); - services.AddSingleton(); + services.AddSingleton(); } } diff --git a/Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs index 375256bcc..78974168f 100644 --- a/Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/ShortcutsUITestContextExtensions.cs @@ -744,23 +744,25 @@ public static Task ExecuteJsonRecipeSiteSettingAsync(this UITestContext conte public static Task EnableTimeShiftingAsync(this UITestContext context) => context.EnableFeatureDirectlyAsync(ShiftTime); /// - /// Sets the time shift to a specific value. If both and are - /// provided, then the values are added together. + /// Sets the time shift to a specific value. /// - public static Task SetShiftTimeAsync(this UITestContext context, double days = 0, double seconds = 0) + public static Task SetTimeShiftAsync(this UITestContext context, TimeSpan time) { context.EnsureValidOrchardCoreTenantScope(); - return context.GoToAsync(controller => controller.Set(days, seconds)); + return time.TotalDays >= 1.0 + ? context.GoToAsync(controller => controller.Set(time.TotalDays, 0)) + : context.GoToAsync(controller => controller.Set(0, time.TotalSeconds)); } /// - /// Adds the specified value to the time shift. If both and are - /// provided, then the values for both are added. Negative values are supported as well. + /// Adds the specified value to the time shift. /// - public static Task AddShiftTimeAsync(this UITestContext context, double days = 0, double seconds = 0) + public static Task AddTimeShiftAsync(this UITestContext context, TimeSpan time) { context.EnsureValidOrchardCoreTenantScope(); - return context.GoToAsync(controller => controller.Add(days, seconds)); + return time.TotalDays >= 1.0 + ? context.GoToAsync(controller => controller.Add(time.TotalDays, 0)) + : context.GoToAsync(controller => controller.Add(0, time.TotalSeconds)); } ///