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

Add IUserTimeZoneService to make it easier to mock UserTimeZoneService #16614

Merged
merged 19 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -10,9 +10,9 @@ namespace OrchardCore.Users.TimeZone.Drivers;

public sealed class UserTimeZoneDisplayDriver : SectionDisplayDriver<User, UserTimeZone>
{
private readonly UserTimeZoneService _userTimeZoneService;
private readonly IUserTimeZoneService _userTimeZoneService;

public UserTimeZoneDisplayDriver(UserTimeZoneService userTimeZoneService)
public UserTimeZoneDisplayDriver(IUserTimeZoneService userTimeZoneService)
{
_userTimeZoneService = userTimeZoneService;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using OrchardCore.Modules;

namespace OrchardCore.Users.TimeZone.Services;

/// <summary>
/// Contract for user time zone service.
/// </summary>
public interface IUserTimeZoneService
{
/// <summary>
/// Gets the time zone of the currently logged-in user.
/// </summary>
public ValueTask<ITimeZone> GetUserTimeZoneAsync();
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Updates the time zone of the currently logged-in user.
/// </summary>
/// <param name="user">The <see cref="IUser"/>.</param>
public ValueTask UpdateUserTimeZoneAsync(IUser user);
hishamco marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets the time zone identifier of the currently logged-in user.
/// </summary>
public ValueTask<string> GetCurrentUserTimeZoneIdAsync();
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace OrchardCore.Users.TimeZone.Services;
/// </summary>
public class UserTimeZoneSelector : ITimeZoneSelector
{
private readonly UserTimeZoneService _userTimeZoneService;
private readonly IUserTimeZoneService _userTimeZoneService;

public UserTimeZoneSelector(UserTimeZoneService userTimeZoneService)
public UserTimeZoneSelector(IUserTimeZoneService userTimeZoneService)
{
_userTimeZoneService = userTimeZoneService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OrchardCore.Users.TimeZone.Services;

public class UserTimeZoneService
public class UserTimeZoneService : IUserTimeZoneService
{
private const string EmptyTimeZone = "empty";
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
private const string CacheKey = "UserTimeZone/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class Startup : StartupBase
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ITimeZoneSelector, UserTimeZoneSelector>();
services.AddSingleton<UserTimeZoneService>();
services.AddSingleton<IUserTimeZoneService, UserTimeZoneService>();
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
services.AddScoped<IDisplayDriver<User>, UserTimeZoneDisplayDriver>();
}
}