Skip to content

Commit

Permalink
Merge pull request #44 from SSchulze1989/develop
Browse files Browse the repository at this point in the history
v 0.6.2
  • Loading branch information
SSchulze1989 authored May 4, 2023
2 parents f833fe3 + b8b7db9 commit 2accbb2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/iRLeagueApiCore.Common/LeagueRoleValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ internal LeagueRoleValue(string value)
internal LeagueRoleValue(string value, IEnumerable<LeagueRoleValue> implicitRoles)
{
this.value = value;
this.implicitRoles = implicitRoles.ToArray();
this.implicitRoles = implicitRoles
.SelectMany(x => new[] { x }.Concat(x.GetImplicitRoles()))
.ToArray();
}

public static implicit operator string(LeagueRoleValue role) => role.value;
Expand Down
9 changes: 8 additions & 1 deletion src/iRLeagueApiCore.Common/LeagueRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ public static class LeagueRoles
/// Administrator of the league with full privileges
/// </summary>
public const string Admin = "Admin";
public static LeagueRoleValue AdminValue { get; } = new(Admin, new[] { OrganizerValue, StewardValue, MemberValue });
public static LeagueRoleValue AdminValue { get; } = new(Admin, new[] { OrganizerValue, StewardValue });
/// <summary>
/// Owner of the league
/// Full privilige including right to delete
/// </summary>
public const string Owner = "Owner";
public static LeagueRoleValue OwnerValue { get; } = new(Owner, new[] { AdminValue });

/// <summary>
/// Array of all available league roles
/// </summary>
public static LeagueRoleValue[] RolesAvailable { get; } = new[]
{
OwnerValue,
AdminValue,
OrganizerValue,
StewardValue,
Expand Down
2 changes: 1 addition & 1 deletion src/iRLeagueApiCore.Common/iRLeagueApiCore.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PackageId>iRLeagueApiCore.Common</PackageId>
<Version>0.6.1</Version>
<Version>0.6.2</Version>
<Authors>Simon Schulze</Authors>
<Company>Simon Schulze</Company>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
20 changes: 12 additions & 8 deletions test/iRLeagueApiCore.Common.Tests/LeagueRolesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ namespace iRLeagueApiCore.Common.Tests;
public class LeagueRolesTests
{
[Theory]
[InlineData("Admin", true, true, true, true)]
[InlineData("Organizer", false, true, false, true)]
[InlineData("Steward", false, false, true, true)]
[InlineData("Member", false, false, false, true)]
[InlineData(LeagueRoles.Owner, true, true, true, true, true)]
[InlineData(LeagueRoles.Admin, false, true, true, true, true)]
[InlineData(LeagueRoles.Organizer, false, false, true, false, true)]
[InlineData(LeagueRoles.Steward, false, false, false, true, true)]
[InlineData(LeagueRoles.Member, false, false, false, false, true)]
public void ShouldHaveRoles(string roleName,
bool owner,
bool admin,
bool organizer,
bool steward,
Expand All @@ -17,17 +19,19 @@ public void ShouldHaveRoles(string roleName,
var role = LeagueRoles.GetRoleValue(roleName);
var roles = new[] { role };

LeagueRoles.CheckRole(LeagueRoles.OwnerValue, roles).Should().Be(owner);
LeagueRoles.CheckRole(LeagueRoles.AdminValue, roles).Should().Be(admin);
LeagueRoles.CheckRole(LeagueRoles.OrganizerValue, roles).Should().Be(organizer);
LeagueRoles.CheckRole(LeagueRoles.StewardValue, roles).Should().Be(steward);
LeagueRoles.CheckRole(LeagueRoles.MemberValue, roles).Should().Be(member);
}

[Theory]
[InlineData("Admin", new string[0])]
[InlineData("Organizer", new[] { "Admin" })]
[InlineData("Steward", new[] { "Admin" })]
[InlineData("Member", new[] { "Admin", "Organizer", "Steward" })]
[InlineData(LeagueRoles.Owner, new string[0])]
[InlineData(LeagueRoles.Admin, new[] { LeagueRoles.Owner })]
[InlineData(LeagueRoles.Organizer, new[] { LeagueRoles.Owner, LeagueRoles.Admin })]
[InlineData(LeagueRoles.Steward, new[] { LeagueRoles.Owner, LeagueRoles.Admin })]
[InlineData(LeagueRoles.Member, new[] { LeagueRoles.Owner, LeagueRoles.Admin, LeagueRoles.Organizer, LeagueRoles.Steward })]
public void ShouldBeImplicitOf(string roleName, string[] implicitOfRoleNames)
{
// Setup
Expand Down

0 comments on commit 2accbb2

Please sign in to comment.