Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Delete.cs
Andy Butland d623476902 Use UTC for system dates in Umbraco (#19822)
* Persist and expose Umbraco system dates as UTC (#19705)

* Updated persistence DTOs defining default dates to use UTC.

* Remove ForceToUtc = false from all persistence DTO attributes (default when not specified is true).

* Removed use of SpecifyKind setting dates to local.

* Removed unnecessary Utc suffixes on properties.

* Persist current date time with UtcNow.

* Removed further necessary Utc suffixes and fixed failing unit tests.

* Added migration for SQL server to update database date default constraints.

* Added comment justifying not providing a migration for SQLite default date constraints.

* Ensure UTC for datetimes created from persistence DTOs.

* Ensure UTC when creating dates for published content rendering in Razor and outputting in delivery API.

* Fixed migration SQL syntax.

* Introduced AuditItemFactory for creating entries for the backoffice document history, so we can control the UTC setting on the retrieved persisted dates.

* Ensured UTC dates are retrieved for document versions.

* Ensured UTC is returned for backoffice display of last edited and published for variant content.

* Fixed SQLite syntax for default current datetime.

* Apply suggestions from code review

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>

* Further updates from code review.

---------

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>

* Migrate system dates from local server time to UTC (#19798)

* Add settings for the migration.

* Add migration and implement for SQL server.

* Implement for SQLite.

* Fixes from testing with SQL Server.

* Fixes from testing with SQLite.

* Code tidy.

* Cleaned up usings.

* Removed audit log date from conversion.

* Removed webhook log date from conversion.

* Updated update date initialization on saving dictionary items.

* Updated filter on log queries.

* Use timezone ID instead of system name to work cross-culture.

---------

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>
2025-08-22 11:59:23 +02:00

71 lines
2.7 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Services.OperationStatus;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
internal sealed partial class UserServiceCrudTests
{
[Test]
public async Task Delete_Returns_Not_Found_If_Not_Found()
{
var userService = CreateUserService();
var result = await userService.DeleteAsync(Constants.Security.SuperUserKey, Guid.NewGuid());
Assert.AreEqual(UserOperationStatus.UserNotFound, result);
}
[Test]
public async Task Cannot_Delete_User_With_Login()
{
var userGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias);
var userCreateModel = new UserCreateModel
{
Email = "test@test.com",
UserName = "test@test.com",
Name = "test@test.com",
UserGroupKeys = new HashSet<Guid> { userGroup.Key }
};
var userService = CreateUserService();
var creationResult = await userService.CreateAsync(Constants.Security.SuperUserKey, userCreateModel, true);
Assert.IsTrue(creationResult.Success);
var createdUser = creationResult.Result.CreatedUser;
createdUser!.LastLoginDate = DateTime.UtcNow;
userService.Save(createdUser);
var result = await userService.DeleteAsync(Constants.Security.SuperUserKey, createdUser.Key);
Assert.AreEqual(UserOperationStatus.CannotDelete, result);
// Asset that it is in fact not deleted
var postDeletedUser = await userService.GetAsync(createdUser.Key);
Assert.IsNotNull(postDeletedUser);
Assert.AreEqual(createdUser.Key, postDeletedUser.Key);
}
[Test]
public async Task Can_Delete_User_That_Has_Not_Logged_In()
{
var userGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias);
var userCreateModel = new UserCreateModel
{
Email = "test@test.com",
UserName = "test@test.com",
Name = "test@test.com",
UserGroupKeys = new HashSet<Guid> { userGroup.Key }
};
var userService = CreateUserService();
var creationResult = await userService.CreateAsync(Constants.Security.SuperUserKey, userCreateModel, true);
Assert.IsTrue(creationResult.Success);
var deletionResult = await userService.DeleteAsync(Constants.Security.SuperUserKey, creationResult.Result.CreatedUser!.Key);
Assert.AreEqual(UserOperationStatus.Success, deletionResult);
// Make sure it's actually deleted
var postDeletedUser = await userService.GetAsync(creationResult.Result.CreatedUser.Key);
Assert.IsNull(postDeletedUser);
}
}