|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.AspNetCore.Identity; |
| 7 | +using Microsoft.Extensions.Options; |
| 8 | +using NUnit.Framework; |
| 9 | +using Umbraco.Cms.Core.Configuration.Models; |
| 10 | +using Umbraco.Cms.Core.Mapping; |
| 11 | +using Umbraco.Cms.Core.Models.Membership; |
| 12 | +using Umbraco.Cms.Core.Scoping; |
| 13 | +using Umbraco.Cms.Core.Security; |
| 14 | +using Umbraco.Cms.Core.Services; |
| 15 | +using Umbraco.Cms.Tests.Common.Testing; |
| 16 | +using Umbraco.Cms.Tests.Integration.Testing; |
| 17 | + |
| 18 | +namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Security |
| 19 | +{ |
| 20 | + [TestFixture] |
| 21 | + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] |
| 22 | + public class BackOfficeUserStoreTests : UmbracoIntegrationTest |
| 23 | + { |
| 24 | + private IUserService UserService => GetRequiredService<IUserService>(); |
| 25 | + private IEntityService EntityService => GetRequiredService<IEntityService>(); |
| 26 | + private IExternalLoginService ExternalLoginService => GetRequiredService<IExternalLoginService>(); |
| 27 | + private IUmbracoMapper UmbracoMapper => GetRequiredService<IUmbracoMapper>(); |
| 28 | + private ILocalizedTextService TextService => GetRequiredService<ILocalizedTextService>(); |
| 29 | + |
| 30 | + private BackOfficeUserStore GetUserStore() |
| 31 | + => new BackOfficeUserStore( |
| 32 | + ScopeProvider, |
| 33 | + UserService, |
| 34 | + EntityService, |
| 35 | + ExternalLoginService, |
| 36 | + Options.Create(GlobalSettings), |
| 37 | + UmbracoMapper, |
| 38 | + new BackOfficeErrorDescriber(TextService), |
| 39 | + AppCaches); |
| 40 | + |
| 41 | + [Test] |
| 42 | + public async Task Can_Persist_Is_Approved() |
| 43 | + { |
| 44 | + var userStore = GetUserStore(); |
| 45 | + var user = new BackOfficeIdentityUser(GlobalSettings, 1, new List<IReadOnlyUserGroup>()) |
| 46 | + { |
| 47 | + Name = "Test", |
| 48 | + |
| 49 | + |
| 50 | + }; |
| 51 | + IdentityResult createResult = await userStore.CreateAsync(user); |
| 52 | + Assert.IsTrue(createResult.Succeeded); |
| 53 | + Assert.IsFalse(user.IsApproved); |
| 54 | + |
| 55 | + // update |
| 56 | + user.IsApproved = true; |
| 57 | + var saveResult = await userStore.UpdateAsync(user); |
| 58 | + Assert.IsTrue(saveResult.Succeeded); |
| 59 | + Assert.IsTrue(user.IsApproved); |
| 60 | + |
| 61 | + // get get |
| 62 | + user = await userStore.FindByIdAsync(user.Id); |
| 63 | + Assert.IsTrue(user.IsApproved); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments