mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Formats code comments as sentences in the tests.
Capitalizes the first word and adds the terminal period in the unit, integration and security tests. The AAA markers stay bare, the TODO bodies stay lowercase, and no assertion, payload, expected status code or test signature changes.
This commit is contained in:
1 parent
727aa33318
commit
057f557791
540 files changed
+3888
-3888
No files matched your search
+2
-2
@@ -123,11 +123,11 @@ public class GetUsersEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// clear junction tables first
|
||||
// Clear junction tables first.
|
||||
await dbContext.Set<RolePermissionEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<UserPermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
// then clear main tables
|
||||
// Then clear main tables.
|
||||
await dbContext.Set<UserEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<RoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<PermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
+1
-1
@@ -310,7 +310,7 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
|
||||
UserEntity user = _userEntityFixture.Create(username: _testUsername, password: _hashService.HashString("TestPass123!"));
|
||||
user.TotpSecret = null;
|
||||
user.TempPassword = Uri.EscapeDataString(_hashService.HashString("TempPass123!"));
|
||||
user.TempPasswordCreated = DateTime.UtcNow.AddMinutes(-16); // expired (> 15 minutes old)
|
||||
user.TempPasswordCreated = DateTime.UtcNow.AddMinutes(-16); // Expired (> 15 minutes old).
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
+6
-6
@@ -58,7 +58,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
_apiFactory = apiFactory;
|
||||
_testUsername = $"testuser_{Guid.NewGuid()}";
|
||||
|
||||
// get the encryption service with the test key from factory
|
||||
// Get the encryption service with the test key from factory.
|
||||
using IServiceScope scope = apiFactory.Services.CreateScope();
|
||||
_cryptographyService = scope.ServiceProvider.GetRequiredService<ICryptographyService>();
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
// Arrange
|
||||
UserEntity user = await CreateUserWithTotp();
|
||||
|
||||
// decrypt the TOTP secret and generate a valid code
|
||||
// Decrypt the TOTP secret and generate a valid code.
|
||||
byte[] totpSecret = Convert.FromBase64String(_cryptographyService.Decrypt(user.TotpSecret!));
|
||||
Totp totp = new(totpSecret);
|
||||
string validTotpCode = totp.ComputeTotp(DateTime.UtcNow);
|
||||
@@ -101,11 +101,11 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
Assert.NotNull(result);
|
||||
Assert.True(result!.IsPasswordReset);
|
||||
|
||||
// Create a new context to get fresh data
|
||||
// Create a new context to get fresh data.
|
||||
using IServiceScope verificationScope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext verificationContext = verificationScope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// Ensure we get fresh data from the database
|
||||
// Ensure we get fresh data from the database.
|
||||
verificationContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
UserEntity? updatedUser = await verificationContext.Users
|
||||
.AsNoTracking()
|
||||
@@ -244,12 +244,12 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
public async Task RecoverPassword_WhenUserDoesNotUseTotpAndTriesToRecoverWithoutCode_ShouldReturnForbiddenResult()
|
||||
{
|
||||
// Arrange
|
||||
// Setup user without TOTP
|
||||
// Setup user without TOTP.
|
||||
using (IServiceScope scope = _apiFactory.Services.CreateScope())
|
||||
{
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
UserEntity userWithoutTotp = _userEntityFixture.Create(username: "userwithoutotp2", password: _hashService.HashString("OldPass123!"));
|
||||
userWithoutTotp.TotpSecret = null; // No TOTP configured
|
||||
userWithoutTotp.TotpSecret = null; // No TOTP configured.
|
||||
dbContext.Users.Add(userWithoutTotp);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
+5
-5
@@ -174,7 +174,7 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
|
||||
|
||||
private async Task<UserEntity> AddRolesAndPermissionsToUser(UserEntity existingUser, LuminaDbContext dbContext)
|
||||
{
|
||||
// create and save role and permission first
|
||||
// Create and save role and permission first.
|
||||
RoleEntity adminRole = _roleEntityFixture.Create(roleName: "Admin");
|
||||
PermissionEntity viewUsersPermission = _permissionEntityFixture.Create(permissionName: AuthorizationPermission.CanViewUsers);
|
||||
|
||||
@@ -182,21 +182,21 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
|
||||
await dbContext.Permissions.AddAsync(viewUsersPermission);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// create role permission
|
||||
// Create role permission.
|
||||
RolePermissionEntity rolePermission = _rolePermissionEntityFixture.Create(role: adminRole, permission: viewUsersPermission);
|
||||
await dbContext.RolePermissions.AddAsync(rolePermission);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// remove existing user role if any
|
||||
// Remove existing user role if any.
|
||||
if (existingUser.UserRole != null)
|
||||
dbContext.UserRoles.Remove(existingUser.UserRole);
|
||||
|
||||
// add new user role
|
||||
// Add new user role.
|
||||
UserRoleEntity userRole = _userRoleEntityFixture.Create(user: existingUser, role: adminRole);
|
||||
await dbContext.UserRoles.AddAsync(userRole);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// refresh the user entity
|
||||
// Refresh the user entity.
|
||||
await dbContext.Entry(existingUser).ReloadAsync();
|
||||
|
||||
return existingUser;
|
||||
|
||||
+3
-3
@@ -65,7 +65,7 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
UserEntity? user = dbContext.Users.FirstOrDefault();
|
||||
Assert.NotNull(user);
|
||||
|
||||
// Add a direct user permission
|
||||
// Add a direct user permission.
|
||||
PermissionEntity permission = dbContext.Permissions.First();
|
||||
UserPermissionEntity userPermission = _userPermissionEntityFixture.Create(user, permission);
|
||||
dbContext.UserPermissions.Add(userPermission);
|
||||
@@ -169,11 +169,11 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// clear junction tables first
|
||||
// Clear junction tables first.
|
||||
await dbContext.Set<RolePermissionEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<UserPermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
// then clear main tables
|
||||
// Then clear main tables.
|
||||
await dbContext.Set<UserEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<RoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<PermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
+2
-2
@@ -156,11 +156,11 @@ public class GetUserRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// clear junction tables first
|
||||
// Clear junction tables first.
|
||||
await dbContext.Set<RolePermissionEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<UserPermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
// then clear main tables
|
||||
// Then clear main tables.
|
||||
await dbContext.Set<UserEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<RoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<PermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
+6
-6
@@ -68,12 +68,12 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// create a non-admin role first
|
||||
// Create a non-admin role first.
|
||||
RoleEntity editorRole = _roleEntityFixture.Create(roleName: "Editor");
|
||||
dbContext.Roles.Add(editorRole);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// create test user
|
||||
// Create test user.
|
||||
UserEntity user = _userEntityFixture.Create(username: "TestUser", password: "HashedPassword");
|
||||
user.TotpSecret = null;
|
||||
dbContext.Users.Add(user);
|
||||
@@ -140,12 +140,12 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// create Editor role
|
||||
// Create Editor role.
|
||||
RoleEntity editorRole = _roleEntityFixture.Create(roleName: "Editor");
|
||||
dbContext.Roles.Add(editorRole);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// get the admin user that was created by CreateAuthenticatedAdminClientAsync
|
||||
// Get the admin user that was created by CreateAuthenticatedAdminClientAsync.
|
||||
UserEntity? adminUser = dbContext.Users.FirstOrDefault(u => u.UserRole!.Role.RoleName == "Admin");
|
||||
Assert.NotNull(adminUser);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||
@@ -229,11 +229,11 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// clear junction tables first
|
||||
// Clear junction tables first.
|
||||
await dbContext.Set<RolePermissionEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<UserPermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
// then clear main tables
|
||||
// Then clear main tables.
|
||||
await dbContext.Set<UserEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<RoleEntity>().ExecuteDeleteAsync();
|
||||
await dbContext.Set<PermissionEntity>().ExecuteDeleteAsync();
|
||||
|
||||
+2
-2
@@ -155,8 +155,8 @@ public class UpdatePlaybackStateEndpointTests : IClassFixture<AuthenticatedLumin
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(1.01)] // just above the maximum
|
||||
[InlineData(-0.01)] // Just below the minimum.
|
||||
[InlineData(1.01)] // Just above the maximum.
|
||||
public async Task UpdatePlaybackState_WhenVolumeIsOutOfRange_ShouldReturnValidationError(double volume)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
+16
-16
@@ -273,8 +273,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // below the minimum
|
||||
[InlineData(129)] // above the maximum
|
||||
[InlineData(0)] // Below the minimum.
|
||||
[InlineData(129)] // Above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterSegmentCountIsOutOfRange_ShouldReturnValidationError(int vuMeterSegmentCount)
|
||||
{
|
||||
// Arrange
|
||||
@@ -288,8 +288,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // below the minimum
|
||||
[InlineData(33)] // above the maximum
|
||||
[InlineData(-1)] // Below the minimum.
|
||||
[InlineData(33)] // Above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterSegmentGapIsOutOfRange_ShouldReturnValidationError(int vuMeterSegmentGap)
|
||||
{
|
||||
// Arrange
|
||||
@@ -303,8 +303,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(1.01)] // just above the maximum
|
||||
[InlineData(-0.01)] // Just below the minimum.
|
||||
[InlineData(1.01)] // Just above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterMediumThresholdIsOutOfRange_ShouldReturnValidationError(double vuMeterMediumThreshold)
|
||||
{
|
||||
// Arrange
|
||||
@@ -320,8 +320,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(1.01)] // just above the maximum
|
||||
[InlineData(-0.01)] // Just below the minimum.
|
||||
[InlineData(1.01)] // Just above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsOutOfRange_ShouldReturnValidationError(double vuMeterHighThreshold)
|
||||
{
|
||||
// Arrange
|
||||
@@ -352,8 +352,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0.5, 0.5)] // the thresholds are equal
|
||||
[InlineData(0.4, 0.9)] // the high threshold is greater than the medium one
|
||||
[InlineData(0.5, 0.5)] // The thresholds are equal.
|
||||
[InlineData(0.4, 0.9)] // The high threshold is greater than the medium one.
|
||||
public async Task UpdateUserSettings_WhenVuMeterHighThresholdIsGreaterThanOrEqualToMediumThreshold_ShouldUpdateSettings(
|
||||
double vuMeterMediumThreshold,
|
||||
double vuMeterHighThreshold)
|
||||
@@ -372,8 +372,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // below the minimum
|
||||
[InlineData(10001)] // above the maximum
|
||||
[InlineData(-1)] // Below the minimum.
|
||||
[InlineData(10001)] // Above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterPeakHoldDurationIsOutOfRange_ShouldReturnValidationError(int vuMeterPeakHoldDurationInMilliseconds)
|
||||
{
|
||||
// Arrange
|
||||
@@ -388,8 +388,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(100.01)] // just above the maximum
|
||||
[InlineData(-0.01)] // Just below the minimum.
|
||||
[InlineData(100.01)] // Just above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterReleasePerSecondIsOutOfRange_ShouldReturnValidationError(double vuMeterReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
@@ -403,8 +403,8 @@ public class UpdateUserSettingsEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-0.01)] // just below the minimum
|
||||
[InlineData(100.01)] // just above the maximum
|
||||
[InlineData(-0.01)] // Just below the minimum.
|
||||
[InlineData(100.01)] // Just above the maximum.
|
||||
public async Task UpdateUserSettings_WhenVuMeterPeakReleasePerSecondIsOutOfRange_ShouldReturnValidationError(double vuMeterPeakReleasePerSecond)
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in new issue
Block a user