Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

62 lines
2.0 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.Linq;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
/// <summary>
/// Tests covering the SectionService
/// </summary>
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public class SectionServiceTests : UmbracoIntegrationTest
{
private ISectionService SectionService => GetRequiredService<ISectionService>();
private IUserService UserService => GetRequiredService<IUserService>();
[Test]
public void SectionService_Can_Get_Allowed_Sections_For_User()
{
// Arrange
var user = CreateTestUser();
// Act
var result = SectionService.GetAllowedSections(user.Id).ToList();
// Assert
Assert.AreEqual(3, result.Count);
}
private IUser CreateTestUser()
{
using var scope = ScopeProvider.CreateScope(autoComplete: true);
using var _ = scope.Notifications.Suppress();
var globalSettings = new GlobalSettings();
var user = new User(globalSettings) { Name = "Test user", Username = "testUser", Email = "testuser@test.com" };
UserService.Save(user);
var userGroupA = new UserGroup(ShortStringHelper) { Alias = "GroupA", Name = "Group A" };
userGroupA.AddAllowedSection("media");
userGroupA.AddAllowedSection("settings");
// TODO: This is failing the test
UserService.Save(userGroupA, new[] { user.Id });
var userGroupB = new UserGroup(ShortStringHelper) { Alias = "GroupB", Name = "Group B" };
userGroupB.AddAllowedSection("settings");
userGroupB.AddAllowedSection("member");
UserService.Save(userGroupB, new[] { user.Id });
return UserService.GetUserById(user.Id);
}
}