Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

79 lines
2.4 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Scoping;
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
IUser user = CreateTestUser();
// Act
var result = SectionService.GetAllowedSections(user.Id).ToList();
// Assert
Assert.AreEqual(3, result.Count);
}
private IUser CreateTestUser()
{
using IScope scope = ScopeProvider.CreateScope(autoComplete: true);
using IDisposable _ = 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);
}
}
}