-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using Domain.Interfaces.Authorization; | ||
|
||
namespace Application.Interfaces; | ||
|
||
/// <inheritdoc cref="ICallerContext" /> | ||
public partial interface ICallerContext | ||
{ | ||
/// <summary> | ||
/// Defines the authorization roles that a caller can have | ||
/// </summary> | ||
public class CallerRoles | ||
{ | ||
public CallerRoles() | ||
{ | ||
All = Array.Empty<string>(); | ||
Platform = Array.Empty<string>(); | ||
Organization = Array.Empty<string>(); | ||
} | ||
|
||
public CallerRoles(string[]? platform, string[]? member) | ||
{ | ||
Platform = platform ?? Array.Empty<string>(); | ||
Organization = member ?? Array.Empty<string>(); | ||
All = Platform | ||
.Concat(Organization) | ||
.Distinct() | ||
.ToArray(); | ||
} | ||
|
||
public string[] All { get; } | ||
|
||
public string[] Organization { get; } | ||
|
||
public string[] Platform { get; } | ||
} | ||
|
||
/// <summary> | ||
/// Defines the sets of features that a caller can have | ||
/// </summary> | ||
public class CallerFeatureLevels | ||
{ | ||
public CallerFeatureLevels() | ||
{ | ||
All = Array.Empty<FeatureLevel>(); | ||
Platform = Array.Empty<FeatureLevel>(); | ||
Organization = Array.Empty<FeatureLevel>(); | ||
} | ||
|
||
public CallerFeatureLevels(FeatureLevel[]? platform, FeatureLevel[]? member) | ||
{ | ||
Platform = platform ?? Array.Empty<FeatureLevel>(); | ||
Organization = member ?? Array.Empty<FeatureLevel>(); | ||
All = Platform | ||
.Concat(Organization) | ||
.Distinct() | ||
.ToArray(); | ||
} | ||
|
||
public FeatureLevel[] All { get; } | ||
|
||
public FeatureLevel[] Organization { get; } | ||
|
||
public FeatureLevel[] Platform { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
using Domain.Interfaces.Authorization; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Domain.Interfaces.UnitTests.Authorization; | ||
|
||
[Trait("Category", "Unit")] | ||
public class FeatureLevelSpec | ||
{ | ||
[Fact] | ||
public void WhenEqualsAndNamesDifferent_ThenReturnsFalse() | ||
{ | ||
var level1 = new FeatureLevel("alevel1"); | ||
var level2 = new FeatureLevel("alevel2"); | ||
|
||
var result = level1.Equals(level2); | ||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameButNoChildren_ThenReturnsTrue() | ||
{ | ||
var level1 = new FeatureLevel("alevel1"); | ||
var level2 = new FeatureLevel("alevel1"); | ||
|
||
var result = level1.Equals(level2); | ||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameButOneHasChild_ThenReturnsFalse() | ||
{ | ||
var level1 = new FeatureLevel("alevel1"); | ||
var level2 = new FeatureLevel("alevel1", new FeatureLevel[] { new("achild1") }); | ||
|
||
var result = level1.Equals(level2); | ||
Check failure on line 38 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameButOneHasGrandChild_ThenReturnsFalse() | ||
{ | ||
var level1 = new FeatureLevel("alevel1", new FeatureLevel[] { new("achild1") }); | ||
var level2 = new FeatureLevel("alevel1", | ||
new FeatureLevel[] { new("achild1", new FeatureLevel[] { new("achild2") }) }); | ||
|
||
var result = level1.Equals(level2); | ||
Check failure on line 50 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameAndSameChild_ThenReturnsTrue() | ||
{ | ||
var level1 = new FeatureLevel("alevel1", new FeatureLevel[] { new("achild1") }); | ||
var level2 = new FeatureLevel("alevel1", new FeatureLevel[] { new("achild1") }); | ||
|
||
var result = level1.Equals(level2); | ||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameAndDifferentAncestors_ThenReturnsFalse() | ||
{ | ||
var level1 = new FeatureLevel("alevel1", | ||
new FeatureLevel[] { new("achild1", new FeatureLevel[] { new("achild2") }) }); | ||
var level2 = new FeatureLevel("alevel1", | ||
new FeatureLevel[] { new("achild1", new FeatureLevel[] { new("achild3") }) }); | ||
|
||
var result = level1.Equals(level2); | ||
Check failure on line 74 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenEqualsAndNamesSameAndSameAncestors_ThenReturnsTrue() | ||
{ | ||
var level1 = new FeatureLevel("alevel1", | ||
new FeatureLevel[] { new("achild1", new FeatureLevel[] { new("achild2") }) }); | ||
var level2 = new FeatureLevel("alevel1", | ||
new FeatureLevel[] { new("achild1", new FeatureLevel[] { new("achild2") }) }); | ||
|
||
var result = level1.Equals(level2); | ||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasNoChild_ThenFalse() | ||
{ | ||
var level = new FeatureLevel("alevel1"); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild")); | ||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasChild_ThenTrue() | ||
{ | ||
var level = new FeatureLevel("alevel1", new FeatureLevel[] | ||
{ | ||
new("achild") | ||
}); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild")); | ||
Check failure on line 110 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasNoChild2_ThenFalse() | ||
{ | ||
var level = new FeatureLevel("alevel1", new FeatureLevel[] | ||
{ | ||
new("alevel2") | ||
}); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild2")); | ||
|
||
result.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasGrandChild_ThenTrue() | ||
{ | ||
var level = new FeatureLevel("alevel1", | ||
new FeatureLevel[] | ||
{ | ||
new("alevel2", new FeatureLevel[] | ||
{ | ||
new("achild") | ||
}) | ||
}); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild")); | ||
Check failure on line 140 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasGreatGrandChild_ThenTrue() | ||
{ | ||
var level = new FeatureLevel("alevel1", | ||
new FeatureLevel[] | ||
{ | ||
new("alevel2", new FeatureLevel[] | ||
{ | ||
new("alevel3", new FeatureLevel[] | ||
{ | ||
new("achild") | ||
}) | ||
}) | ||
}); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild")); | ||
Check failure on line 160 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void WhenIsDescendantAndHasGreatGrandChild2_ThenTrue() | ||
{ | ||
var level = new FeatureLevel("alevel1", | ||
new FeatureLevel[] | ||
{ | ||
new("alevel2", | ||
new FeatureLevel[] | ||
{ | ||
new("alevel3", | ||
new FeatureLevel("achild1"), | ||
new FeatureLevel("achild2"), | ||
new FeatureLevel("achild3")) | ||
}) | ||
}); | ||
|
||
var result = level.IsDescendant(new FeatureLevel("achild2")); | ||
Check failure on line 181 in src/Domain.Interfaces.UnitTests/Authorization/FeatureLevelSpec.cs
|
||
|
||
result.Should().BeTrue(); | ||
} | ||
} |