fix tests
This commit is contained in:
@@ -149,7 +149,7 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PostUnlockUsers_When_User_Does_Not_Exist_Expect_InvalidOperationException()
|
||||
public async Task PostUnlockUsers_When_User_Does_Not_Exist_Expect_Zero_Users_Message()
|
||||
{
|
||||
var userId = 42; // Must not exist
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(new []{userId}));
|
||||
@@ -158,18 +158,15 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
var response = await Client.PostAsync(url, new StringContent(string.Empty));
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix);
|
||||
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
|
||||
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var actual = JsonConvert.DeserializeObject<ExceptionViewModel>(body, new JsonSerializerSettings
|
||||
var actual = JsonConvert.DeserializeObject<SimpleNotificationModel>(body, new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new IgnoreRequiredAttributesResolver()
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var expected = new InvalidOperationException();
|
||||
Assert.IsNotNull(actual);
|
||||
Assert.AreEqual(expected.GetType(), actual.ExceptionType);
|
||||
Assert.AreEqual(expected.Message, actual.ExceptionMessage);
|
||||
Assert.AreEqual($"Unlocked 0 users", actual.Message);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -230,8 +227,6 @@ namespace Umbraco.Tests.Integration.TestServerTest.Controllers
|
||||
userService.Save(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
var url = PrepareUrl<UsersController>(x => x.PostUnlockUsers(users.Select(x=>x.Id).ToArray()));
|
||||
|
||||
// Act
|
||||
|
||||
@@ -739,11 +739,16 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
public async Task<IActionResult> PostUnlockUsers([FromQuery]int[] userIds)
|
||||
{
|
||||
if (userIds.Length <= 0) return Ok();
|
||||
var notFound = new List<int>();
|
||||
|
||||
foreach (var u in userIds)
|
||||
{
|
||||
var user = await _backOfficeUserManager.FindByIdAsync(u.ToString());
|
||||
if (user == null) throw new InvalidOperationException();
|
||||
if (user == null)
|
||||
{
|
||||
notFound.Add(u);
|
||||
continue;
|
||||
}
|
||||
|
||||
var unlockResult = await _backOfficeUserManager.SetLockoutEndDateAsync(user, DateTimeOffset.Now);
|
||||
if (unlockResult.Succeeded == false)
|
||||
@@ -760,7 +765,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
}
|
||||
|
||||
return new UmbracoNotificationSuccessResponse(
|
||||
_localizedTextService.Localize("speechBubbles/unlockUsersSuccess", new[] {userIds.Length.ToString()}));
|
||||
_localizedTextService.Localize("speechBubbles/unlockUsersSuccess", new[] {(userIds.Length - notFound.Count).ToString()}));
|
||||
}
|
||||
|
||||
[AdminUsersAuthorize("userIds")]
|
||||
|
||||
Reference in New Issue
Block a user