Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs

80 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
2021-07-12 10:20:59 -06:00
using System;
using System.Linq;
2018-03-30 19:31:42 +02:00
using System.Threading;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models.Membership;
2021-07-12 10:20:59 -06:00
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider;
using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services
2017-09-14 19:29:12 +02:00
{
/// <summary>
/// Tests covering the SectionService
/// </summary>
2018-03-30 19:31:42 +02:00
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class SectionServiceTests : UmbracoIntegrationTest
2017-09-14 19:29:12 +02:00
{
2020-10-06 12:43:24 +02:00
private ISectionService SectionService => GetRequiredService<ISectionService>();
2020-10-06 12:43:24 +02:00
private IUserService UserService => GetRequiredService<IUserService>();
2019-01-18 10:02:47 +01:00
2017-09-14 19:29:12 +02:00
[Test]
public void SectionService_Can_Get_Allowed_Sections_For_User()
{
// Arrange
IUser user = CreateTestUser();
2017-09-14 19:29:12 +02:00
// Act
2020-10-06 12:43:24 +02:00
var result = SectionService.GetAllowedSections(user.Id).ToList();
2017-09-14 19:29:12 +02:00
// Assert
Assert.AreEqual(3, result.Count);
}
private IUser CreateTestUser()
{
2021-07-12 10:20:59 -06:00
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
using IDisposable _ = scope.Notifications.Suppress();
2021-07-12 10:20:59 -06:00
2020-09-21 21:06:24 +02:00
var globalSettings = new GlobalSettings();
2020-08-24 16:06:09 +02:00
var user = new User(globalSettings)
2017-09-14 19:29:12 +02:00
{
Name = "Test user",
Username = "testUser",
Email = "testuser@test.com",
};
2021-07-12 10:20:59 -06:00
UserService.Save(user);
2017-09-14 19:29:12 +02:00
var userGroupA = new UserGroup(ShortStringHelper)
2017-09-14 19:29:12 +02:00
{
Alias = "GroupA",
Name = "Group A"
};
userGroupA.AddAllowedSection("media");
userGroupA.AddAllowedSection("settings");
// TODO: This is failing the test
2021-07-12 10:20:59 -06:00
UserService.Save(userGroupA, new[] { user.Id });
2017-09-14 19:29:12 +02:00
var userGroupB = new UserGroup(ShortStringHelper)
2017-09-14 19:29:12 +02:00
{
Alias = "GroupB",
Name = "Group B"
};
userGroupB.AddAllowedSection("settings");
2019-01-17 17:50:59 +11:00
userGroupB.AddAllowedSection("member");
2021-07-12 10:20:59 -06:00
UserService.Save(userGroupB, new[] { user.Id });
2017-09-14 19:29:12 +02:00
2020-10-06 12:43:24 +02:00
return UserService.GetUserById(user.Id);
2017-09-14 19:29:12 +02:00
}
}
2017-09-23 10:08:18 +02:00
}