mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Removes FluentAssertions library from test projects, due to licensing changes
This commit is contained in:
1 parent
c1100e5398
commit
d46bfae4fc
235 files changed
+4468
-4725
No files matched your search
+52
-44
@@ -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>
|
||||
|
||||
+22
-23
@@ -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>
|
||||
|
||||
+47
-40
@@ -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()
|
||||
|
||||
+68
-57
@@ -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()
|
||||
|
||||
+31
-26
@@ -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()
|
||||
|
||||
+30
-29
@@ -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)
|
||||
|
||||
+32
-33
@@ -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>
|
||||
|
||||
+29
-31
@@ -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>
|
||||
|
||||
+37
-40
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user