mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Implements authorization caching and check in the web client
This commit is contained in:
1 parent
7bca5b1ba3
commit
8eb1b9f13c
108 files changed
+5931
-73
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetAuthorizationRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAuthorizationRequestMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetAuthorizationRequest request = new(userId);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = new(null);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().BeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("00000000-0000-0000-0000-000000000000")]
|
||||
[InlineData("12345678-1234-1234-1234-123456789012")]
|
||||
[InlineData("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")]
|
||||
public void ToQuery_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.Parse(userIdString);
|
||||
GetAuthorizationRequest request = new(userId);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(request.UserId);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UserAuthorizationEntityMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserAuthorizationEntityMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidEntity_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Roles = new HashSet<AuthorizationRole> { AuthorizationRole.Admin },
|
||||
Permissions = new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
};
|
||||
|
||||
// Act
|
||||
GetAuthorizationResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(entity.UserId);
|
||||
result.Roles.Should().BeEquivalentTo(entity.Roles);
|
||||
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingEntityWithEmptyCollections_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Roles = new HashSet<AuthorizationRole>(),
|
||||
Permissions = new HashSet<AuthorizationPermission>()
|
||||
};
|
||||
|
||||
// Act
|
||||
GetAuthorizationResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(entity.UserId);
|
||||
result.Roles.Should().BeEmpty();
|
||||
result.Permissions.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingEntityWithMultipleRolesAndPermissions_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.NewGuid(),
|
||||
Roles = new HashSet<AuthorizationRole>
|
||||
{
|
||||
AuthorizationRole.Admin,
|
||||
AuthorizationRole.None
|
||||
},
|
||||
Permissions = new HashSet<AuthorizationPermission>
|
||||
{
|
||||
AuthorizationPermission.CanViewUsers,
|
||||
AuthorizationPermission.CanDeleteUsers,
|
||||
AuthorizationPermission.CanRegisterUsers
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
GetAuthorizationResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(entity.UserId);
|
||||
result.Roles.Should().BeEquivalentTo(entity.Roles);
|
||||
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("00000000-0000-0000-0000-000000000000")]
|
||||
[InlineData("12345678-1234-1234-1234-123456789012")]
|
||||
[InlineData("FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")]
|
||||
public void ToResponse_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
||||
{
|
||||
// Arrange
|
||||
UserAuthorizationEntity entity = new()
|
||||
{
|
||||
UserId = Guid.Parse(userIdString),
|
||||
Roles = new HashSet<AuthorizationRole> { AuthorizationRole.Admin },
|
||||
Permissions = new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
};
|
||||
|
||||
// Act
|
||||
GetAuthorizationResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(entity.UserId);
|
||||
result.Roles.Should().BeEquivalentTo(entity.Roles);
|
||||
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user