// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Entities.Schemas; using Xunit; #pragma warning disable xUnit2017 // Do not use Contains() to check if a value exists in a collection namespace Squidex.Domain.Apps.Entities.Apps { public class RolePermissionsProviderTests { private readonly IAppProvider appProvider = A.Fake(); private readonly IAppEntity app = A.Fake(); private readonly RolePermissionsProvider sut; public RolePermissionsProviderTests() { A.CallTo(() => app.Name).Returns("my-app"); sut = new RolePermissionsProvider(appProvider); } [Fact] public async Task Should_provide_all_permissions() { A.CallTo(() => appProvider.GetSchemasAsync(A.Ignored)) .Returns(new List { CreateSchema("schema1"), CreateSchema("schema2") }); var result = await sut.GetPermissionsAsync(app); Assert.True(result.Contains("*")); Assert.True(result.Contains("clients.read")); Assert.True(result.Contains("schemas.*.read")); Assert.True(result.Contains("schemas.schema1.read")); Assert.True(result.Contains("schemas.schema2.read")); } private ISchemaEntity CreateSchema(string name) { var schema = A.Fake(); A.CallTo(() => schema.Name).Returns(name); return schema; } } }