Merge pull request #113 from BinaryAlley/refactor/remove-fluent-assertions-library-in-test-projects

Removes FluentAssertions library from test projects, due to licensing…
This commit is contained in:
BinaryAlley authored and GitHub committed 2025-02-02 22:49:24 +00:00
commit fb400a699a
235 files changed
+4468 -4725

No files matched your search

+4 -5
View File
@@ -608,10 +608,9 @@ public void Add_WhenCalledWithTwoNumbers_ShouldReturnTheirSum()
3. **[AutoFixture.AutoNSubstitute](https://github.com/AutoFixture/AutoFixture/tree/master/Src/AutoNSubstitute)**
4. **[AutoFixture.Xunit2](https://github.com/AutoFixture/AutoFixture/tree/master/Src/AutoFixture.xUnit2)**
5. **[Bogus](https://github.com/bchavez/Bogus)**
6. **[FluentAssertions](https://github.com/fluentassertions/fluentassertions)**
7. **[Microsoft.EntityFrameworkCore.InMemory](https://github.com/dotnet/efcore/tree/main/src/EFCore.InMemory)**
8. **[Microsoft.Extensions.DependencyInjection](https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyInjection)**
9. **[EntityFrameworkCore.Testing.NSubstitute](https://github.com/rgvlee/EntityFrameworkCore.Testing)**
6. **[Microsoft.EntityFrameworkCore.InMemory](https://github.com/dotnet/efcore/tree/main/src/EFCore.InMemory)**
7. **[Microsoft.Extensions.DependencyInjection](https://github.com/dotnet/runtime/tree/main/src/libraries/Microsoft.Extensions.DependencyInjection)**
8. **[EntityFrameworkCore.Testing.NSubstitute](https://github.com/rgvlee/EntityFrameworkCore.Testing)**
### Types of Tests
#### Unit Tests
@@ -638,7 +637,7 @@ public void CreateRepository_WhenUnregisteredTypeRequested_ShouldThrowException(
- Group fixtures in directories called `Fixture` for each class of tests
### Assertions
- Use specific assertions rather than general ones (e.g., Assert.Equal instead of Assert.True)
- Use fluent style of assertions
- Do not use fluent style of assertions, use default xUnit assertions
### Test Data
- Use meaningful test data that covers various scenarios. For parameterized tests, use a variety of inputs:
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.Authorization;
@@ -12,7 +11,6 @@ using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
@@ -63,18 +61,18 @@ public class GetPermissionsEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PermissionResponse>? result = JsonSerializer.Deserialize<IEnumerable<PermissionResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result.Should().NotBeEmpty();
result!.Should().AllSatisfy(permission =>
Assert.NotNull(result);
Assert.NotEmpty(result);
foreach (PermissionResponse permission in result!)
{
permission.Id.Should().NotBe(Guid.Empty);
permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
});
Assert.NotEqual(Guid.Empty, permission.Id);
Assert.NotEqual(AuthorizationPermission.None, permission.PermissionName);
}
}
[Fact]
@@ -85,18 +83,19 @@ public class GetPermissionsEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -105,15 +104,12 @@ public class GetPermissionsEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel();
await _client.GetAsync("/api/v1/auth/permissions", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.DTO.Authentication;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.DataAccess.Core.UoW;
@@ -75,19 +75,19 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RolePermissionsResponse? result = JsonSerializer.Deserialize<RolePermissionsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Role.RoleName.Should().Be("Editor");
result.Permissions.Should().HaveCount(2);
result.Permissions.Should().AllSatisfy(permission =>
Assert.NotNull(result);
Assert.Equal("Editor", result!.Role.RoleName);
Assert.Equal(2, result.Permissions.Length);
foreach (PermissionDto permission in result.Permissions)
{
permission.Id.Should().NotBe(Guid.Empty);
permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
});
Assert.NotEqual(Guid.Empty, permission.Id);
Assert.NotEqual(AuthorizationPermission.None, permission.PermissionName);
}
}
[Fact]
@@ -104,17 +104,18 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/roles", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/roles");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -130,17 +131,18 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/roles", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status409Conflict);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.10");
problemDetails["title"].GetString().Should().Be("General.Conflict");
problemDetails["detail"].GetString().Should().Be("RoleAlreadyExists");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/roles");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status409Conflict, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.10", problemDetails["type"].GetString());
Assert.Equal("General.Conflict", problemDetails["title"].GetString());
Assert.Equal("RoleAlreadyExists", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -153,15 +155,12 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
Permissions: [Guid.NewGuid()]
);
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel();
await _client.PostAsJsonAsync("/api/v1/auth/roles", request, cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.DataAccess.Core.UoW;
@@ -75,11 +74,11 @@ public class DeleteRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/auth/roles/{role.Id}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
// Verify role was deleted
// verify role was deleted
RoleEntity? deletedRole = await dbContext.Roles.FirstOrDefaultAsync(r => r.Id == role.Id);
deletedRole.Should().BeNull();
Assert.Null(deletedRole);
}
[Fact]
@@ -93,17 +92,18 @@ public class DeleteRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/auth/roles/{roleId}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/roles/{roleId}");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/roles/{roleId}", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -113,23 +113,24 @@ public class DeleteRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
RoleEntity? adminRole = dbContext.Roles.FirstOrDefault(r => r.RoleName == "Admin");
adminRole.Should().NotBeNull("Admin role should exist");
Assert.NotNull(adminRole);
// Act
HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/auth/roles/{adminRole!.Id}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Forbidden");
problemDetails["detail"].GetString().Should().Be("AdminRoleCannotBeDeleted");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/roles/{adminRole!.Id}");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Forbidden", problemDetails["title"].GetString());
Assert.Equal("AdminRoleCannotBeDeleted", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/roles/{adminRole!.Id}", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -142,17 +143,18 @@ public class DeleteRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
HttpResponseMessage response = await _client.DeleteAsync($"/api/v1/auth/roles/{nonExistentRoleId}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("RoleNotFound");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/roles/{nonExistentRoleId}");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("RoleNotFound", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/roles/{nonExistentRoleId}", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -162,15 +164,13 @@ public class DeleteRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
using CancellationTokenSource cts = new();
Guid roleId = Guid.NewGuid();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.DeleteAsync($"/api/v1/auth/roles/{roleId}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.DTO.Authentication;
using Lumina.Contracts.Responses.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Enums.Authorization;
@@ -62,27 +62,27 @@ public class GetRolePermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
RoleEntity? role = dbContext.Roles.FirstOrDefault();
role.Should().NotBeNull("Admin role should exist");
Assert.NotNull(role);
// Act
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/roles/{role!.Id}/permissions");
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RolePermissionsResponse? result = JsonSerializer.Deserialize<RolePermissionsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Role.Id.Should().Be(role.Id);
result.Role.RoleName.Should().Be("Admin");
result.Permissions.Should().NotBeEmpty();
result.Permissions.Should().AllSatisfy(permission =>
Assert.NotNull(result);
Assert.Equal(role.Id, result!.Role.Id);
Assert.Equal("Admin", result.Role.RoleName);
Assert.NotEmpty(result.Permissions);
foreach (PermissionDto permission in result.Permissions)
{
permission.Id.Should().NotBe(Guid.Empty);
permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
});
Assert.NotEqual(Guid.Empty, permission.Id);
Assert.NotEqual(AuthorizationPermission.None, permission.PermissionName);
}
}
[Fact]
@@ -93,23 +93,24 @@ public class GetRolePermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
RoleEntity? role = dbContext.Roles.FirstOrDefault();
role.Should().NotBeNull("Admin role should exist");
Assert.NotNull(role);
// Act
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/roles/{role!.Id}/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/roles/{role.Id}/permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/roles/{role.Id}/permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -120,17 +121,18 @@ public class GetRolePermissionsEndpointTests : IClassFixture<AuthenticatedLumina
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/roles/{invalidRoleId}/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("RoleNotFound");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/roles/{invalidRoleId}/permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("RoleNotFound", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/roles/{invalidRoleId}/permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -141,17 +143,14 @@ public class GetRolePermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
RoleEntity? role = dbContext.Roles.FirstOrDefault();
role.Should().NotBeNull("Admin role should exist");
Assert.NotNull(role);
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel();
await _client.GetAsync($"/api/v1/auth/roles/{role!.Id}/permissions", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.Authorization;
@@ -61,14 +60,14 @@ public class GetRolesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<RoleResponse>? result = JsonSerializer.Deserialize<IEnumerable<RoleResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result.Should().NotBeEmpty();
result!.Should().Contain(role =>
Assert.NotNull(result);
Assert.NotEmpty(result);
Assert.Contains(result, role =>
role.Id != Guid.Empty &&
role.RoleName == "Admin"
);
@@ -84,17 +83,18 @@ public class GetRolesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/roles");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/roles");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -103,15 +103,12 @@ public class GetRolesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel();
await _client.GetAsync("/api/v1/auth/roles", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.DTO.Authentication;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.DataAccess.Core.UoW;
@@ -86,20 +86,20 @@ public class UpdateRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RolePermissionsResponse? result = JsonSerializer.Deserialize<RolePermissionsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Role.Id.Should().Be(role.Id);
result.Role.RoleName.Should().Be("UpdatedRole");
result.Permissions.Should().HaveCount(2);
result.Permissions.Should().AllSatisfy(permission =>
Assert.NotNull(result);
Assert.Equal(role.Id, result!.Role.Id);
Assert.Equal("UpdatedRole", result.Role.RoleName);
Assert.Equal(2, result.Permissions.Length);
foreach (PermissionDto permission in result.Permissions)
{
permission.Id.Should().NotBe(Guid.Empty);
permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
});
Assert.NotEqual(Guid.Empty, permission.Id);
Assert.NotEqual(AuthorizationPermission.None, permission.PermissionName);
}
}
[Fact]
@@ -117,17 +117,18 @@ public class UpdateRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/auth/roles", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/roles");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -145,17 +146,18 @@ public class UpdateRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/auth/roles", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("RoleNotFound");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/roles");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("RoleNotFound", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -169,15 +171,12 @@ public class UpdateRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
Permissions: [Guid.NewGuid()]
);
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel();
await _client.PutAsJsonAsync($"/api/v1/auth/roles", request, cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -71,12 +70,12 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
string content = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
List<DirectoryResponse>? directories = JsonSerializer.Deserialize<List<DirectoryResponse>>(content, _jsonOptions);
directories.Should().NotBeNull();
directories!.Should().BeEmpty();
Assert.NotNull(directories);
Assert.Empty(directories);
}
finally
{
@@ -101,21 +100,21 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<DirectoryResponse>? directories = JsonSerializer.Deserialize<List<DirectoryResponse>>(content, _jsonOptions);
directories.Should().NotBeNull();
directories!.Should().NotBeEmpty();
Assert.NotNull(directories);
Assert.NotNull(directories);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
DirectoryResponse firstDirectory = directories!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "NestedDirectory_2");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "NestedDirectory_2" + System.IO.Path.DirectorySeparatorChar));
directories!.Count.Should().Be(1); // only directories
Assert.Equal((s_isUnix ? "." : string.Empty) + "NestedDirectory_2", directories!.First().Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "NestedDirectory_2" + System.IO.Path.DirectorySeparatorChar), directories.First().Path);
Assert.Single(directories); // only directories
}
finally
{
@@ -135,17 +134,18 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/directories/get-directories");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/directories/get-directories", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -160,20 +160,23 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/directories/get-directories");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/directories/get-directories", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -185,11 +188,11 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -201,15 +204,12 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/directories/get-directories?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
@@ -67,18 +66,18 @@ public class GetDrivesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? drives = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
drives.Should().NotBeNull();
drives.Should().NotBeEmpty();
Assert.NotNull(drives);
Assert.NotEmpty(drives);
FileSystemTreeNodeResponse firstDrive = drives!.First();
firstDrive.Name.Should().Be(s_isUnix ? "/" : "C:\\");
firstDrive.Path.Should().Be(s_isUnix ? "/" : "C:\\");
firstDrive.ItemType.Should().Be(FileSystemItemType.Root);
drives!.Count.Should().BeGreaterThanOrEqualTo(1);
Assert.Equal(s_isUnix ? "/" : "C:\\", firstDrive.Name);
Assert.Equal(s_isUnix ? "/" : "C:\\", firstDrive.Path);
Assert.Equal(FileSystemItemType.Root, firstDrive.ItemType);
Assert.True(drives.Count >= 1);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
using System.Diagnostics.CodeAnalysis;
@@ -55,11 +54,11 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/file-system/get-type");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
FileSystemTypeResponse? result = JsonSerializer.Deserialize<FileSystemTypeResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.PlatformType.Should().BeOneOf(PlatformType.Unix, PlatformType.Windows);
Assert.NotNull(result);
Assert.True(result!.PlatformType == PlatformType.Unix || result.PlatformType == PlatformType.Windows);
}
[Fact]
@@ -70,8 +69,8 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response2 = await _client.GetAsync("/api/v1/file-system/get-type");
// Assert
response1.StatusCode.Should().Be(HttpStatusCode.OK);
response2.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response1.StatusCode);
Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
string content1 = await response1.Content.ReadAsStringAsync();
string content2 = await response2.Content.ReadAsStringAsync();
@@ -79,9 +78,9 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
FileSystemTypeResponse? result1 = JsonSerializer.Deserialize<FileSystemTypeResponse>(content1, _jsonOptions);
FileSystemTypeResponse? result2 = JsonSerializer.Deserialize<FileSystemTypeResponse>(content2, _jsonOptions);
result1.Should().NotBeNull();
result2.Should().NotBeNull();
result1.Should().BeEquivalentTo(result2);
Assert.NotNull(result1);
Assert.NotNull(result2);
Assert.Equal(result1.PlatformType, result2.PlatformType);
}
[Fact]
@@ -90,11 +89,11 @@ public class GetTypeEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// Arrange
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync("/api/v1/file-system/get-type", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync("/api/v1/file-system/get-type", cts.Token)
);
Assert.Null(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -68,21 +67,21 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(1); // only files
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
}
finally
{
@@ -106,15 +105,15 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
Assert.NotNull(files);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
}
finally
{
@@ -138,23 +137,24 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileResponse>? files = JsonSerializer.Deserialize<List<FileResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "TestFile_1.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"));
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
FileResponse secondDirectory = files!.Last();
secondDirectory.Name.Should().Be("TestFile_2.txt");
secondDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(2);
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.Equal(2, files.Count);
}
finally
{
@@ -174,17 +174,18 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-files");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-files", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -199,20 +200,23 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-files");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-files", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -224,11 +228,11 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -240,15 +244,13 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/files/get-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
@@ -68,21 +67,21 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(1); // only files
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
}
finally
{
@@ -106,16 +105,16 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
Assert.NotNull(files);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be("TestFile_2.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
}
finally
{
@@ -139,23 +138,24 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
List<FileSystemTreeNodeResponse>? files = JsonSerializer.Deserialize<List<FileSystemTreeNodeResponse>>(content, _jsonOptions);
files.Should().NotBeNull();
files!.Should().NotBeEmpty();
Assert.NotNull(files);
Assert.NotEmpty(files);
string[] pathSegments = testPath.Split(System.IO.Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries);
FileSystemTreeNodeResponse firstDirectory = files!.First();
firstDirectory.Name.Should().Be((s_isUnix ? "." : string.Empty) + "TestFile_1.txt");
firstDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"));
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
FileSystemTreeNodeResponse secondDirectory = files!.Last();
secondDirectory.Name.Should().Be("TestFile_2.txt");
secondDirectory.Path.Should().Be(System.IO.Path.Combine(testPath, "TestFile_2.txt"));
files!.Count.Should().Be(2);
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.Equal(2, files.Count);
}
finally
{
@@ -174,17 +174,18 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-tree-files");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-tree-files", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -199,20 +200,23 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/files/get-tree-files");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-tree-files", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -224,11 +228,11 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
bool includeHiddenElements = true;
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -240,15 +244,13 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
bool includeHiddenElements = true;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/files/get-tree-files?path={encodedPath}&includeHiddenElements={includeHiddenElements}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -59,11 +58,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(tempPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.Exists);
}
[Fact]
@@ -76,11 +75,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(nonExistingPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.Exists);
}
[Fact]
@@ -93,20 +92,22 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(path)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/check-path-exists");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/check-path-exists", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -119,11 +120,11 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/check-path-exists?path={Uri.EscapeDataString(invalidPath)}&includeHiddenElements=false");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathExistsResponse? result = JsonSerializer.Deserialize<PathExistsResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Exists.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.Exists);
}
[Fact]
@@ -134,15 +135,13 @@ public class CheckPathExistsEndpointTests : IClassFixture<AuthenticatedLuminaApi
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/check-path-exists?path={encodedPath}&includeHiddenElements=false", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -63,11 +62,11 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSegmentResponse? result = JsonSerializer.Deserialize<PathSegmentResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Path.Should().Be(expectedPath);
Assert.NotNull(result);
Assert.Equal(expectedPath, result!.Path);
}
[Fact]
@@ -81,20 +80,23 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/combine");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/combine", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -105,11 +107,11 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string newPath = "documents";
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -120,15 +122,13 @@ public class CombinePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string newPath = "testFile.txt";
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/combine?originalPath={Uri.EscapeDataString(originalPath)}&newPath={Uri.EscapeDataString(newPath)}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -63,11 +62,11 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PathSegmentResponse>? result = JsonSerializer.Deserialize<IEnumerable<PathSegmentResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Should().NotBeEmpty();
Assert.NotNull(result);
Assert.NotEmpty(result);
List<string> hierarchy = [];
string path = System.IO.Path.GetDirectoryName(testPath)!;
@@ -84,7 +83,7 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
}
hierarchy.Reverse();
result!.Select(r => r.Path).Should().BeEquivalentTo(hierarchy, options => options.WithStrictOrdering());
Assert.Equal(hierarchy, result.Select(r => r.Path));
}
[Fact]
@@ -98,17 +97,18 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("CannotNavigateUp");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("CannotNavigateUp", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -122,20 +122,22 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -149,20 +151,23 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -173,11 +178,11 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -188,15 +193,13 @@ public class GetPathParentEndpointTests : IClassFixture<AuthenticatedLuminaApiFa
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/get-path-parent?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -8,7 +7,6 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
@@ -61,11 +59,12 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSegmentResponse? result = JsonSerializer.Deserialize<PathSegmentResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Path.Should().NotBeNullOrEmpty();
Assert.NotNull(result);
Assert.NotNull(result!.Path);
Assert.NotEmpty(result.Path);
}
[Fact]
@@ -79,20 +78,23 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-root");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-root", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -106,20 +108,23 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/get-path-root");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-root", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -130,11 +135,11 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -145,15 +150,13 @@ public class GetPathRootEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/get-path-root?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
@@ -54,11 +53,11 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-separator");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathSeparatorResponse? result = JsonSerializer.Deserialize<PathSeparatorResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Separator.Should().BeOneOf("/", "\\");
Assert.NotNull(result);
Assert.True(result!.Separator == "/" || result.Separator == "\\");
}
[Fact]
@@ -69,8 +68,8 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response2 = await _client.GetAsync("/api/v1/path/get-path-separator");
// Assert
response1.StatusCode.Should().Be(HttpStatusCode.OK);
response2.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response1.StatusCode);
Assert.Equal(HttpStatusCode.OK, response2.StatusCode);
string content1 = await response1.Content.ReadAsStringAsync();
string content2 = await response2.Content.ReadAsStringAsync();
@@ -78,9 +77,9 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
PathSeparatorResponse? result1 = JsonSerializer.Deserialize<PathSeparatorResponse>(content1, _jsonOptions);
PathSeparatorResponse? result2 = JsonSerializer.Deserialize<PathSeparatorResponse>(content2, _jsonOptions);
result1.Should().NotBeNull();
result2.Should().NotBeNull();
result1.Should().BeEquivalentTo(result2);
Assert.NotNull(result1);
Assert.NotNull(result2);
Assert.Equal(result1, result2);
}
[Fact]
@@ -89,11 +88,11 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
// Arrange
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -102,15 +101,13 @@ public class GetPathSeparatorEndpointTests : IClassFixture<AuthenticatedLuminaAp
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync("/api/v1/path/get-path-separator", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -61,12 +60,15 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(testPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PathSegmentResponse>? result = JsonSerializer.Deserialize<IEnumerable<PathSegmentResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Should().HaveCountGreaterThanOrEqualTo(3);
result!.Select(r => r.Path).Should().Contain(["testFolder", "testFile.txt"]);
Assert.NotNull(result);
Assert.True(result!.Count() >= 3);
IEnumerable<string> paths = result.Select(r => r.Path);
Assert.Contains("testFolder", paths);
Assert.Contains("testFile.txt", paths);
}
[Fact]
@@ -79,20 +81,23 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/split");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/split", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -105,20 +110,23 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/split?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/path/split");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/split", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["InvalidPath"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidPath", errors["General.Validation"]);
}
[Fact]
@@ -129,15 +137,13 @@ public class SplitPathEndpointTests : IClassFixture<AuthenticatedLuminaApiFactor
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/split?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using System;
@@ -58,11 +57,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(testPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.IsValid);
}
[Fact]
@@ -75,11 +74,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(invalidPath)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.IsValid);
}
[Fact]
@@ -92,11 +91,11 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/path/validate?path={Uri.EscapeDataString(path)}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
PathValidResponse? result = JsonSerializer.Deserialize<PathValidResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsValid.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.IsValid);
}
[Fact]
@@ -107,15 +106,13 @@ public class ValidatePathEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
string encodedPath = Uri.EscapeDataString(testPath);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/path/validate?path={encodedPath}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Microsoft.AspNetCore.Http;
@@ -62,10 +61,10 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
response.Content.Headers.ContentType!.MediaType.Should().Be("image/jpeg");
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("image/jpeg", response.Content.Headers.ContentType!.MediaType);
byte[] content = await response.Content.ReadAsByteArrayAsync();
content.Should().NotBeEmpty();
Assert.NotEmpty(content);
}
[Fact]
@@ -79,17 +78,18 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(invalidImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("UnauthorizedAccess");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("UnauthorizedAccess", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -103,20 +103,23 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(invalidImagePath)}&quality={quality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["PathCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PathCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -129,20 +132,23 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
HttpResponseMessage response = await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={invalidQuality}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().BeEquivalentTo(["ImageQualityMustBeBetweenZeroAndOneHundred"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("ImageQualityMustBeBetweenZeroAndOneHundred", errors["General.Validation"]);
}
[Fact]
@@ -152,15 +158,13 @@ public class GetThumbnailEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
int quality = 80;
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/thumbnails/get-thumbnail?path={Uri.EscapeDataString(_testImagePath)}&quality={quality}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,15 +1,12 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement;
using Lumina.DataAccess.Core.UoW;
using Lumina.Infrastructure.Core.Security;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
@@ -63,13 +60,13 @@ public class CheckInitializationEndpointTests : IClassFixture<AuthenticatedLumin
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
InitializationResponse? result = JsonSerializer.Deserialize<InitializationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsInitialized.Should().BeFalse();
Assert.NotNull(result);
Assert.False(result!.IsInitialized);
}
[Fact]
@@ -83,13 +80,13 @@ public class CheckInitializationEndpointTests : IClassFixture<AuthenticatedLumin
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
InitializationResponse? result = JsonSerializer.Deserialize<InitializationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsInitialized.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.IsInitialized);
}
[Fact]
@@ -98,15 +95,13 @@ public class CheckInitializationEndpointTests : IClassFixture<AuthenticatedLumin
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.GetAsync("/api/v1/initialization", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
private async Task<UserEntity> CreateTestUser()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
@@ -76,18 +75,19 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/initialization", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RegistrationResponse? result = JsonSerializer.Deserialize<RegistrationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(_testUsername);
result.Id.Should().NotBe(Guid.Empty);
result.TotpSecret.Should().NotBeNullOrEmpty();
result.TotpSecret.Should().StartWith("data:image/png;base64,");
Assert.NotNull(result);
Assert.Equal(_testUsername, result!.Username);
Assert.NotEqual(Guid.Empty, result.Id);
Assert.NotNull(result.TotpSecret);
Assert.NotEmpty(result.TotpSecret);
Assert.StartsWith("data:image/png;base64,", result.TotpSecret);
response.Headers.Location.Should().NotBeNull();
response.Headers.Location!.ToString().Should().Be($"http://localhost/api/v1/users/{result.Id}");
Assert.NotNull(response.Headers.Location);
Assert.Equal($"http://localhost/api/v1/users/{result.Id}", response.Headers.Location.ToString());
// verify default permissions, roles, and role permissions are set
await VerifyDefaultSetup(result.Id);
@@ -109,17 +109,17 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/initialization", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RegistrationResponse? result = JsonSerializer.Deserialize<RegistrationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(_testUsername);
result.Id.Should().NotBe(Guid.Empty);
result.TotpSecret.Should().BeNull();
Assert.NotNull(result);
Assert.Equal(_testUsername, result!.Username);
Assert.NotEqual(Guid.Empty, result.Id);
Assert.Null(result.TotpSecret);
response.Headers.Location.Should().NotBeNull();
response.Headers.Location!.ToString().Should().Be($"http://localhost/api/v1/users/{result.Id}");
Assert.NotNull(response.Headers.Location);
Assert.Equal($"http://localhost/api/v1/users/{result.Id}", response.Headers.Location.ToString());
// verify default permissions, roles, and role permissions are set
await VerifyDefaultSetup(result.Id);
@@ -141,17 +141,18 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/initialization", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status409Conflict);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.10");
problemDetails["title"].GetString().Should().Be("General.Conflict");
problemDetails["detail"].GetString().Should().Be("AdminAccountAlreadyCreated");
problemDetails["instance"].GetString().Should().Be("/api/v1/initialization");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status409Conflict, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.10", problemDetails["type"].GetString());
Assert.Equal("General.Conflict", problemDetails["title"].GetString());
Assert.Equal("AdminAccountAlreadyCreated", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/initialization", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -164,14 +165,17 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/initialization", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
Assert.NotNull(problemDetails);
Dictionary<string, string[]>? errors = problemDetails!["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation")
.WhoseValue.Should().Contain(["UsernameCannotBeEmpty", "PasswordCannotBeEmpty", "PasswordConfirmCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("UsernameCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("PasswordCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("PasswordConfirmCannotBeEmpty", errors["General.Validation"]);
}
private async Task VerifyDefaultSetup(Guid userId)
@@ -182,25 +186,25 @@ public class SetupApplicationEndpointTests : IClassFixture<AuthenticatedLuminaAp
// TODO: update list when defaults change
// verify default permissions
List<PermissionEntity> permissions = await dbContext.Permissions.ToListAsync();
permissions.Should().Contain(p => p.PermissionName == AuthorizationPermission.CanViewUsers);
permissions.Should().Contain(p => p.PermissionName == AuthorizationPermission.CanDeleteUsers);
permissions.Should().Contain(p => p.PermissionName == AuthorizationPermission.CanRegisterUsers);
Assert.Contains(permissions, p => p.PermissionName == AuthorizationPermission.CanViewUsers);
Assert.Contains(permissions, p => p.PermissionName == AuthorizationPermission.CanDeleteUsers);
Assert.Contains(permissions, p => p.PermissionName == AuthorizationPermission.CanRegisterUsers);
// verify default roles
List<RoleEntity> roles = await dbContext.Roles.ToListAsync();
RoleEntity? adminRole = roles.FirstOrDefault(r => r.RoleName == "Admin");
adminRole.Should().NotBeNull();
Assert.NotNull(adminRole);
// verify admin role permissions
List<RolePermissionEntity> rolePermissions = await dbContext.RolePermissions
.Where(rp => rp.RoleId == adminRole!.Id)
.ToListAsync();
rolePermissions.Should().NotBeEmpty();
rolePermissions.Should().Contain(rp => permissions.Any(p => p.Id == rp.PermissionId));
Assert.NotEmpty(rolePermissions);
Assert.Contains(rolePermissions, rp => permissions.Any(p => p.Id == rp.PermissionId));
// verify user has admin role
UserRoleEntity? userRole = await dbContext.UserRoles.FirstOrDefaultAsync(ur => ur.UserId == userId && ur.RoleId == adminRole!.Id);
userRole.Should().NotBeNull();
Assert.NotNull(userRole);
}
private async Task<UserEntity> CreateTestUser()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
@@ -71,12 +70,12 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Assert
string content = await response.Content.ReadAsStringAsync();
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
ChangePasswordResponse? result = JsonSerializer.Deserialize<ChangePasswordResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsPasswordChanged.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.IsPasswordChanged);
}
[Fact]
@@ -94,20 +93,23 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/change-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/change-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain("PasswordsNotMatch");
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PasswordsNotMatch", errors["General.Validation"]);
}
[Fact]
@@ -125,17 +127,18 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("UsernameDoesNotExist");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/change-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("UsernameDoesNotExist", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/change-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -153,17 +156,18 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["detail"].GetString().Should().Be("InvalidCurrentPassword");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/change-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("InvalidCurrentPassword", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/change-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -176,20 +180,26 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/change-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/change-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["UsernameCannotBeEmpty", "CurrentPasswordCannotBeEmpty", "NewPasswordCannotBeEmpty", "NewPasswordConfirmCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("UsernameCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("CurrentPasswordCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("NewPasswordCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("NewPasswordConfirmCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -204,15 +214,13 @@ public class ChangePasswordEndpointTests : IClassFixture<AuthenticatedLuminaApiF
);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.PostAsJsonAsync("/api/v1/auth/change-password", request, cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement.Users;
@@ -61,19 +60,20 @@ public class GetUsersEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<UserResponse>? result = JsonSerializer.Deserialize<IEnumerable<UserResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result.Should().NotBeEmpty();
result!.Should().AllSatisfy(user =>
Assert.NotNull(result);
Assert.NotEmpty(result);
foreach (UserResponse user in result!)
{
user.Id.Should().NotBe(Guid.Empty);
user.Username.Should().NotBeNullOrEmpty();
user.CreatedOnUtc.Should().NotBe(default);
});
Assert.NotEqual(Guid.Empty, user.Id);
Assert.NotNull(user.Username);
Assert.NotEmpty(user.Username);
Assert.NotEqual(default, user.CreatedOnUtc);
}
}
[Fact]
@@ -86,17 +86,18 @@ public class GetUsersEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/users");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/users");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/users", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -105,15 +106,13 @@ public class GetUsersEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.GetAsync("/api/v1/auth/users", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.Infrastructure.Security;
using Lumina.Contracts.Requests.Authentication;
@@ -83,15 +82,16 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
LoginResponse? result = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(user.Username);
result.UsesTotp.Should().BeFalse();
result.Token.Should().NotBeNullOrEmpty();
Assert.NotNull(result);
Assert.Equal(user.Username, result!.Username);
Assert.False(result.UsesTotp);
Assert.NotNull(result.Token);
Assert.NotEmpty(result.Token);
}
[Fact]
@@ -114,15 +114,16 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
LoginResponse? result = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(user.Username);
result.UsesTotp.Should().BeTrue();
result.Token.Should().NotBeNullOrEmpty();
Assert.NotNull(result);
Assert.Equal(user.Username, result!.Username);
Assert.True(result.UsesTotp);
Assert.NotNull(result.Token);
Assert.NotEmpty(result.Token);
}
[Fact]
@@ -140,14 +141,15 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
LoginResponse? result = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(user.Username);
result.Token.Should().NotBeNullOrEmpty();
Assert.NotNull(result);
Assert.Equal(user.Username, result!.Username);
Assert.NotNull(result.Token);
Assert.NotEmpty(result.Token);
}
[Fact]
@@ -164,17 +166,18 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/login", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["detail"].GetString().Should().Be("TempPasswordExpired");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/login");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("TempPasswordExpired", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/login", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -191,17 +194,18 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/login", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Failure");
problemDetails["detail"].GetString().Should().Be("InvalidUsernameOrPassword");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/login");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Failure", problemDetails["title"].GetString());
Assert.Equal("InvalidUsernameOrPassword", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/login", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -219,20 +223,23 @@ public class LoginEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>,
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/login", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/login");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/login", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["InvalidTotpCode"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidTotpCode", errors["General.Validation"]);
}
private async Task<UserEntity> CreateTestUser()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.Infrastructure.Security;
using Lumina.Contracts.Requests.Authentication;
@@ -92,13 +91,13 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RecoverPasswordResponse? result = JsonSerializer.Deserialize<RecoverPasswordResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.IsPasswordReset.Should().BeTrue();
Assert.NotNull(result);
Assert.True(result!.IsPasswordReset);
// Create a new context to get fresh data
using IServiceScope verificationScope = _apiFactory.Services.CreateScope();
@@ -110,9 +109,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
.AsNoTracking()
.FirstOrDefaultAsync(u => u.Username == user.Username);
updatedUser.Should().NotBeNull();
updatedUser!.TempPassword.Should().NotBeNull();
updatedUser.TempPasswordCreated.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(5));
Assert.NotNull(updatedUser);
Assert.NotNull(updatedUser!.TempPassword);
Assert.True(Math.Abs((updatedUser.TempPasswordCreated - DateTime.UtcNow)!.Value.TotalSeconds) < 5);
}
[Fact]
@@ -128,17 +127,18 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("UsernameDoesNotExist");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/recover-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("UsernameDoesNotExist", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/recover-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -155,20 +155,23 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/recover-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/recover-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["InvalidTotpCode"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidTotpCode", errors["General.Validation"]);
}
[Fact]
@@ -181,20 +184,24 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/recover-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/recover-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["UsernameCannotBeEmpty", "TotpCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("UsernameCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("TotpCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -212,20 +219,23 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/recover-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/recover-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["InvalidTotpCode"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("InvalidTotpCode", errors["General.Validation"]);
}
[Fact]
@@ -260,20 +270,23 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/recover-password");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/recover-password", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(["TotpCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("TotpCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -286,15 +299,13 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
);
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request, cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
private async Task<UserEntity> CreateUserWithTotp()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
@@ -72,17 +71,17 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RegistrationResponse? result = JsonSerializer.Deserialize<RegistrationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(_testUsername);
result.Id.Should().NotBe(Guid.Empty);
result.TotpSecret.Should().BeNull();
Assert.NotNull(result);
Assert.Equal(_testUsername, result!.Username);
Assert.NotEqual(Guid.Empty, result.Id);
Assert.Null(result.TotpSecret);
response.Headers.Location.Should().NotBeNull();
response.Headers.Location!.ToString().Should().Be($"http://localhost/api/v1/users/{result.Id}");
Assert.NotNull(response.Headers.Location);
Assert.Equal($"http://localhost/api/v1/users/{result.Id}", response.Headers.Location.ToString());
}
[Fact]
@@ -100,15 +99,16 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RegistrationResponse? result = JsonSerializer.Deserialize<RegistrationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Username.Should().Be(_testUsername);
result.Id.Should().NotBe(Guid.Empty);
result.TotpSecret.Should().NotBeNullOrEmpty();
result.TotpSecret.Should().StartWith("data:image/png;base64,");
Assert.NotNull(result);
Assert.Equal(_testUsername, result!.Username);
Assert.NotEqual(Guid.Empty, result.Id);
Assert.NotNull(result.TotpSecret);
Assert.NotEmpty(result.TotpSecret);
Assert.StartsWith("data:image/png;base64,", result.TotpSecret);
}
[Fact]
@@ -127,14 +127,14 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status409Conflict);
problemDetails["title"].GetString().Should().Be("General.Conflict");
problemDetails["detail"].GetString().Should().Be("UsernameAlreadyExists");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status409Conflict, problemDetails!["status"].GetInt32());
Assert.Equal("General.Conflict", problemDetails["title"].GetString());
Assert.Equal("UsernameAlreadyExists", problemDetails["detail"].GetString());
}
[Fact]
@@ -152,13 +152,15 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
Assert.NotNull(problemDetails);
Dictionary<string, string[]>? errors = problemDetails!["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain("PasswordsNotMatch");
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("PasswordsNotMatch", errors["General.Validation"]);
}
[Fact]
@@ -171,14 +173,17 @@ public class RegisterEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
Assert.NotNull(problemDetails);
Dictionary<string, string[]>? errors = problemDetails!["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation")
.WhoseValue.Should().Contain(["UsernameCannotBeEmpty", "PasswordCannotBeEmpty", "PasswordConfirmCannotBeEmpty"]);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("UsernameCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("PasswordCannotBeEmpty", errors["General.Validation"]);
Assert.Contains("PasswordConfirmCannotBeEmpty", errors["General.Validation"]);
}
private async Task<UserEntity> CreateTestUser()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authorization;
@@ -86,15 +85,15 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
AuthorizationResponse? result = JsonSerializer.Deserialize<AuthorizationResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.UserId.Should().Be(user.Id);
result.Role.Should().Contain("Admin");
result.Permissions.Should().Contain(AuthorizationPermission.CanViewUsers);
Assert.NotNull(result);
Assert.Equal(user.Id, result!.UserId);
Assert.Contains("Admin", result.Role);
Assert.Contains(AuthorizationPermission.CanViewUsers, result.Permissions);
}
[Fact]
@@ -107,17 +106,18 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/get-authorization?userId={request.UserId}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/get-authorization");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/get-authorization", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -130,20 +130,23 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/get-authorization?userId={request.UserId}");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["instance"].GetString().Should().Be("/api/v1/auth/get-authorization");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("/api/v1/auth/get-authorization", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain("UserIdCannotBeEmpty");
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.Contains("UserIdCannotBeEmpty", errors["General.Validation"]);
}
[Fact]
@@ -153,15 +156,13 @@ public class GetAuthorizationEndpointTests : IClassFixture<AuthenticatedLuminaAp
GetAuthorizationRequest request = new(Guid.NewGuid());
CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.GetAsync($"/api/v1/auth/get-authorization?userId={request.UserId}", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
private static async Task<UserEntity> AddRolesAndPermissionsToUser(UserEntity existingUser, LuminaDbContext dbContext)
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.Authorization;
@@ -62,7 +61,7 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Add a direct user permission
PermissionEntity permission = dbContext.Permissions.First();
@@ -83,18 +82,18 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
IEnumerable<PermissionResponse>? result = JsonSerializer.Deserialize<IEnumerable<PermissionResponse>>(content, _jsonOptions);
result.Should().NotBeNull();
result.Should().NotBeEmpty();
result!.Should().AllSatisfy(permission =>
Assert.NotNull(result);
Assert.NotEmpty(result);
foreach (PermissionResponse perm in result!)
{
permission.Id.Should().NotBe(Guid.Empty);
permission.PermissionName.Should().NotBe(AuthorizationPermission.None);
});
Assert.NotEqual(Guid.Empty, perm.Id);
Assert.NotEqual(AuthorizationPermission.None, perm.PermissionName);
}
}
[Fact]
@@ -105,23 +104,24 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Act
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/users/{user!.Id}/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{user.Id}/permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{user!.Id}/permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -134,17 +134,18 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/users/{nonExistentUserId}/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("UsernameDoesNotExist");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{nonExistentUserId}/permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("UsernameDoesNotExist", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{nonExistentUserId}/permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -155,17 +156,15 @@ public class GetUserPermissionsEndpointTests : IClassFixture<AuthenticatedLumina
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.GetAsync($"/api/v1/auth/users/{user!.Id}/permissions", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,10 +1,8 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Enums.Authorization;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@@ -62,21 +60,21 @@ public class GetUserRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Act
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/users/{user!.Id}/role");
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
RoleResponse? result = JsonSerializer.Deserialize<RoleResponse>(content, _jsonOptions);
result.Should().NotBeNull();
result!.Id.Should().NotBe(Guid.Empty);
result.RoleName.Should().Be("Admin");
Assert.NotNull(result);
Assert.NotEqual(Guid.Empty, result!.Id);
Assert.Equal("Admin", result.RoleName);
}
[Fact]
@@ -87,23 +85,24 @@ public class GetUserRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Act
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/users/{user!.Id}/role");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{user.Id}/role");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{user!.Id}/role", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -116,17 +115,18 @@ public class GetUserRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
HttpResponseMessage response = await _client.GetAsync($"/api/v1/auth/users/{nonExistentUserId}/role");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("UsernameDoesNotExist");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{nonExistentUserId}/role");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("UsernameDoesNotExist", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{nonExistentUserId}/role", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -137,17 +137,15 @@ public class GetUserRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
using IServiceScope scope = _apiFactory.Services.CreateScope();
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
UserEntity? user = dbContext.Users.FirstOrDefault();
user.Should().NotBeNull("Test user should exist");
Assert.NotNull(user);
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.GetAsync($"/api/v1/auth/users/{user!.Id}/role", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,11 +1,8 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.DataAccess.Core.UoW;
using Lumina.Domain.Common.Enums.Authorization;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@@ -104,15 +101,15 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
JsonNode? jsonNode = JsonNode.Parse(content);
jsonNode.Should().NotBeNull();
Guid.Parse(jsonNode!["userId"]!.ToString()).Should().Be(user.Id);
jsonNode["role"]!.ToString().Should().Be("Editor");
jsonNode["permissions"]!.AsArray().Count.Should().BeGreaterThan(0);
Assert.NotNull(jsonNode);
Assert.Equal(user.Id, Guid.Parse(jsonNode!["userId"]!.ToString()));
Assert.Equal("Editor", jsonNode["role"]!.ToString());
Assert.True(jsonNode["permissions"]!.AsArray().Count > 0);
}
@@ -131,17 +128,18 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/auth/users/{request.UserId}/role-and-permissions", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Unauthorized");
problemDetails["detail"].GetString().Should().Be("NotAuthorized");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{request.UserId}/role-and-permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Unauthorized", problemDetails["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{request.UserId}/role-and-permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -164,8 +162,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
// get the admin user that was created by CreateAuthenticatedAdminClientAsync
UserEntity? adminUser = dbContext.Users.FirstOrDefault(u => u.UserRole!.Role.RoleName == "Admin");
adminUser.Should().NotBeNull("Admin user should exist");
Assert.NotNull(adminUser);
UpdateUserRoleAndPermissionsRequest request = new(
UserId: adminUser!.Id,
RoleId: editorRole.Id,
@@ -176,17 +173,18 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/auth/users/{request.UserId}/role-and-permissions", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status403Forbidden);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.4");
problemDetails["title"].GetString().Should().Be("General.Forbidden");
problemDetails["detail"].GetString().Should().Be("CannotRemoveLastAdmin");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{request.UserId}/role-and-permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status403Forbidden, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.4", problemDetails["type"].GetString());
Assert.Equal("General.Forbidden", problemDetails["title"].GetString());
Assert.Equal("CannotRemoveLastAdmin", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{request.UserId}/role-and-permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -204,17 +202,18 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/auth/users/{nonExistentUserId}/role-and-permissions", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status404NotFound);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
problemDetails["title"].GetString().Should().Be("General.NotFound");
problemDetails["detail"].GetString().Should().Be("UserDoesNotExist");
problemDetails["instance"].GetString().Should().Be($"/api/v1/auth/users/{nonExistentUserId}/role-and-permissions");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status404NotFound, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc9110#section-15.5.5", problemDetails["type"].GetString());
Assert.Equal("General.NotFound", problemDetails["title"].GetString());
Assert.Equal("UserDoesNotExist", problemDetails["detail"].GetString());
Assert.Equal($"/api/v1/auth/users/{nonExistentUserId}/role-and-permissions", problemDetails["instance"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
}
[Fact]
@@ -228,15 +227,13 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<Authentic
Permissions: [Guid.NewGuid()]
);
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel();
await _client.PutAsJsonAsync($"/api/v1/auth/users/{request.UserId}/role-and-permissions", request, cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -1,6 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Presentation.Api.IntegrationTests.Common.Converters;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.WrittenContentLibrary.BookLibrary.Books.Fixtures;
using Microsoft.AspNetCore.Http;
@@ -14,11 +18,6 @@ using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Lumina.Domain.Common.Errors;
using Bogus;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Presentation.Api.IntegrationTests.Common.Converters;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
namespace Lumina.Presentation.Api.IntegrationTests.Core.Endpoints.WrittenContentLibrary.BookLibrary.Books;
@@ -73,91 +72,97 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// Assert
response.EnsureSuccessStatusCode();
Book? bookResponse = await response.Content.ReadFromJsonAsync<Book>(_jsonOptions);
response.StatusCode.Should().Be(HttpStatusCode.Created);
bookResponse.Should().NotBeNull();
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
Assert.NotNull(bookResponse);
// metadata checks
bookResponse!.Metadata.Title.Should().Be(bookRequest.Metadata!.Title);
bookResponse.Metadata.OriginalTitle.Value.Should().Be(bookRequest.Metadata.OriginalTitle);
bookResponse.Metadata.Description.Value.Should().Be(bookRequest.Metadata.Description);
bookResponse.Metadata.Publisher.Value.Should().Be(bookRequest.Metadata.Publisher);
bookResponse.Metadata.PageCount.Value.Should().Be(bookRequest.Metadata.PageCount);
Assert.Equal(bookRequest.Metadata!.Title, bookResponse!.Metadata.Title);
Assert.Equal(bookRequest.Metadata.OriginalTitle, bookResponse.Metadata.OriginalTitle.Value);
Assert.Equal(bookRequest.Metadata.Description, bookResponse.Metadata.Description.Value);
Assert.Equal(bookRequest.Metadata.Publisher, bookResponse.Metadata.Publisher.Value);
Assert.Equal(bookRequest.Metadata.PageCount, bookResponse.Metadata.PageCount.Value);
// releaseInfo checks
bookResponse.Metadata.ReleaseInfo.OriginalReleaseDate.Value.Should().Be(bookRequest.Metadata.ReleaseInfo!.OriginalReleaseDate);
bookResponse.Metadata.ReleaseInfo.OriginalReleaseYear.Value.Should().Be(bookRequest.Metadata.ReleaseInfo.OriginalReleaseYear);
bookResponse.Metadata.ReleaseInfo.ReReleaseDate.Value.Should().Be(bookRequest.Metadata.ReleaseInfo.ReReleaseDate);
bookResponse.Metadata.ReleaseInfo.ReReleaseYear.Value.Should().Be(bookRequest.Metadata.ReleaseInfo.ReReleaseYear);
bookResponse.Metadata.ReleaseInfo.ReleaseCountry.Value.Should().Be(bookRequest.Metadata.ReleaseInfo.ReleaseCountry);
bookResponse.Metadata.ReleaseInfo.ReleaseVersion.Value.Should().Be(bookRequest.Metadata.ReleaseInfo.ReleaseVersion);
Assert.Equal(bookRequest.Metadata.ReleaseInfo!.OriginalReleaseDate, bookResponse.Metadata.ReleaseInfo.OriginalReleaseDate.Value);
Assert.Equal(bookRequest.Metadata.ReleaseInfo.OriginalReleaseYear, bookResponse.Metadata.ReleaseInfo.OriginalReleaseYear.Value);
Assert.Equal(bookRequest.Metadata.ReleaseInfo.ReReleaseDate, bookResponse.Metadata.ReleaseInfo.ReReleaseDate.Value);
Assert.Equal(bookRequest.Metadata.ReleaseInfo.ReReleaseYear, bookResponse.Metadata.ReleaseInfo.ReReleaseYear.Value);
Assert.Equal(bookRequest.Metadata.ReleaseInfo.ReleaseCountry, bookResponse.Metadata.ReleaseInfo.ReleaseCountry.Value);
Assert.Equal(bookRequest.Metadata.ReleaseInfo.ReleaseVersion, bookResponse.Metadata.ReleaseInfo.ReleaseVersion.Value);
// language checks
bookResponse.Metadata.Language.Value.LanguageCode.Should().Be(bookRequest.Metadata.Language!.LanguageCode);
bookResponse.Metadata.Language.Value.LanguageName.Should().Be(bookRequest.Metadata.Language.LanguageName);
bookResponse.Metadata.Language.Value.NativeName.Value.Should().Be(bookRequest.Metadata.Language.NativeName);
Assert.Equal(bookRequest.Metadata.Language!.LanguageCode, bookResponse.Metadata.Language.Value.LanguageCode);
Assert.Equal(bookRequest.Metadata.Language.LanguageName, bookResponse.Metadata.Language.Value.LanguageName);
Assert.Equal(bookRequest.Metadata.Language.NativeName, bookResponse.Metadata.Language.Value.NativeName.Value);
// original language checks
bookResponse.Metadata.OriginalLanguage.Value.LanguageCode.Should().Be(bookRequest.Metadata.OriginalLanguage!.LanguageCode);
bookResponse.Metadata.OriginalLanguage.Value.LanguageName.Should().Be(bookRequest.Metadata.OriginalLanguage.LanguageName);
bookResponse.Metadata.OriginalLanguage.Value.NativeName.Value.Should().Be(bookRequest.Metadata.OriginalLanguage.NativeName);
Assert.Equal(bookRequest.Metadata.OriginalLanguage!.LanguageCode, bookResponse.Metadata.OriginalLanguage.Value.LanguageCode);
Assert.Equal(bookRequest.Metadata.OriginalLanguage.LanguageName, bookResponse.Metadata.OriginalLanguage.Value.LanguageName);
Assert.Equal(bookRequest.Metadata.OriginalLanguage.NativeName, bookResponse.Metadata.OriginalLanguage.Value.NativeName.Value);
// genres checks
bookResponse.Metadata.Genres.Should().HaveCount(bookRequest.Metadata.Genres!.Count);
bookResponse.Metadata.Genres.Select(genre => genre.Name).Should().BeEquivalentTo(bookRequest.Metadata.Genres.Select(genre => genre.Name));
Assert.Equal(bookRequest.Metadata.Genres!.Count, bookResponse.Metadata.Genres.Count);
Assert.Equal(
bookRequest.Metadata.Genres.Select(genre => genre.Name).OrderBy(x => x),
bookResponse.Metadata.Genres.Select(genre => genre.Name).OrderBy(x => x));
// tags checks
bookResponse.Metadata.Tags.Should().HaveCount(bookRequest.Metadata.Tags!.Count);
bookResponse.Metadata.Tags.Select(tag => tag.Name).Should().BeEquivalentTo(bookRequest.Metadata.Tags.Select(tag => tag.Name));
Assert.Equal(bookRequest.Metadata.Tags!.Count, bookResponse.Metadata.Tags.Count);
Assert.Equal(
bookRequest.Metadata.Tags.Select(tag => tag.Name).OrderBy(x => x),
bookResponse.Metadata.Tags.Select(tag => tag.Name).OrderBy(x => x));
// book specific properties
bookResponse.Format.Value.Should().Be(bookRequest.Format);
bookResponse.Edition.Value.Should().Be(bookRequest.Edition);
bookResponse.VolumeNumber.Value.Should().Be(bookRequest.VolumeNumber);
bookResponse.ASIN.Value.Should().Be(bookRequest.ASIN);
bookResponse.GoodreadsId.Value.Should().Be(bookRequest.GoodreadsId);
bookResponse.LCCN.Value.Should().Be(bookRequest.LCCN);
bookResponse.OCLCNumber.Value.Should().Be(bookRequest.OCLCNumber);
bookResponse.OpenLibraryId.Value.Should().Be(bookRequest.OpenLibraryId);
bookResponse.LibraryThingId.Value.Should().Be(bookRequest.LibraryThingId);
bookResponse.GoogleBooksId.Value.Should().Be(bookRequest.GoogleBooksId);
bookResponse.BarnesAndNobleId.Value.Should().Be(bookRequest.BarnesAndNobleId);
bookResponse.AppleBooksId.Value.Should().Be(bookRequest.AppleBooksId);
Assert.Equal(bookRequest.Format, bookResponse.Format.Value);
Assert.Equal(bookRequest.Edition, bookResponse.Edition.Value);
Assert.Equal(bookRequest.VolumeNumber, bookResponse.VolumeNumber.Value);
Assert.Equal(bookRequest.ASIN, bookResponse.ASIN.Value);
Assert.Equal(bookRequest.GoodreadsId, bookResponse.GoodreadsId.Value);
Assert.Equal(bookRequest.LCCN, bookResponse.LCCN.Value);
Assert.Equal(bookRequest.OCLCNumber, bookResponse.OCLCNumber.Value);
Assert.Equal(bookRequest.OpenLibraryId, bookResponse.OpenLibraryId.Value);
Assert.Equal(bookRequest.LibraryThingId, bookResponse.LibraryThingId.Value);
Assert.Equal(bookRequest.GoogleBooksId, bookResponse.GoogleBooksId.Value);
Assert.Equal(bookRequest.BarnesAndNobleId, bookResponse.BarnesAndNobleId.Value);
Assert.Equal(bookRequest.AppleBooksId, bookResponse.AppleBooksId.Value);
// ISBNs checks
bookResponse.ISBNs.Should().HaveCount(bookRequest.ISBNs!.Count);
bookResponse.ISBNs.Should().HaveCount(bookRequest.ISBNs.Count);
bookResponse.ISBNs.Select(isbn => new { isbn.Value, isbn.Format })
.Should().BeEquivalentTo(bookRequest.ISBNs.Select(isbn => new { isbn.Value, isbn.Format }));
// contributors checks
// TODO: update when contributors are implemented
// bookResponse.Contributors.Should().HaveCount(bookRequest.Contributors.Count);
Assert.Equal(bookRequest.ISBNs!.Count, bookResponse.ISBNs.Count);
var requestIsbnData = bookRequest.ISBNs.Select(isbn => new { isbn.Value, isbn.Format }).OrderBy(x => x.Value).ToList();
var responseIsbnData = bookResponse.ISBNs.Select(isbn => new { Value = isbn.Value, Format = isbn.Format }).OrderBy(x => x.Value).ToList();
Assert.Equal(requestIsbnData.Count, responseIsbnData.Count);
for (int i = 0; i < requestIsbnData.Count; i++)
{
Assert.Equal(requestIsbnData[i].Value, responseIsbnData[i].Value);
Assert.Equal(requestIsbnData[i].Format, responseIsbnData[i].Format);
}
// ratings checks
bookResponse.Ratings.Should().HaveCount(bookRequest.Ratings!.Count);
bookResponse.Ratings.Should().HaveCount(bookRequest.Ratings.Count);
bookResponse.Ratings.Select(bookRating => new { Source = bookRating.Source.Value, bookRating.Value, bookRating.MaxValue, VoteCount = bookRating.VoteCount.Value })
.Should().BeEquivalentTo(bookRequest.Ratings.Select(bookRating => new { bookRating.Source, bookRating.Value, bookRating.MaxValue, bookRating.VoteCount }));
Assert.Equal(bookRequest.Ratings!.Count, bookResponse.Ratings.Count);
var requestRatingData = bookRequest.Ratings.Select(r => new { Source = r.Source, r.Value, r.MaxValue, r.VoteCount }).OrderBy(x => x.Source).ToList();
var responseRatingData = bookResponse.Ratings.Select(r => new { Source = r.Source.Value, r.Value, r.MaxValue, VoteCount = r.VoteCount.Value }).OrderBy(x => x.Source).ToList();
Assert.Equal(requestRatingData.Count, responseRatingData.Count);
for (int i = 0; i < requestRatingData.Count; i++)
{
Assert.Equal(requestRatingData[i].Source, responseRatingData[i].Source);
Assert.Equal(requestRatingData[i].Value, responseRatingData[i].Value);
Assert.Equal(requestRatingData[i].MaxValue, responseRatingData[i].MaxValue);
Assert.Equal(requestRatingData[i].VoteCount, responseRatingData[i].VoteCount);
}
// series checks
if (bookRequest.Series is not null)
{
bookResponse.Series.Should().NotBeNull();
bookResponse.Series.Value.Metadata.Title.Should().Be(bookRequest.Series.Title);
}
Assert.Equal(bookRequest.Series.Title, bookResponse.Series.Value.Metadata.Title);
else
bookResponse.Series.Value.Should().BeNull();
Assert.Null(bookResponse.Series.Value);
// check Location header
response.Headers.Location.Should().NotBeNull();
Assert.NotNull(response.Headers.Location);
string locationUri = response.Headers.Location!.ToString();
locationUri.Should().EndWith("/api/v1/books/" + bookResponse.Id.Value);
Assert.EndsWith("/api/v1/books/" + bookResponse.Id.Value, locationUri);
// extract ID from Location header
// extract ID from Location header and compare
string idFromHeader = locationUri.Split('/').Last();
// compare with bookResponse id
bookResponse!.Id.ToString().Should().Be(idFromHeader);
Assert.Equal(idFromHeader, bookResponse!.Id.ToString());
}
[Fact]
@@ -1580,21 +1585,24 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
private async Task AssertUnprocessableEntityWithValidationErrors(HttpResponseMessage response, params string[] expectedErrorCodes)
{
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
response.Content.Headers.ContentType?.MediaType.Should().Be("application/problem+json");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.Equal("application/problem+json", response.Content.Headers.ContentType?.MediaType);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status422UnprocessableEntity);
problemDetails["title"].GetString().Should().Be("General.Validation");
problemDetails["instance"].GetString().Should().Be("/api/v1/books");
problemDetails["detail"].GetString().Should().Be("OneOrMoreValidationErrorsOccurred");
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
problemDetails["traceId"].GetString().Should().NotBeNullOrWhiteSpace();
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status422UnprocessableEntity, problemDetails!["status"].GetInt32());
Assert.Equal("General.Validation", problemDetails["title"].GetString());
Assert.Equal("/api/v1/books", problemDetails["instance"].GetString());
Assert.Equal("OneOrMoreValidationErrorsOccurred", problemDetails["detail"].GetString());
Assert.Equal("https://tools.ietf.org/html/rfc4918#section-11.2", problemDetails["type"].GetString());
Assert.NotNull(problemDetails["traceId"].GetString());
Assert.NotEmpty(problemDetails["traceId"].GetString());
Dictionary<string, string[]>? errors = problemDetails["errors"].Deserialize<Dictionary<string, string[]>>(_jsonOptions);
errors.Should().ContainKey("General.Validation").WhoseValue.Should().Contain(expectedErrorCodes);
Assert.NotNull(errors);
Assert.Contains("General.Validation", errors.Keys);
Assert.All(expectedErrorCodes, code => Assert.Contains(code, errors["General.Validation"]));
}
private async Task AssertCreated(AddBookRequest bookRequest)
@@ -1602,8 +1610,8 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/books", bookRequest);
response.EnsureSuccessStatusCode();
Book? bookResponse = await response.Content.ReadFromJsonAsync<Book>(_jsonOptions);
response.StatusCode.Should().Be(HttpStatusCode.Created);
bookResponse.Should().NotBeNull();
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
Assert.NotNull(bookResponse);
}
/// <summary>
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -60,21 +59,22 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert
response.EnsureSuccessStatusCode();
response.StatusCode.Should().Be(HttpStatusCode.OK);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Book[]? bookResponse = await response.Content.ReadFromJsonAsync<Book[]>(_jsonOptions);
bookResponse.Should().NotBeNull();
Assert.NotNull(bookResponse);
}
[Fact]
public async Task ExecuteAsync_WhenCalledWithCancellationToken_ShouldCompletesuccessfuly()
{
// Arrange
using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5));
// Act
Func<Task> act = async () => await _client.GetAsync($"/api/v1/books", cts.Token);
// Assert
await act.Should().NotThrowAsync();
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
await _client.GetAsync($"/api/v1/books", cts.Token)
);
Assert.Null(exception);
}
[Fact]
@@ -83,15 +83,13 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Arrange
using CancellationTokenSource cts = new();
// Act
Func<Task> act = async () =>
// Act & Assert
Exception? exception = await Record.ExceptionAsync(async () =>
{
cts.Cancel(); // Cancel the token immediately
cts.Cancel();
await _client.GetAsync($"/api/v1/books", cts.Token);
};
// Assert
await act.Should().ThrowAsync<TaskCanceledException>();
});
Assert.IsType<TaskCanceledException>(exception);
}
/// <summary>
@@ -24,7 +24,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetPermissionsEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/permissions");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/permissions");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/permissions", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -46,16 +45,16 @@ public class AddRoleEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.PostAsync("/api/v1/auth/roles", content);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/roles");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -41,16 +40,16 @@ public class DeleteRoleEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.DeleteAsync(url);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be(url);
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal(url, problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -41,16 +40,16 @@ public class GetRolePermissionsEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync(url);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be(url);
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal(url, problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetRolesEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/roles");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/roles");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
@@ -52,16 +51,16 @@ public class UpdateRoleEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.PutAsync("/api/v1/auth/roles", content);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/roles");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/roles", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetDirectoriesEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/directories/get-directories");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/directories/get-directories");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/directories/get-directories", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetDrivesEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/drives/get-drives");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/drives/get-drives");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/drives/get-drives", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetTypeEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/file-system/get-type");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/file-system/get-type");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/file-system/get-type", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetFilesEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/files/get-files");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/files/get-files");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-files", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetTreeFilesEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/files/get-tree-files");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/files/get-tree-files");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/files/get-tree-files", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class CheckPathExistsEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/check-path-exists");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/check-path-exists");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/check-path-exists", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class CombinePathEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/combine");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/combine");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/combine", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetPathParentEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-parent");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-parent");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-parent", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetPathRootEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-root");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-root");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-root", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetPathSeparatorEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-separator");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-separator");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/get-path-separator", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class SplitPathEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/split");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/split");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/split", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class ValidatePathEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/path/validate");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/validate");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/path/validate", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetThumbnailEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/thumbnails/get-thumbnail");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/thumbnails/get-thumbnail");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/thumbnails/get-thumbnail", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
@@ -62,17 +61,17 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string content = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/change-password");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/change-password", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
[Fact]
@@ -103,7 +102,7 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
// Assert
double stdDev = CalculateStandardDeviation(timings);
stdDev.Should().BeLessThan(200);
Assert.True(stdDev < 200);
}
private static double CalculateStandardDeviation(List<long> values)
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -37,16 +36,16 @@ public class GetUsersEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync("/api/v1/auth/users");
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/users");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/users", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.Infrastructure.Security;
using Lumina.Contracts.Requests.Authentication;
@@ -89,18 +88,18 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
TimeSpan actualDifference = tokenExpiration - beforeRequest;
TimeSpan expectedDifference = TimeSpan.FromMinutes(15);
actualDifference.Should().BeCloseTo(expectedDifference, precision: allowedVariance);
Assert.True(Math.Abs((actualDifference - expectedDifference).TotalSeconds) < allowedVariance.TotalSeconds);
token.Header.Alg.Should().Be("HS256");
token.Claims.Should().Contain(c => c.Type == "sub" && c.Value == user.Id.ToString());
token.Claims.Should().Contain(c => c.Type == "unique_name" && c.Value == user.Username);
token.Claims.Should().Contain(c => c.Type == "jti");
token.Claims.Should().Contain(c => c.Type == "iss" && c.Value == "Lumina");
token.Claims.Should().Contain(c => c.Type == "aud" && c.Value == "Lumina");
Assert.Equal("HS256", token.Header.Alg);
Assert.Contains(token.Claims, c => c.Type == "sub" && c.Value == user.Id.ToString());
Assert.Contains(token.Claims, c => c.Type == "unique_name" && c.Value == user.Username);
Assert.Contains(token.Claims, c => c.Type == "jti");
Assert.Contains(token.Claims, c => c.Type == "iss" && c.Value == "Lumina");
Assert.Contains(token.Claims, c => c.Type == "aud" && c.Value == "Lumina");
content.Should().NotContain("password");
content.Should().NotContain("hash");
content.Should().NotContain("salt");
Assert.DoesNotContain("password", content);
Assert.DoesNotContain("hash", content);
Assert.DoesNotContain("salt", content);
// TODO: implement more strict security checks:
// // check security headers
@@ -142,7 +141,7 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
// Assert
// check for timing consistency to prevent timing attacks
double stdDev = CalculateStandardDeviation(timings);
stdDev.Should().BeLessThan(200);
Assert.True(stdDev < 200);
}
[Fact]
@@ -164,20 +163,20 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
// Assert
HttpResponseMessage lastResponse = responses.Last();
lastResponse.StatusCode.Should().Be(HttpStatusCode.TooManyRequests);
Assert.Equal(HttpStatusCode.TooManyRequests, lastResponse.StatusCode);
string content = await lastResponse.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status429TooManyRequests);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7231#section-6.5.29");
problemDetails["title"].GetString().Should().Be("TooManyRequests");
problemDetails["detail"].GetString().Should().Be("TooManyRequests");
problemDetails["retryAfter"].GetString().Should().Be("900");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status429TooManyRequests, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7231#section-6.5.29", problemDetails["type"].GetString());
Assert.Equal("TooManyRequests", problemDetails["title"].GetString());
Assert.Equal("TooManyRequests", problemDetails["detail"].GetString());
Assert.Equal("900", problemDetails["retryAfter"].GetString());
lastResponse.Headers.Should().ContainKey("X-RateLimit-Limit");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Reset");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Remaining");
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Limit"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Reset"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Remaining"));
}
[Theory]
@@ -200,11 +199,11 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
content.Should().NotContain("SQL");
content.Should().NotContain("Exception");
content.Should().NotContain(legitimateUser.Username); // shouldn't expose other usernames
content.Should().NotContain(legitimateUser.Password); // shouldn't expose password hashes
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
Assert.DoesNotContain("SQL", content);
Assert.DoesNotContain("Exception", content);
Assert.DoesNotContain(legitimateUser.Username, content); // shouldn't expose other usernames
Assert.DoesNotContain(legitimateUser.Password, content); // shouldn't expose password hashes
}
[Fact]
@@ -224,9 +223,9 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Forbidden);
content.Should().NotContain("SQL");
content.Should().NotContain("Exception");
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
Assert.DoesNotContain("SQL", content);
Assert.DoesNotContain("Exception", content);
}
[Fact]
@@ -245,9 +244,9 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
content.Should().NotContain("SQL");
content.Should().NotContain("Exception");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.DoesNotContain("SQL", content);
Assert.DoesNotContain("Exception", content);
}
private double CalculateStandardDeviation(List<long> values)
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
using Lumina.DataAccess.Core.UoW;
@@ -60,20 +59,20 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
// Assert
HttpResponseMessage lastResponse = responses.Last();
lastResponse.StatusCode.Should().Be(HttpStatusCode.TooManyRequests);
Assert.Equal(HttpStatusCode.TooManyRequests, lastResponse.StatusCode);
string content = await lastResponse.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status429TooManyRequests);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7231#section-6.5.29");
problemDetails["title"].GetString().Should().Be("TooManyRequests");
problemDetails["detail"].GetString().Should().Be("TooManyRequests");
problemDetails["retryAfter"].GetString().Should().Be("900");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status429TooManyRequests, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7231#section-6.5.29", problemDetails["type"].GetString());
Assert.Equal("TooManyRequests", problemDetails["title"].GetString());
Assert.Equal("TooManyRequests", problemDetails["detail"].GetString());
Assert.Equal("900", problemDetails["retryAfter"].GetString());
lastResponse.Headers.Should().ContainKey("X-RateLimit-Limit");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Reset");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Remaining");
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Limit"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Reset"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Remaining"));
}
public void Dispose()
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Requests.Authentication;
using Lumina.DataAccess.Core.UoW;
@@ -71,7 +70,7 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
// Assert
double stdDev = CalculateStandardDeviation(timings);
stdDev.Should().BeLessThan(200);
Assert.True(stdDev < 200);
}
[Fact]
@@ -93,20 +92,20 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
// Assert
HttpResponseMessage lastResponse = responses.Last();
lastResponse.StatusCode.Should().Be(HttpStatusCode.TooManyRequests);
Assert.Equal(HttpStatusCode.TooManyRequests, lastResponse.StatusCode);
string content = await lastResponse.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status429TooManyRequests);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7231#section-6.5.29");
problemDetails["title"].GetString().Should().Be("TooManyRequests");
problemDetails["detail"].GetString().Should().Be("TooManyRequests");
problemDetails["retryAfter"].GetString().Should().Be("900");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status429TooManyRequests, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7231#section-6.5.29", problemDetails["type"].GetString());
Assert.Equal("TooManyRequests", problemDetails["title"].GetString());
Assert.Equal("TooManyRequests", problemDetails["detail"].GetString());
Assert.Equal("900", problemDetails["retryAfter"].GetString());
lastResponse.Headers.Should().ContainKey("X-RateLimit-Limit");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Reset");
lastResponse.Headers.Should().ContainKey("X-RateLimit-Remaining");
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Limit"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Reset"));
Assert.True(lastResponse.Headers.Contains("X-RateLimit-Remaining"));
}
[Theory]
@@ -129,12 +128,12 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
content.Should().NotContain("SQL");
content.Should().NotContain("Exception");
content.Should().NotContain("password");
content.Should().NotContain("hash");
content.Should().NotContain("salt");
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.DoesNotContain("SQL", content);
Assert.DoesNotContain("Exception", content);
Assert.DoesNotContain("password", content);
Assert.DoesNotContain("hash", content);
Assert.DoesNotContain("salt", content);
}
[Theory]
@@ -158,8 +157,8 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.UnprocessableContent);
content.Should().NotContain(weakPassword); // shouldn't leak the actual password
Assert.Equal(HttpStatusCode.UnprocessableContent, response.StatusCode);
Assert.DoesNotContain(weakPassword, content); // shouldn't leak the actual password
}
[Theory]
@@ -178,7 +177,7 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/register", request);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Created);
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
}
[Fact]
@@ -199,11 +198,10 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
string content = await response.Content.ReadAsStringAsync();
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
content.Should().NotContain(_testUsername);
content.Should().NotContain("password");
content.Should().NotContain("hash");
content.Should().NotContain("salt");
Assert.Equal(HttpStatusCode.Conflict, response.StatusCode);
Assert.DoesNotContain("password", content);
Assert.DoesNotContain("hash", content);
Assert.DoesNotContain("salt", content);
}
private double CalculateStandardDeviation(List<long> values)
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -41,16 +40,16 @@ public class GetAuthorizationEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync(url);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/auth/get-authorization");
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal("/api/v1/auth/get-authorization", problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -40,16 +39,16 @@ public class GetUserPermissionsEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync(url);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be(url);
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal(url, problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -41,16 +40,16 @@ public class GetUserRoleEndpointTests : IClassFixture<LuminaApiFactory>
HttpResponseMessage response = await _client.GetAsync(url);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be(url);
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal(url, problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
@@ -42,16 +41,16 @@ public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<LuminaApi
HttpResponseMessage response = await _client.PutAsync(url, new StringContent("{}", Encoding.UTF8, "application/json"));
// Assert
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
string responseContent = await response.Content.ReadAsStringAsync();
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(responseContent, _jsonOptions);
problemDetails.Should().NotBeNull();
problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized);
problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1");
problemDetails["title"].GetString().Should().Be("Unauthorized");
problemDetails["instance"].GetProperty("value").GetString().Should().Be(url);
problemDetails["detail"].GetString().Should().Be("Authentication failed");
Assert.NotNull(problemDetails);
Assert.Equal(StatusCodes.Status401Unauthorized, problemDetails!["status"].GetInt32());
Assert.Equal("https://tools.ietf.org/html/rfc7235#section-3.1", problemDetails["type"].GetString());
Assert.Equal("Unauthorized", problemDetails["title"].GetString());
Assert.Equal(url, problemDetails["instance"].GetProperty("value").GetString());
Assert.Equal("Authentication failed", problemDetails["detail"].GetString());
}
}
@@ -24,7 +24,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using FluentValidation;
using FluentValidation.Results;
using Lumina.Application.Common.Behaviors;
@@ -46,8 +45,8 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(expectedResponse);
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
@@ -65,8 +64,8 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().Be(expectedResponse);
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
@@ -88,12 +87,12 @@ public class ValidationBehaviorTests
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
result.IsError.Should().BeTrue();
result.Errors.Should().HaveCount(2);
result.Errors[0].Type.Should().Be(ErrorType.Validation);
result.Errors[0].Description.Should().Be("Error message 1");
result.Errors[1].Type.Should().Be(ErrorType.Validation);
result.Errors[1].Description.Should().Be("Error message 2");
Assert.True(result.IsError);
Assert.Equal(2, result.Errors.Count);
Assert.Equal(ErrorType.Validation, result.Errors[0].Type);
Assert.Equal("Error message 1", result.Errors[0].Description);
Assert.Equal(ErrorType.Validation, result.Errors[1].Type);
Assert.Equal("Error message 2", result.Errors[1].Description);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.DidNotReceive().Invoke(request, Arg.Any<CancellationToken>());
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
using Lumina.Contracts.Requests.Authentication;
@@ -35,11 +34,11 @@ public class ChangePasswordRequestMappingTests
ChangePasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.CurrentPassword.Should().Be(request.CurrentPassword);
result.NewPassword.Should().Be(request.NewPassword);
result.NewPasswordConfirm.Should().Be(request.NewPasswordConfirm);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.CurrentPassword, result.CurrentPassword);
Assert.Equal(request.NewPassword, result.NewPassword);
Assert.Equal(request.NewPasswordConfirm, result.NewPasswordConfirm);
}
[Fact]
@@ -52,11 +51,11 @@ public class ChangePasswordRequestMappingTests
ChangePasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.CurrentPassword.Should().BeNull();
result.NewPassword.Should().BeNull();
result.NewPasswordConfirm.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.CurrentPassword);
Assert.Null(result.NewPassword);
Assert.Null(result.NewPasswordConfirm);
}
[Theory]
@@ -76,10 +75,10 @@ public class ChangePasswordRequestMappingTests
ChangePasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.CurrentPassword.Should().Be(currentPassword);
result.NewPassword.Should().Be(newPassword);
result.NewPasswordConfirm.Should().Be(newPasswordConfirm);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(currentPassword, result.CurrentPassword);
Assert.Equal(newPassword, result.NewPassword);
Assert.Equal(newPasswordConfirm, result.NewPasswordConfirm);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authentication;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
@@ -35,10 +34,10 @@ public class LoginRequestMappingTests
LoginUserQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.Password.Should().Be(request.Password);
result.TotpCode.Should().Be(request.TotpCode);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.TotpCode, result.TotpCode);
}
[Fact]
@@ -51,10 +50,10 @@ public class LoginRequestMappingTests
LoginUserQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.TotpCode.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.TotpCode);
}
[Theory]
@@ -74,9 +73,9 @@ public class LoginRequestMappingTests
LoginUserQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.Password.Should().Be(password);
result.TotpCode.Should().Be(totpCode);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(totpCode, result.TotpCode);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authentication;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
@@ -35,9 +34,9 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.TotpCode.Should().Be(request.TotpCode);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.TotpCode, result.TotpCode);
}
[Fact]
@@ -50,9 +49,9 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.TotpCode.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.TotpCode);
}
[Theory]
@@ -71,8 +70,8 @@ public class RecoverPasswordRequestMappingTests
RecoverPasswordCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.TotpCode.Should().Be(totpCode);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(totpCode, result.TotpCode);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authentication;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
@@ -36,11 +35,11 @@ public class RegistrationRequestMappingTests
SetupApplicationCommand result = request.ToSetupCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.Password.Should().Be(request.Password);
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
result.Use2fa.Should().Be(request.Use2fa);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.PasswordConfirm, result.PasswordConfirm);
Assert.Equal(request.Use2fa, result.Use2fa);
}
[Fact]
@@ -53,11 +52,11 @@ public class RegistrationRequestMappingTests
RegisterUserCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(request.Username);
result.Password.Should().Be(request.Password);
result.PasswordConfirm.Should().Be(request.PasswordConfirm);
result.Use2fa.Should().Be(request.Use2fa);
Assert.NotNull(result);
Assert.Equal(request.Username, result.Username);
Assert.Equal(request.Password, result.Password);
Assert.Equal(request.PasswordConfirm, result.PasswordConfirm);
Assert.Equal(request.Use2fa, result.Use2fa);
}
[Fact]
@@ -70,11 +69,11 @@ public class RegistrationRequestMappingTests
SetupApplicationCommand result = request.ToSetupCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.PasswordConfirm.Should().BeNull();
result.Use2fa.Should().BeTrue();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.PasswordConfirm);
Assert.True(result.Use2fa);
}
[Fact]
@@ -87,11 +86,11 @@ public class RegistrationRequestMappingTests
RegisterUserCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().BeNull();
result.Password.Should().BeNull();
result.PasswordConfirm.Should().BeNull();
result.Use2fa.Should().BeTrue();
Assert.NotNull(result);
Assert.Null(result.Username);
Assert.Null(result.Password);
Assert.Null(result.PasswordConfirm);
Assert.True(result.Use2fa);
}
[Theory]
@@ -112,11 +111,11 @@ public class RegistrationRequestMappingTests
SetupApplicationCommand result = request.ToSetupCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.Password.Should().Be(password);
result.PasswordConfirm.Should().Be(passwordConfirm);
result.Use2fa.Should().Be(use2fa);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(passwordConfirm, result.PasswordConfirm);
Assert.Equal(use2fa, result.Use2fa);
}
[Theory]
@@ -137,10 +136,10 @@ public class RegistrationRequestMappingTests
RegisterUserCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
result.Password.Should().Be(password);
result.PasswordConfirm.Should().Be(passwordConfirm);
result.Use2fa.Should().Be(use2fa);
Assert.NotNull(result);
Assert.Equal(username, result.Username);
Assert.Equal(password, result.Password);
Assert.Equal(passwordConfirm, result.PasswordConfirm);
Assert.Equal(use2fa, result.Use2fa);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using Lumina.Contracts.Requests.Authorization;
@@ -29,9 +28,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -47,9 +46,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Empty(result.Permissions);
}
[Theory]
@@ -68,9 +67,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(roleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(roleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -89,9 +88,9 @@ public class AddRoleRequestMappingTests
AddRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
}
[Theory]
@@ -44,8 +43,8 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(roleId);
Assert.NotNull(result);
Assert.Equal(roleId, result.RoleId);
}
[Fact]
@@ -54,11 +53,8 @@ public class DeleteRoleRequestMappingTests
// Arrange
DeleteRoleRequest request = new(null);
// Act
Action act = () => request.ToCommand();
// Assert
act.Should().Throw<InvalidOperationException>();
// Act & Assert
Assert.Throws<InvalidOperationException>(() => request.ToCommand());
}
[Fact]
@@ -71,7 +67,7 @@ public class DeleteRoleRequestMappingTests
DeleteRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.RoleId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,7 +57,7 @@ public class GetAuthorizationRequestMappingTests
GetAuthorizationQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId);
Assert.NotNull(result);
Assert.Equal(request.RoleId, result.RoleId);
}
[Theory]
@@ -44,8 +43,8 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(roleId);
Assert.NotNull(result);
Assert.Equal(roleId, result.RoleId);
}
[Fact]
@@ -58,7 +57,7 @@ public class GetRolePermissionsRequestMappingTests
GetRolePermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.RoleId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,8 +57,8 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -72,7 +71,7 @@ public class GetUserPermissionsRequestMappingTests
GetUserPermissionsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Contracts.Requests.Authorization;
@@ -26,8 +25,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -40,8 +39,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().BeNull();
Assert.NotNull(result);
Assert.Null(result.UserId);
}
[Theory]
@@ -58,8 +57,8 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
Assert.NotNull(result);
Assert.Equal(request.UserId, result.UserId);
}
[Fact]
@@ -72,7 +71,7 @@ public class GetUserRoleRequestMappingTests
GetUserRoleQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(Guid.Empty);
Assert.NotNull(result);
Assert.Equal(Guid.Empty, result.UserId);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -7,6 +6,7 @@ using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
@@ -31,9 +31,9 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(entity.PermissionName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.PermissionName, result.PermissionName);
}
[Theory]
@@ -54,9 +54,9 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(permission);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(permission, result.PermissionName);
}
[Fact]
@@ -74,11 +74,10 @@ public class PermissionEntityMappingTests
IEnumerable<PermissionResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(3);
results.Should().BeEquivalentTo(entities, options => options
.Including(x => x.Id)
.Including(x => x.PermissionName));
Assert.NotNull(results);
Assert.Equal(3, results.Count());
Assert.Equal(entities.Select(e => e.Id), results.Select(r => r.Id));
Assert.Equal(entities.Select(e => e.PermissionName), results.Select(r => r.PermissionName));
}
[Fact]
@@ -91,8 +90,8 @@ public class PermissionEntityMappingTests
IEnumerable<PermissionResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
[Theory]
@@ -112,8 +111,8 @@ public class PermissionEntityMappingTests
PermissionResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.PermissionName.Should().Be(entity.PermissionName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.PermissionName, result.PermissionName);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -7,6 +6,7 @@ using Lumina.Domain.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
@@ -31,9 +31,9 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(entity.RoleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.RoleName, result.RoleName);
}
[Fact]
@@ -77,10 +77,10 @@ public class RoleEntityMappingTests
RolePermissionsResponse result = role.ToRolePermissionsResponse();
// Assert
result.Should().NotBeNull();
result.Role.Id.Should().Be(role.Id);
result.Role.RoleName.Should().Be(role.RoleName);
result.Permissions.Should().HaveCount(2);
Assert.NotNull(result);
Assert.Equal(role.Id, result.Role.Id);
Assert.Equal(role.RoleName, result.Role.RoleName);
Assert.Equal(2, result.Permissions.Length);
}
[Fact]
@@ -98,11 +98,14 @@ public class RoleEntityMappingTests
IEnumerable<RoleResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(3);
results.Should().BeEquivalentTo(entities, options => options
.Including(x => x.Id)
.Including(x => x.RoleName));
Assert.NotNull(results);
Assert.Equal(3, results.Count());
List<RoleResponse> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
Assert.Equal(entities[i].Id, resultList[i].Id);
Assert.Equal(entities[i].RoleName, resultList[i].RoleName);
}
}
[Fact]
@@ -115,8 +118,8 @@ public class RoleEntityMappingTests
IEnumerable<RoleResponse> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
Assert.NotNull(results);
Assert.Empty(results);
}
[Theory]
@@ -136,9 +139,9 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(roleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(roleName, result.RoleName);
}
[Theory]
@@ -158,8 +161,8 @@ public class RoleEntityMappingTests
RoleResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.RoleName.Should().Be(entity.RoleName);
Assert.NotNull(result);
Assert.Equal(entity.Id, result.Id);
Assert.Equal(entity.RoleName, result.RoleName);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using Lumina.Contracts.Requests.Authorization;
@@ -31,10 +30,10 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
result.RoleName.Should().Be(request.RoleName);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
Assert.Equal(request.RoleName, result.RoleName);
Assert.Equal(request.Permissions, result.Permissions);
}
[Theory]
@@ -54,8 +53,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleName.Should().Be(roleName);
Assert.NotNull(result);
Assert.Equal(roleName, result.RoleName);
}
[Theory]
@@ -75,8 +74,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.RoleId.Should().Be(request.RoleId!.Value);
Assert.NotNull(result);
Assert.Equal(request.RoleId!.Value, result.RoleId);
}
[Fact]
@@ -95,8 +94,8 @@ public class UpdateRoleRequestMappingTests
UpdateRoleCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using Lumina.Contracts.Requests.Authorization;
@@ -31,10 +30,10 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
result.RoleId.Should().Be(request.RoleId);
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
Assert.Equal(request.RoleId, result.RoleId);
Assert.Equal(request.Permissions, result.Permissions);
}
[Fact]
@@ -52,10 +51,10 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
result.RoleId.Should().BeNull();
result.Permissions.Should().BeEquivalentTo(request.Permissions);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
Assert.Null(result.RoleId);
Assert.Equal(request.Permissions, result.Permissions);
}
[Theory]
@@ -75,8 +74,8 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId!.Value);
Assert.NotNull(result);
Assert.Equal(request.UserId!.Value, result.UserId);
}
[Fact]
@@ -99,8 +98,8 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
UpdateUserRoleAndPermissionsCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Permissions.Should().BeEquivalentTo(permissions);
result.Permissions.Should().HaveCount(3);
Assert.NotNull(result);
Assert.Equal(permissions, result.Permissions);
Assert.Equal(3, result.Permissions.Count);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Mapping.Authorization;
using Lumina.Contracts.Responses.Authorization;
@@ -32,10 +31,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
[Fact]
@@ -53,10 +52,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEmpty();
result.Permissions.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Empty(result.Role!);
Assert.Empty(result.Permissions);
}
[Fact]
@@ -79,10 +78,10 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
[Theory]
@@ -103,9 +102,9 @@ public class UserAuthorizationEntityMappingTests
AuthorizationResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(entity.UserId);
result.Role.Should().BeEquivalentTo(entity.Role);
result.Permissions.Should().BeEquivalentTo(entity.Permissions);
Assert.NotNull(result);
Assert.Equal(entity.UserId, result.UserId);
Assert.Equal(entity.Role, result.Role);
Assert.Equal(entity.Permissions, result.Permissions);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -27,9 +26,9 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
[Theory]
@@ -46,9 +45,9 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(genreDto.Name, result.Value.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class GenreDtoMappingTests
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -83,14 +82,14 @@ public class GenreDtoMappingTests
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreDtos.Count);
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < genreDtos.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(genreDtos[i].Name);
Assert.False(resultList[i].IsError);
Assert.Equal(genreDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -110,18 +109,18 @@ public class GenreDtoMappingTests
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreDtos.Count);
Assert.NotNull(results);
Assert.Equal(genreDtos.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("Rock");
Assert.False(resultList[0].IsError);
Assert.Equal("Rock", resultList[0].Value.Name);
resultList[1].IsError.Should().BeTrue();
Assert.True(resultList[1].IsError);
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("Jazz");
Assert.False(resultList[2].IsError);
Assert.Equal("Jazz", resultList[2].Value.Name);
resultList[3].IsError.Should().BeTrue();
Assert.True(resultList[3].IsError);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
@@ -29,8 +28,8 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -47,8 +46,8 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class GenreEntityMappingTests
GenreDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
Assert.Equal(invalidName, result.Name);
}
[Fact]
@@ -77,9 +76,9 @@ public class GenreEntityMappingTests
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
[Theory]
@@ -95,8 +94,8 @@ public class GenreEntityMappingTests
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.GenreNameCannotBeEmpty);
Assert.True(result.IsError);
Assert.Equal(Errors.Metadata.GenreNameCannotBeEmpty, result.FirstError);
}
[Fact]
@@ -115,14 +114,14 @@ public class GenreEntityMappingTests
IEnumerable<ErrorOr<Genre>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(entities[i].Name);
Assert.False(resultList[i].IsError);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -142,13 +141,13 @@ public class GenreEntityMappingTests
IEnumerable<GenreDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<GenreDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
Assert.Equal(entities[i].Name, resultList[i].Name);
}
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -22,15 +21,15 @@ public class GenreMappingTests
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create("Rock");
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
Assert.NotNull(result);
Assert.Equal(genre.Name, result.Name);
}
[Theory]
@@ -42,15 +41,15 @@ public class GenreMappingTests
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create(name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
Assert.NotNull(result);
Assert.Equal(genre.Name, result.Name);
}
[Fact]
@@ -69,10 +68,10 @@ public class GenreMappingTests
IEnumerable<GenreEntity> results = genres.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genres.Count);
Assert.NotNull(results);
Assert.Equal(genres.Count, results.Count());
List<GenreEntity> resultList = results.ToList();
for (int i = 0; i < genres.Count; i++)
resultList[i].Name.Should().Be(genres[i].Name);
Assert.Equal(genres[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -27,9 +26,9 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
[Theory]
@@ -47,9 +46,9 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagDto.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(tagDto.Name, result.Value.Name);
}
[Theory]
@@ -65,7 +64,7 @@ public class TagDtoMappingTests
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
Assert.True(result.IsError);
}
[Fact]
@@ -84,14 +83,14 @@ public class TagDtoMappingTests
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagDtos.Count);
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < tagDtos.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(tagDtos[i].Name);
Assert.False(resultList[i].IsError);
Assert.Equal(tagDtos[i].Name, resultList[i].Value.Name);
}
}
@@ -111,18 +110,18 @@ public class TagDtoMappingTests
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagDtos.Count);
Assert.NotNull(results);
Assert.Equal(tagDtos.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("indie");
Assert.False(resultList[0].IsError);
Assert.Equal("indie", resultList[0].Value.Name);
resultList[1].IsError.Should().BeTrue();
Assert.True(resultList[1].IsError);
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("electronic");
Assert.False(resultList[2].IsError);
Assert.Equal("electronic", resultList[2].Value.Name);
resultList[3].IsError.Should().BeTrue();
Assert.True(resultList[3].IsError);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
@@ -29,8 +28,8 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -47,8 +46,8 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
Assert.NotNull(result);
Assert.Equal(entity.Name, result.Name);
}
[Theory]
@@ -64,7 +63,7 @@ public class TagEntityMappingTests
TagDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
Assert.Equal(invalidName, result.Name);
}
[Fact]
@@ -77,9 +76,9 @@ public class TagEntityMappingTests
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(entity.Name, result.Value.Name);
}
[Theory]
@@ -95,8 +94,8 @@ public class TagEntityMappingTests
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.TagNameCannotBeEmpty);
Assert.True(result.IsError);
Assert.Equal(Errors.Metadata.TagNameCannotBeEmpty, result.FirstError);
}
[Fact]
@@ -115,14 +114,14 @@ public class TagEntityMappingTests
IEnumerable<ErrorOr<Tag>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(entities[i].Name);
Assert.False(resultList[i].IsError);
Assert.Equal(entities[i].Name, resultList[i].Value.Name);
}
}
@@ -142,13 +141,11 @@ public class TagEntityMappingTests
IEnumerable<TagDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
Assert.NotNull(results);
Assert.Equal(entities.Count, results.Count());
List<TagDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
}
Assert.Equal(entities[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -22,15 +21,15 @@ public class TagMappingTests
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create("indie");
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
Assert.NotNull(result);
Assert.Equal(tag.Name, result.Name);
}
[Theory]
@@ -43,15 +42,15 @@ public class TagMappingTests
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create(name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
Assert.NotNull(result);
Assert.Equal(tag.Name, result.Name);
}
[Fact]
@@ -71,10 +70,10 @@ public class TagMappingTests
IEnumerable<TagEntity> results = tags.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tags.Count);
Assert.NotNull(results);
Assert.Equal(tags.Count, results.Count());
List<TagEntity> resultList = results.ToList();
for (int i = 0; i < tags.Count; i++)
resultList[i].Name.Should().Be(tags[i].Name);
Assert.Equal(tags[i].Name, resultList[i].Name);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Common;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Domain.Common.Enums.FileSystem;
@@ -37,11 +36,11 @@ public class FileSystemTreeNodeResponseMappingTests
ErrorOr<WindowsRootItem> result = response.ToWindowsRootItem();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Id.Path.Should().Be(response.Path);
result.Value.Name.Should().Be(response.Name);
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(response.Path, result.Value.Id.Path);
Assert.Equal(response.Name, result.Value.Name);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
[Fact]
@@ -54,8 +53,8 @@ public class FileSystemTreeNodeResponseMappingTests
ErrorOr<UnixRootItem> result = response.ToUnixRootItem();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
Assert.False(result.IsError);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
@@ -46,20 +45,20 @@ public class DirectoryMappingTests
FileSystemTreeNodeResponse result = directory.ToFileSystemTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(directory.Name);
result.Path.Should().Be(directory.Id.Path);
result.ItemType.Should().Be(directory.Type);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().NotBeNull();
result.Children.Should().HaveCount(childItems.Count);
Assert.NotNull(result);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.NotNull(result.Children);
Assert.Equal(childItems.Count, result.Children.Count);
for (int i = 0; i < childItems.Count; i++)
{
result.Children[i].Name.Should().Be(childItems[i].Name);
result.Children[i].Path.Should().Be(childItems[i].Id.Path);
result.Children[i].ItemType.Should().Be(childItems[i].Type);
Assert.Equal(childItems[i].Name, result.Children[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Children[i].Path);
Assert.Equal(childItems[i].Type, result.Children[i].ItemType);
}
}
@@ -73,15 +72,15 @@ public class DirectoryMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = directories.ToFileSystemTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(directories.Count);
Assert.NotNull(result);
Assert.Equal(directories.Count, result.Count());
List<FileSystemTreeNodeResponse> resultList = result.ToList();
for (int i = 0; i < directories.Count; i++)
{
resultList[i].Name.Should().Be(directories[i].Name);
resultList[i].Path.Should().Be(directories[i].Id.Path);
resultList[i].ItemType.Should().Be(directories[i].Type);
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].Id.Path, resultList[i].Path);
Assert.Equal(directories[i].Type, resultList[i].ItemType);
}
}
@@ -102,18 +101,18 @@ public class DirectoryMappingTests
DirectoryResponse result = directory.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(directory.Id.Path);
result.Name.Should().Be(directory.Name);
result.DateCreated.Should().Be(directory.DateCreated.Value);
result.DateModified.Should().Be(directory.DateModified.Value);
result.Items.Should().NotBeNull();
result.Items.Should().HaveCount(childItems.Count);
Assert.NotNull(result);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.DateCreated.Value, result.DateCreated);
Assert.Equal(directory.DateModified.Value, result.DateModified);
Assert.NotNull(result.Items);
Assert.Equal(childItems.Count, result.Items.Count);
for (int i = 0; i < childItems.Count; i++)
{
result.Items[i].Name.Should().Be(childItems[i].Name);
result.Items[i].Path.Should().Be(childItems[i].Id.Path);
Assert.Equal(childItems[i].Name, result.Items[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Items[i].Path);
}
}
@@ -127,16 +126,16 @@ public class DirectoryMappingTests
IEnumerable<DirectoryResponse> result = directories.ToResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(directories.Count);
Assert.NotNull(result);
Assert.Equal(directories.Count, result.Count());
List<DirectoryResponse> resultList = result.ToList();
for (int i = 0; i < directories.Count; i++)
{
resultList[i].Path.Should().Be(directories[i].Id.Path);
resultList[i].Name.Should().Be(directories[i].Name);
resultList[i].DateCreated.Should().Be(directories[i].DateCreated.Value);
resultList[i].DateModified.Should().Be(directories[i].DateModified.Value);
Assert.Equal(directories[i].Id.Path, resultList[i].Path);
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directories[i].DateModified.Value, resultList[i].DateModified);
}
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
@@ -36,8 +35,8 @@ public class GetDirectoriesRequestMappingTests
GetDirectoriesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
@@ -59,11 +58,11 @@ public class FileSystemItemMappingTests
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
[Fact]
@@ -76,10 +75,10 @@ public class FileSystemItemMappingTests
FileSystemTreeNodeResponse result = directory.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(directory.Name);
result.Path.Should().Be(directory.Id.Path);
result.ItemType.Should().Be(directory.Type);
Assert.NotNull(result);
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
}
[Fact]
@@ -92,10 +91,10 @@ public class FileSystemItemMappingTests
FileSystemTreeNodeResponse result = file.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(file.Name);
result.Path.Should().Be(file.Id.Path);
result.ItemType.Should().Be(file.Type);
Assert.NotNull(result);
Assert.Equal(file.Name, result.Name);
Assert.Equal(file.Id.Path, result.Path);
Assert.Equal(file.Type, result.ItemType);
}
[Fact]
@@ -108,13 +107,13 @@ public class FileSystemItemMappingTests
FileSystemTreeNodeResponse result = windowsRootItem.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(windowsRootItem.Name);
result.Path.Should().Be(windowsRootItem.Id.Path);
result.ItemType.Should().Be(windowsRootItem.Type);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(windowsRootItem.Name, result.Name);
Assert.Equal(windowsRootItem.Id.Path, result.Path);
Assert.Equal(windowsRootItem.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Fact]
@@ -127,13 +126,13 @@ public class FileSystemItemMappingTests
FileSystemTreeNodeResponse result = unixRootItem.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(unixRootItem.Name);
result.Path.Should().Be(unixRootItem.Id.Path);
result.ItemType.Should().Be(unixRootItem.Type);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(unixRootItem.Name, result.Name);
Assert.Equal(unixRootItem.Id.Path, result.Path);
Assert.Equal(unixRootItem.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Theory]
@@ -149,11 +148,11 @@ public class FileSystemItemMappingTests
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
[Fact]
@@ -163,26 +162,26 @@ public class FileSystemItemMappingTests
List<FileSystemItem> domainModels =
[
_directoryFixture.CreateDirectory(),
_fileFixture.CreateFile(),
_windowsRootItemFixture.Create(),
_unixRootItemFixture.Create()
_fileFixture.CreateFile(),
_windowsRootItemFixture.Create(),
_unixRootItemFixture.Create()
];
// Act
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count);
Assert.NotNull(result);
Assert.Equal(domainModels.Count, result.Count());
List<FileSystemTreeNodeResponse> resultList = result.ToList();
for (int i = 0; i < resultList.Count; i++)
{
resultList[i].Name.Should().Be(domainModels[i].Name);
resultList[i].Path.Should().Be(domainModels[i].Id.Path);
resultList[i].ItemType.Should().Be(domainModels[i].Type);
resultList[i].IsExpanded.Should().BeFalse();
resultList[i].ChildrenLoaded.Should().BeFalse();
Assert.Equal(domainModels[i].Name, resultList[i].Name);
Assert.Equal(domainModels[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModels[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
}
}
@@ -196,9 +195,8 @@ public class FileSystemItemMappingTests
FileSystemItemFixture invalidItem = new(id, name, type);
// Act & Assert
invalidItem.Invoking(item => item.ToTreeNodeResponse())
.Should().Throw<ArgumentException>()
.WithMessage("Invalid FileSystemItem");
ArgumentException exception = Assert.Throws<ArgumentException>(() => invalidItem.ToTreeNodeResponse());
Assert.Equal("Invalid FileSystemItem", exception.Message);
}
[Fact]
@@ -211,19 +209,19 @@ public class FileSystemItemMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.Count());
List<FileSystemTreeNodeResponse> resultList = result.ToList();
List<FileSystemItem> domainModelsList = domainModels.ToList();
for (int i = 0; i < resultList.Count; i++)
{
resultList[i].Name.Should().Be(domainModelsList[i].Name);
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
resultList[i].IsExpanded.Should().BeFalse();
resultList[i].ChildrenLoaded.Should().BeFalse();
resultList[i].Children.Should().BeEmpty();
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
}
}
@@ -1,14 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -25,20 +20,20 @@ public class UnixRootItemMappingTests
{
// Arrange
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
UnixRootItem domainModel = createResult.Value;
// Act
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.ItemType.Should().Be(FileSystemItemType.Root);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().NotBeNull();
result.Children.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.NotNull(result.Children);
Assert.Empty(result.Children);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
@@ -23,20 +22,20 @@ public class WindowsRootItemMappingTests
string path = "C:\\";
string name = "C:";
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
WindowsRootItem domainModel = createResult.Value;
// Act
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.ItemType.Should().Be(FileSystemItemType.Root);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Fact]
@@ -47,19 +46,19 @@ public class WindowsRootItemMappingTests
string name = "D:";
FileSystemItemStatus customStatus = FileSystemItemStatus.Inaccessible;
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
WindowsRootItem domainModel = createResult.Value;
// Act
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.ItemType.Should().Be(FileSystemItemType.Root);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
result.Children.Should().BeEmpty();
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(FileSystemItemType.Root, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
@@ -40,12 +39,12 @@ public class FileMappingTests
FileSystemTreeNodeResponse result = domainModel.ToFileSystemTreeNodeResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(domainModel.Name);
result.Path.Should().Be(domainModel.Id.Path);
result.ItemType.Should().Be(domainModel.Type);
result.IsExpanded.Should().BeFalse();
result.ChildrenLoaded.Should().BeFalse();
Assert.NotNull(result);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Type, result.ItemType);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
}
[Fact]
@@ -58,19 +57,19 @@ public class FileMappingTests
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.Count());
List<FileSystemTreeNodeResponse> resultList = result.ToList();
List<File> domainModelsList = domainModels.ToList();
for (int i = 0; i < resultList.Count; i++)
{
resultList[i].Name.Should().Be(domainModelsList[i].Name);
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
resultList[i].IsExpanded.Should().BeFalse();
resultList[i].ChildrenLoaded.Should().BeFalse();
resultList[i].Children.Should().BeEmpty();
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
}
@@ -84,12 +83,12 @@ public class FileMappingTests
FileResponse result = domainModel.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(domainModel.Id.Path);
result.Name.Should().Be(domainModel.Name);
result.DateCreated.Should().Be(domainModel.DateCreated.Value);
result.DateModified.Should().Be(domainModel.DateModified.Value);
result.Size.Should().Be(domainModel.Size);
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.DateCreated.Value, result.DateCreated);
Assert.Equal(domainModel.DateModified.Value, result.DateModified);
Assert.Equal(domainModel.Size, result.Size);
}
[Fact]
@@ -102,18 +101,18 @@ public class FileMappingTests
IEnumerable<FileResponse> result = domainModels.ToResponses();
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(domainModels.Count());
Assert.NotNull(result);
Assert.Equal(domainModels.Count(), result.Count());
List<FileResponse> resultList = result.ToList();
List<File> domainModelsList = domainModels.ToList();
for (int i = 0; i < resultList.Count; i++)
{
resultList[i].Name.Should().Be(domainModelsList[i].Name);
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
resultList[i].Size.Should().Be(domainModelsList[i].Size);
resultList[i].DateCreated.Should().Be(domainModelsList[i].DateCreated.Value);
resultList[i].DateModified.Should().Be(domainModelsList[i].DateModified.Value);
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Size, resultList[i].Size);
Assert.Equal(domainModelsList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(domainModelsList[i].DateModified.Value, resultList[i].DateModified);
}
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
@@ -36,8 +35,8 @@ public class GetFilesRequestMappingTests
GetFilesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
@@ -36,8 +35,8 @@ public class GetTreeFilesRequestMappingTests
GetTreeFilesQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
@@ -38,9 +37,9 @@ public class CheckPathExistsRequestMappingTests
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
Assert.Equal(request.IncludeHiddenElements, result.IncludeHiddenElements);
}
[Theory]
@@ -56,9 +55,9 @@ public class CheckPathExistsRequestMappingTests
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
result.IncludeHiddenElements.Should().Be(includeHiddenElements);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
Assert.Equal(includeHiddenElements, result.IncludeHiddenElements);
}
[Fact]
@@ -71,12 +70,12 @@ public class CheckPathExistsRequestMappingTests
List<CheckPathExistsQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
results[i].IncludeHiddenElements.Should().Be(requests[i].IncludeHiddenElements);
Assert.Equal(requests[i].Path, results[i].Path);
Assert.Equal(requests[i].IncludeHiddenElements, results[i].IncludeHiddenElements);
}
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
@@ -38,9 +37,9 @@ public class CombinePathRequestMappingTests
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(request.OriginalPath);
result.NewPath.Should().Be(request.NewPath);
Assert.NotNull(result);
Assert.Equal(request.OriginalPath, result.OriginalPath);
Assert.Equal(request.NewPath, result.NewPath);
}
[Theory]
@@ -56,9 +55,9 @@ public class CombinePathRequestMappingTests
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(originalPath);
result.NewPath.Should().Be(newPath);
Assert.NotNull(result);
Assert.Equal(originalPath, result.OriginalPath);
Assert.Equal(newPath, result.NewPath);
}
[Fact]
@@ -71,12 +70,12 @@ public class CombinePathRequestMappingTests
List<CombinePathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].OriginalPath.Should().Be(requests[i].OriginalPath);
results[i].NewPath.Should().Be(requests[i].NewPath);
Assert.Equal(requests[i].OriginalPath, results[i].OriginalPath);
Assert.Equal(requests[i].NewPath, results[i].NewPath);
}
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
@@ -38,8 +37,8 @@ public class GetPathParentRequestMappingTests
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -55,8 +54,8 @@ public class GetPathParentRequestMappingTests
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -69,11 +68,11 @@ public class GetPathParentRequestMappingTests
List<GetPathParentQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
@@ -38,8 +37,8 @@ public class GetPathRootRequestMappingTests
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -56,8 +55,8 @@ public class GetPathRootRequestMappingTests
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -70,11 +69,11 @@ public class GetPathRootRequestMappingTests
List<GetPathRootQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
@@ -22,15 +21,15 @@ public class PathSegmentMappingTests
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
Assert.NotNull(result);
Assert.Equal(pathSegment.Name, result.Path);
}
[Theory]
@@ -41,15 +40,15 @@ public class PathSegmentMappingTests
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
createResult.IsError.Should().BeFalse();
Assert.False(createResult.IsError);
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
Assert.NotNull(result);
Assert.Equal(pathSegment.Name, result.Path);
}
[Fact]
@@ -68,10 +67,10 @@ public class PathSegmentMappingTests
IEnumerable<PathSegmentResponse> results = pathSegments.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(pathSegments.Count);
Assert.NotNull(results);
Assert.Equal(pathSegments.Count, results.Count());
List<PathSegmentResponse> resultList = results.ToList();
for (int i = 0; i < pathSegments.Count; i++)
resultList[i].Path.Should().Be(pathSegments[i].Name);
Assert.Equal(pathSegments[i].Name, resultList[i].Path);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
@@ -38,8 +37,8 @@ public class SplitPathRequestMappingTests
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
Assert.NotNull(result);
Assert.Equal(request.Path, result.Path);
}
[Theory]
@@ -56,8 +55,8 @@ public class SplitPathRequestMappingTests
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
Assert.NotNull(result);
Assert.Equal(path, result.Path);
}
[Fact]
@@ -70,9 +69,9 @@ public class SplitPathRequestMappingTests
List<SplitPathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
Assert.NotNull(results);
Assert.Equal(requests.Count, results.Count);
for (int i = 0; i < requests.Count; i++)
results[i].Path.Should().Be(requests[i].Path);
Assert.Equal(requests[i].Path, results[i].Path);
}
}
Loaded 100 of 235 files, more files were not shown because too many files have changed in this diff. Show more