Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Delete.cs
Mole 21b0a7ffae New Backoffice: Fix feedback to users controller (#14031)
* Add specific not found results

* Add tests for the enable/disable not found tweak

* Cache ids and key in UserIdKeyResolver

* Don't cache null keys

* BackOffice not Backoffice

* Move fetching the user out of the ChangePasswordUsersController

* Move resolving user out of SetAvatar

* Move resolving user out of Update

* Return more specific notfound in bykey

* Use ErrorResult for all endpoints with unknown errors

* Split integration tests

* Add mappers

* Use ?: consistently

* Add reuseable iso code validator

* Validate ISO code

* Update supressions

* Use method from base to get current user key

* Rename ISo to Iso

* Use keys in services instead of user groups + Added a couple of new validations

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2023-04-04 15:41:12 +02:00

71 lines
2.6 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;
public partial class UserServiceCrudTests
{
[Test]
public async Task Delete_Returns_Not_Found_If_Not_Found()
{
var userService = CreateUserService();
var result = await userService.DeleteAsync(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.Now;
userService.Save(createdUser);
var result = await userService.DeleteAsync(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(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);
}
}