diff --git a/README.md b/README.md index 0ae06b59..d7aa0455 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,7 @@ string emailAddressOrErrorMessage = userResponse.Result.Match( | [Get User](https://appwrite.io/docs/references/1.6.x/server-rest/users#get) | ❌ | ⬛ | | [Delete User](https://appwrite.io/docs/references/1.6.x/server-rest/users#delete) | ❌ | ⬛ | | [Update Email](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateEmail) | ❌ | ⬛ | +| [Create User JWT](https://appwrite.io/docs/references/1.6.x/server-rest/users#createJWT) | ❌ | ⬛ | | [Update User Labels](https://appwrite.io/docs/references/1.6.x/server-rest/users#updateLabels) | ❌ | ⬛ | | [List User Logs](https://appwrite.io/docs/references/1.6.x/server-rest/users#listLogs) | ❌ | ⬛ | | [List User Memberships](https://appwrite.io/docs/references/1.6.x/server-rest/users#listMemberships) | ❌ | ⬛ | diff --git a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs index e5a59747..b1b3f29c 100644 --- a/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/AccountClient.cs @@ -7,9 +7,8 @@ using PinguApps.Appwrite.Client.Internals; using PinguApps.Appwrite.Client.Utils; using PinguApps.Appwrite.Shared; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; -using PinguApps.Appwrite.Shared.Utils; namespace PinguApps.Appwrite.Client; @@ -97,11 +96,13 @@ public async Task> UpdateEmail(UpdateEmailRequest request) } /// - public async Task> ListIdentities(List? queries = null) + public async Task> ListIdentities(ListIdentitiesRequest request) { try { - var queryStrings = queries?.Select(x => x.GetQueryString()) ?? []; + request.Validate(true); + + var queryStrings = request.Queries?.Select(x => x.GetQueryString()) ?? []; var result = await _accountApi.ListIdentities(GetCurrentSessionOrThrow(), queryStrings); @@ -146,11 +147,13 @@ public async Task> CreateJwt() } /// - public async Task> ListLogs(List? queries = null) + public async Task> ListLogs(ListLogsRequest request) { try { - var queryStrings = queries?.Select(x => x.GetQueryString()) ?? []; + request.Validate(true); + + var queryStrings = request.Queries?.Select(x => x.GetQueryString()) ?? []; var result = await _accountApi.ListLogs(GetCurrentSessionOrThrow(), queryStrings); diff --git a/src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs b/src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs index 3ad6dda3..7e011b0b 100644 --- a/src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs +++ b/src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs @@ -1,9 +1,8 @@ using System.Collections.Generic; using System.Threading.Tasks; using PinguApps.Appwrite.Shared; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; -using PinguApps.Appwrite.Shared.Utils; namespace PinguApps.Appwrite.Client; @@ -44,7 +43,7 @@ public interface IAccountClient /// /// Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, provider, providerUid, providerEmail, providerAccessTokenExpiry /// The Identities List - Task> ListIdentities(List? queries = null); + Task> ListIdentities(ListIdentitiesRequest request); /// /// Delete an identity by its unique ID @@ -67,7 +66,7 @@ public interface IAccountClient /// /// Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Only supported methods are limit and offset /// The Logs List - Task> ListLogs(List? queries = null); + Task> ListLogs(ListLogsRequest request); /// /// Enable or disable MFA on an account diff --git a/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs b/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs index c462c78e..bc22abad 100644 --- a/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs +++ b/src/PinguApps.Appwrite.Client/Handlers/HeaderHandler.cs @@ -1,15 +1,16 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using PinguApps.Appwrite.Shared; namespace PinguApps.Appwrite.Client.Handlers; internal class HeaderHandler : DelegatingHandler { private readonly string _projectId; - public HeaderHandler(string projectId) + public HeaderHandler(Config config) { - _projectId = projectId; + _projectId = config.ProjectId; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) diff --git a/src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs b/src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs index e7f4b722..87429658 100644 --- a/src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs +++ b/src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; using Refit; diff --git a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs index a35cfb19..a7a5729e 100644 --- a/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Client/ServiceCollectionExtensions.cs @@ -23,16 +23,15 @@ public static class ServiceCollectionExtensions /// The service collection, enabling chaining public static IServiceCollection AddAppwriteClient(this IServiceCollection services, string projectId, string endpoint = "https://cloud.appwrite.io/v1", RefitSettings? refitSettings = null) { - services.AddSingleton(x => new HeaderHandler(projectId)); - services.AddSingleton(); + services.AddSingleton(new Config(endpoint, projectId)); + services.AddTransient(); + services.AddTransient(); services.AddRefitClient(refitSettings) .ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint)) .AddHttpMessageHandler() .AddHttpMessageHandler(); - services.AddSingleton(new Config(endpoint, projectId)); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(x => new Lazy(() => x.GetRequiredService())); @@ -50,7 +49,8 @@ public static IServiceCollection AddAppwriteClient(this IServiceCollection servi /// The service collection, enabling chaining public static IServiceCollection AddAppwriteClientForServer(this IServiceCollection services, string projectId, string endpoint = "https://cloud.appwrite.io/v1", RefitSettings? refitSettings = null) { - services.AddSingleton(sp => new HeaderHandler(projectId)); + services.AddSingleton(new Config(endpoint, projectId)); + services.AddTransient(); services.AddRefitClient(refitSettings) .ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint)) @@ -63,8 +63,6 @@ public static IServiceCollection AddAppwriteClientForServer(this IServiceCollect } }); - services.AddSingleton(new Config(endpoint, projectId)); - services.AddSingleton(); services.AddSingleton(); diff --git a/src/PinguApps.Appwrite.Playground/App.cs b/src/PinguApps.Appwrite.Playground/App.cs index 1b3353cb..db71df3c 100644 --- a/src/PinguApps.Appwrite.Playground/App.cs +++ b/src/PinguApps.Appwrite.Playground/App.cs @@ -1,16 +1,14 @@ using Microsoft.Extensions.Configuration; -using PinguApps.Appwrite.Client; -using PinguApps.Appwrite.Server.Servers; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; namespace PinguApps.Appwrite.Playground; internal class App { - private readonly IAppwriteClient _client; - private readonly IAppwriteServer _server; + private readonly Client.IAppwriteClient _client; + private readonly Server.Clients.IAppwriteClient _server; private readonly string? _session; - public App(IAppwriteClient client, IAppwriteServer server, IConfiguration config) + public App(Client.IAppwriteClient client, Server.Clients.IAppwriteClient server, IConfiguration config) { _client = client; _server = server; @@ -19,9 +17,6 @@ public App(IAppwriteClient client, IAppwriteServer server, IConfiguration config public async Task Run(string[] args) { - _client.SetSession(_session); - - //var response = await _client.Account.CreatePhoneVerification(); var response = await _client.Account.UpdatePhoneVerificationConfirmation(new UpdatePhoneVerificationConfirmationRequest { UserId = "664aac1a00113f82e620", diff --git a/src/PinguApps.Appwrite.Server/Servers/AccountServer.cs b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs similarity index 96% rename from src/PinguApps.Appwrite.Server/Servers/AccountServer.cs rename to src/PinguApps.Appwrite.Server/Clients/AccountClient.cs index 5ee1c1cc..805756a9 100644 --- a/src/PinguApps.Appwrite.Server/Servers/AccountServer.cs +++ b/src/PinguApps.Appwrite.Server/Clients/AccountClient.cs @@ -4,17 +4,17 @@ using PinguApps.Appwrite.Server.Internals; using PinguApps.Appwrite.Server.Utils; using PinguApps.Appwrite.Shared; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; -namespace PinguApps.Appwrite.Server.Servers; -public class AccountServer : IAccountServer +namespace PinguApps.Appwrite.Server.Clients; +public class AccountClient : IAccountClient { private readonly IAccountApi _accountApi; private readonly Config _config; - public AccountServer(IServiceProvider services, Config config) + public AccountClient(IServiceProvider services, Config config) { _accountApi = services.GetRequiredService(); _config = config; diff --git a/src/PinguApps.Appwrite.Server/Clients/AppwriteClient.cs b/src/PinguApps.Appwrite.Server/Clients/AppwriteClient.cs new file mode 100644 index 00000000..f6247301 --- /dev/null +++ b/src/PinguApps.Appwrite.Server/Clients/AppwriteClient.cs @@ -0,0 +1,12 @@ +namespace PinguApps.Appwrite.Server.Clients; +public class AppwriteClient : IAppwriteClient +{ + public IAccountClient Account { get; } + public IUsersClient Users { get; } + + public AppwriteClient(IAccountClient accountClient, IUsersClient usersClient) + { + Account = accountClient; + Users = usersClient; + } +} diff --git a/src/PinguApps.Appwrite.Server/Servers/IAccountServer.cs b/src/PinguApps.Appwrite.Server/Clients/IAccountClient.cs similarity index 98% rename from src/PinguApps.Appwrite.Server/Servers/IAccountServer.cs rename to src/PinguApps.Appwrite.Server/Clients/IAccountClient.cs index 1178ff31..0b29e1a9 100644 --- a/src/PinguApps.Appwrite.Server/Servers/IAccountServer.cs +++ b/src/PinguApps.Appwrite.Server/Clients/IAccountClient.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; using PinguApps.Appwrite.Shared; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; -namespace PinguApps.Appwrite.Server.Servers; +namespace PinguApps.Appwrite.Server.Clients; /// /// The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity. @@ -11,7 +11,7 @@ namespace PinguApps.Appwrite.Server.Servers; /// This service also exposes an endpoint to save and read the user preferences as a key-value object. This feature is handy if you want to allow extra customization in your app.Common usage for this feature may include saving the user's preferred locale, timezone, or custom app theme. /// Appwrite Docs /// -public interface IAccountServer +public interface IAccountClient { /// /// Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the /account/verfication route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new account session. diff --git a/src/PinguApps.Appwrite.Server/Servers/IAppwriteServer.cs b/src/PinguApps.Appwrite.Server/Clients/IAppwriteClient.cs similarity index 67% rename from src/PinguApps.Appwrite.Server/Servers/IAppwriteServer.cs rename to src/PinguApps.Appwrite.Server/Clients/IAppwriteClient.cs index f1642e56..c29a371b 100644 --- a/src/PinguApps.Appwrite.Server/Servers/IAppwriteServer.cs +++ b/src/PinguApps.Appwrite.Server/Clients/IAppwriteClient.cs @@ -1,9 +1,9 @@ -namespace PinguApps.Appwrite.Server.Servers; +namespace PinguApps.Appwrite.Server.Clients; /// /// The root of the Client SDK. Access all API sections from here /// -public interface IAppwriteServer +public interface IAppwriteClient { /// /// The Account service allows you to authenticate and manage a user account. You can use the account service to update user information, retrieve the user sessions across different devices, and fetch the user security logs with his or her recent activity. @@ -11,5 +11,11 @@ public interface IAppwriteServer /// This service also exposes an endpoint to save and read the user preferences as a key-value object. This feature is handy if you want to allow extra customization in your app.Common usage for this feature may include saving the user's preferred locale, timezone, or custom app theme. /// Appwrite Docs /// - IAccountServer Account { get; } + IAccountClient Account { get; } + + /// + /// The Users service allows you to manage your project users. Use this service to search, block, and view your users' info, current sessions, and latest activity logs. You can also use the Users service to edit your users' preferences and personal info. + /// Appwrite Docs + /// + IUsersClient Users { get; } } diff --git a/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs new file mode 100644 index 00000000..281f8c51 --- /dev/null +++ b/src/PinguApps.Appwrite.Server/Clients/IUsersClient.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using PinguApps.Appwrite.Shared; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Responses; + +namespace PinguApps.Appwrite.Server.Clients; + +/// +/// The Users service allows you to manage your project users. Use this service to search, block, and view your users' info, current sessions, and latest activity logs. You can also use the Users service to edit your users' preferences and personal info. +/// Appwrite Docs +/// +public interface IUsersClient +{ + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListUsers(ListUsersRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUser(CreateUserRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithArgon2Password(CreateUserWithArgon2PasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithBcryptPassword(CreateUserWithBcryptPasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListIdentities(ListIdentitiesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task DeleteIdentity(DeleteIdentityRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithMd5Password(CreateUserWithMd5PasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithPhpassPassword(CreateUserWithPhpassPasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithScryptPassword(CreateUserWithScryptPasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithScryptModifiedPassword(CreateUserWithScryptModifiedPasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserWithShaPassword(CreateUserWithShaPasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task DeleteUser(DeleteUserRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> GetUser(GetUserRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateEmail(UpdateEmailRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserJwt(CreateUserJwtRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateUserLabels(UpdateUserLabelsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListUserLogs(ListUserLogsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListUserMemberships(ListUserMembershipsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateMfa(UpdateMfaRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> DeleteAuthenticator(DeleteAuthenticatorRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListFactors(ListFactorsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> GetMfaRecoveryCodes(GetMfaRecoveryCodesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateMfaRecoveryCodes(CreateMfaRecoveryCodesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> RegenerateMfaRecoveryCodes(RegenerateMfaRecoveryCodesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateName(UpdateNameRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdatePassword(UpdatePasswordRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdatePhone(UpdatePhoneRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task>> GetUserPreferences(GetUserPreferencesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task>> UpdateUserPreferences(UpdateUserPreferencesRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task DeleteUserSessions(DeleteUserSessionsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListUserSessions(ListUserSessionsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateSession(CreateSessionRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task DeleteUserSession(DeleteUserSessionRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateUserStatus(UpdateUserStatusRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> ListUserTargets(ListUserTargetsRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateUserTarget(CreateUserTargetRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task DeleteUserTarget(DeleteUserTargetRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> GetUserTarget(GetUserTargetRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateUserTarget(UpdateUserTargertRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> CreateToken(CreateTokenRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdateEmailVerification(UpdateEmailVerificationRequest request); + [Obsolete("This method hasn't yet been implemented.", true)] + Task> UpdatePhoneVerification(UpdatePhoneVerificationRequest request); +} diff --git a/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs new file mode 100644 index 00000000..d67a5eb6 --- /dev/null +++ b/src/PinguApps.Appwrite.Server/Clients/UsersClient.cs @@ -0,0 +1,190 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using PinguApps.Appwrite.Server.Internals; +using PinguApps.Appwrite.Shared; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Responses; + +namespace PinguApps.Appwrite.Server.Clients; +public class UsersClient : IUsersClient +{ + private readonly IUsersApi _usersApi; + private readonly Config _config; + + public UsersClient(IServiceProvider services, Config config) + { + _usersApi = services.GetRequiredService(); + _config = config; + } + + [ExcludeFromCodeCoverage] + /// + public Task> ListUsers(ListUsersRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUser(CreateUserRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithArgon2Password(CreateUserWithArgon2PasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithBcryptPassword(CreateUserWithBcryptPasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListIdentities(ListIdentitiesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task DeleteIdentity(DeleteIdentityRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithMd5Password(CreateUserWithMd5PasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithPhpassPassword(CreateUserWithPhpassPasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithScryptPassword(CreateUserWithScryptPasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithScryptModifiedPassword(CreateUserWithScryptModifiedPasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserWithShaPassword(CreateUserWithShaPasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task DeleteUser(DeleteUserRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> GetUser(GetUserRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateEmail(UpdateEmailRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserJwt(CreateUserJwtRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateUserLabels(UpdateUserLabelsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListUserLogs(ListUserLogsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListUserMemberships(ListUserMembershipsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateMfa(UpdateMfaRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> DeleteAuthenticator(DeleteAuthenticatorRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListFactors(ListFactorsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> GetMfaRecoveryCodes(GetMfaRecoveryCodesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateMfaRecoveryCodes(CreateMfaRecoveryCodesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> RegenerateMfaRecoveryCodes(RegenerateMfaRecoveryCodesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateName(UpdateNameRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdatePassword(UpdatePasswordRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdatePhone(UpdatePhoneRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task>> GetUserPreferences(GetUserPreferencesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task>> UpdateUserPreferences(UpdateUserPreferencesRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task DeleteUserSessions(DeleteUserSessionsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListUserSessions(ListUserSessionsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateSession(CreateSessionRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task DeleteUserSession(DeleteUserSessionRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateUserStatus(UpdateUserStatusRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> ListUserTargets(ListUserTargetsRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateUserTarget(CreateUserTargetRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task DeleteUserTarget(DeleteUserTargetRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> GetUserTarget(GetUserTargetRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateUserTarget(UpdateUserTargertRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> CreateToken(CreateTokenRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdateEmailVerification(UpdateEmailVerificationRequest request) => throw new NotImplementedException(); + + [ExcludeFromCodeCoverage] + /// + public Task> UpdatePhoneVerification(UpdatePhoneVerificationRequest request) => throw new NotImplementedException(); +} diff --git a/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs b/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs index 2459f0d4..8ff5e2af 100644 --- a/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs +++ b/src/PinguApps.Appwrite.Server/Handlers/HeaderHandler.cs @@ -1,6 +1,8 @@ -using System.Net.Http; +using System; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using PinguApps.Appwrite.Shared; namespace PinguApps.Appwrite.Server.Handlers; internal class HeaderHandler : DelegatingHandler @@ -8,10 +10,13 @@ internal class HeaderHandler : DelegatingHandler private readonly string _projectId; private readonly string _apiKey; - public HeaderHandler(string projectId, string apiKey) + public HeaderHandler(Config config) { - _projectId = projectId; - _apiKey = apiKey; + if (config.ApiKey is null) + throw new ArgumentNullException("config.ApiKey"); + + _projectId = config.ProjectId; + _apiKey = config.ApiKey; } protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) diff --git a/src/PinguApps.Appwrite.Server/Internals/IAccountApi.cs b/src/PinguApps.Appwrite.Server/Internals/IAccountApi.cs index 5fbe3c02..fb603e18 100644 --- a/src/PinguApps.Appwrite.Server/Internals/IAccountApi.cs +++ b/src/PinguApps.Appwrite.Server/Internals/IAccountApi.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Responses; using Refit; diff --git a/src/PinguApps.Appwrite.Server/Internals/IUsersApi.cs b/src/PinguApps.Appwrite.Server/Internals/IUsersApi.cs new file mode 100644 index 00000000..47503bcb --- /dev/null +++ b/src/PinguApps.Appwrite.Server/Internals/IUsersApi.cs @@ -0,0 +1,139 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Responses; +using Refit; + +namespace PinguApps.Appwrite.Server.Internals; +internal interface IUsersApi : IBaseApi +{ + [Get("/users")] + [QueryUriFormat(System.UriFormat.Unescaped)] + Task> ListUsers([Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable queries, string search); + + [Post("/users")] + Task> CreateUser(CreateUserRequest request); + + [Post("/users/argon2")] + Task> CreateUserWithArgon2Password(CreateUserWithArgon2PasswordRequest request); + + [Post("/users/bcrypt")] + Task> CreateUserWithBcryptPassword(CreateUserWithBcryptPasswordRequest request); + + [Get("/users/identities")] + [QueryUriFormat(System.UriFormat.Unescaped)] + Task> ListIdentities([Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable queries, string search); + + [Delete("/users/identities/{identityId}")] + Task DeleteIdentity(string identityId); + + [Post("/users/md5")] + Task> CreateUserWithMd5Password(CreateUserWithMd5PasswordRequest request); + + [Post("/users/phpass")] + Task> CreateUserWithPhpassPassword(CreateUserWithPhpassPasswordRequest request); + + [Post("/users/scrypt")] + Task> CreateUserWithScryptPassword(CreateUserWithScryptPasswordRequest request); + + [Post("/users/scrypt-modified")] + Task> CreateUserWithScryptModifiedPassword(CreateUserWithScryptModifiedPasswordRequest request); + + [Post("/users/sha")] + Task> CreateUserWithShaPassword(CreateUserWithShaPasswordRequest request); + + [Delete("/users/{userId}")] + Task DeleteUser(string userId); + + [Get("/users/{userId}")] + Task> GetUser(string userId); + + [Patch("/users/{userId}/email")] + Task> UpdateEmail(string userId, UpdateEmailRequest request); + + [Post("/users/{userId}/jwts")] + Task> CreateUserJwt(string userId, CreateUserJwtRequest request); + + [Put("/users/{userId}/labels")] + Task> UpdateUserLabels(string userId, UpdateUserLabelsRequest request); + + [Get("/users/{userId}/logs")] + [QueryUriFormat(System.UriFormat.Unescaped)] + Task> ListUserLogs(string userId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable queries); + + [Get("/users/{userId}/memberships")] + Task> ListUserMemberships(string userId); + + [Patch("/users/{userId}/mfa")] + Task> UpdateMfa(string userId, UpdateMfaRequest request); + + [Delete("/users/{userId}/mfa/authenticators/{type}")] + Task> DeleteAuthenticator(string userId, string type); + + [Get("/users/{userId}/mfa/factors")] + Task> ListFactors(string userId); + + [Get("/users/{userId}/mfa/recovery-codes")] + Task> GetMfaRecoveryCodes(string userId); + + [Patch("/users{userId}/mfa/recovery-codes")] + Task> CreateMfaRecoveryCodes(string userId); + + [Put("/users/{userId}/mfa/recovery-codes")] + Task> RegenerateMfaRecoveryCodes(string userId); + + [Patch("/users/{userId}/mame")] + Task> UpdateName(string userId, UpdateNameRequest request); + + [Patch("/users/{userId}/password")] + Task> UpdatePassword(string userId, UpdatePasswordRequest request); + + [Patch("/users/{userId}/phone")] + Task> UpdatePhone(string userId, UpdatePhoneRequest request); + + [Get("/users/{userId}/prefs")] + Task>> GetUserPreferences(string userId); + + [Patch("/users/{userId}/prefs")] + Task>> UpdateUserPreferences(string userId, UpdateUserPreferencesRequest request); + + [Delete("/users/{userId}/sessions")] + Task DeleteUserSessions(string userId); + + [Get("/users/{userId}/sessions")] + Task> ListUserSessions(string userId); + + [Post("/users/{userId}/sessions")] + Task> CreateSession(string userId); + + [Delete("/users/{userId}/sessions/{sessionId}")] + Task DeleteUserSession(string userId, string sessionId); + + [Patch("/users/{userId}/status")] + Task> UpdateUserStatus(string userId, UpdateUserStatusRequest request); + + [Get("/users/{userId}/targets")] + [QueryUriFormat(System.UriFormat.Unescaped)] + Task> ListUserTargets(string userId, [Query(CollectionFormat.Multi), AliasAs("queries[]")] IEnumerable queries); + + [Post("/users/{userId}/targets")] + Task> CreateUserTarget(string userId, CreateUserTargetRequest request); + + [Delete("/users/{userId}/targets/{targetId}")] + Task DeleteUserTarget(string userId, string targetId); + + [Get("/users/{userId}/targets/{targetId}")] + Task> GetUserTarget(string userId, string targetId); + + [Patch("/users/{userId}/targets/{targetId}")] + Task> UpdateUserTarget(string userId, string targetId, UpdateUserTargertRequest request); + + [Post("/users/{userId}/tokens")] + Task> CreateToken(string userId, CreateTokenRequest request); + + [Patch("/users/{userId}/verification")] + Task> UpdateEmailVerification(string userId, UpdateEmailVerificationRequest request); + + [Patch("/users/{userId}/verification/phone")] + Task> UpdatePhoneVerification(string userId, UpdatePhoneVerificationRequest request); +} diff --git a/src/PinguApps.Appwrite.Server/Servers/AppwriteServer.cs b/src/PinguApps.Appwrite.Server/Servers/AppwriteServer.cs deleted file mode 100644 index dc33405f..00000000 --- a/src/PinguApps.Appwrite.Server/Servers/AppwriteServer.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace PinguApps.Appwrite.Server.Servers; -public class AppwriteServer : IAppwriteServer -{ - public IAccountServer Account { get; } - - public AppwriteServer(IAccountServer accountServer) - { - Account = accountServer; - } -} diff --git a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs index 9a9cd71c..138c5c5f 100644 --- a/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs +++ b/src/PinguApps.Appwrite.Server/ServiceCollectionExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Net.Http; using Microsoft.Extensions.DependencyInjection; +using PinguApps.Appwrite.Server.Clients; using PinguApps.Appwrite.Server.Handlers; using PinguApps.Appwrite.Server.Internals; -using PinguApps.Appwrite.Server.Servers; using PinguApps.Appwrite.Shared; using Refit; @@ -25,7 +25,8 @@ public static class ServiceCollectionExtensions /// The service collection, enabling chaining public static IServiceCollection AddAppwriteServer(this IServiceCollection services, string projectId, string apiKey, string endpoint = "https://cloud.appwrite.io/v1", RefitSettings? refitSettings = null) { - services.AddSingleton(sp => new HeaderHandler(projectId, apiKey)); + services.AddSingleton(new Config(endpoint, projectId, apiKey)); + services.AddTransient(); services.AddRefitClient(refitSettings) .ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint)) @@ -38,10 +39,20 @@ public static IServiceCollection AddAppwriteServer(this IServiceCollection servi } }); - services.AddSingleton(new Config(endpoint, projectId)); + services.AddRefitClient(refitSettings) + .ConfigureHttpClient(x => x.BaseAddress = new Uri(endpoint)) + .AddHttpMessageHandler() + .ConfigurePrimaryHttpMessageHandler((handler, sp) => + { + if (handler is HttpClientHandler clientHandler) + { + clientHandler.UseCookies = false; + } + }); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); return services; } diff --git a/src/PinguApps.Appwrite.Shared/Config.cs b/src/PinguApps.Appwrite.Shared/Config.cs index c7109103..9abfcb01 100644 --- a/src/PinguApps.Appwrite.Shared/Config.cs +++ b/src/PinguApps.Appwrite.Shared/Config.cs @@ -1,5 +1,6 @@ namespace PinguApps.Appwrite.Shared; public record Config( string Endpoint, - string ProjectId + string ProjectId, + string? ApiKey = null ); diff --git a/src/PinguApps.Appwrite.Shared/Requests/AddAuthenticatorRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/AddAuthenticatorRequest.cs similarity index 76% rename from src/PinguApps.Appwrite.Shared/Requests/AddAuthenticatorRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/AddAuthenticatorRequest.cs index f1d45063..ef207315 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/AddAuthenticatorRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/AddAuthenticatorRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for adding an authenticator diff --git a/src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeConfirmationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeConfirmationRequest.cs similarity index 83% rename from src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeConfirmationRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeConfirmationRequest.cs index f8972e13..9f83061c 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeConfirmationRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeConfirmationRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a 2fa challenge confirmation diff --git a/src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeRequest.cs similarity index 86% rename from src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeRequest.cs index 8a6f17e0..feeb1bb1 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Create2faChallengeRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Create2faChallengeRequest.cs @@ -1,8 +1,8 @@ using System.Text.Json.Serialization; using PinguApps.Appwrite.Shared.Enums; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a 2fa challenge diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateAccountRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateAccountRequest.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/CreateAccountRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateAccountRequest.cs index 02b5d146..21bc4761 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateAccountRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateAccountRequest.cs @@ -1,8 +1,8 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; using PinguApps.Appwrite.Shared.Utils; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an account diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailPasswordSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailPasswordSessionRequest.cs similarity index 83% rename from src/PinguApps.Appwrite.Shared/Requests/CreateEmailPasswordSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailPasswordSessionRequest.cs index 6ba87829..7b7cbbce 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailPasswordSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailPasswordSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an email password session diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailTokenRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailTokenRequest.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/CreateEmailTokenRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailTokenRequest.cs index df7b8f48..af810e4d 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailTokenRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailTokenRequest.cs @@ -1,8 +1,8 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; using PinguApps.Appwrite.Shared.Utils; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an email token diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationConfirmationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationConfirmationRequest.cs similarity index 84% rename from src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationConfirmationRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationConfirmationRequest.cs index 5a1a356b..76b25b03 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationConfirmationRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationConfirmationRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an email verification confirmation diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationRequest.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationRequest.cs index c4f215a6..54f40a74 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateEmailVerificationRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateEmailVerificationRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an email verification (will email the user a link to verify their email) diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateMagicUrlTokenRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateMagicUrlTokenRequest.cs similarity index 93% rename from src/PinguApps.Appwrite.Shared/Requests/CreateMagicUrlTokenRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateMagicUrlTokenRequest.cs index 7844d0a6..b2ed6ffb 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateMagicUrlTokenRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateMagicUrlTokenRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a magic url token diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateOauth2SessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2SessionRequest.cs similarity index 94% rename from src/PinguApps.Appwrite.Shared/Requests/CreateOauth2SessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2SessionRequest.cs index 202a88ed..05a17d9e 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateOauth2SessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2SessionRequest.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using PinguApps.Appwrite.Shared.Attributes; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an Oauth2 Session diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateOauth2TokenRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2TokenRequest.cs similarity index 94% rename from src/PinguApps.Appwrite.Shared/Requests/CreateOauth2TokenRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2TokenRequest.cs index 611fa20e..ca9f536d 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateOauth2TokenRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateOauth2TokenRequest.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using PinguApps.Appwrite.Shared.Attributes; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating an Oauth2 token diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryConfirmationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryConfirmationRequest.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryConfirmationRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryConfirmationRequest.cs index 73ec2f64..11bf8c27 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryConfirmationRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryConfirmationRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a password recovery confirmation diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryRequest.cs similarity index 88% rename from src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryRequest.cs index 81398b88..9952d0d0 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreatePasswordRecoveryRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePasswordRecoveryRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a password recovery diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreatePhoneTokenRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePhoneTokenRequest.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/CreatePhoneTokenRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreatePhoneTokenRequest.cs index b358e83f..2c96f9a6 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreatePhoneTokenRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreatePhoneTokenRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request to create a phone token diff --git a/src/PinguApps.Appwrite.Shared/Requests/CreateSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateSessionRequest.cs similarity index 88% rename from src/PinguApps.Appwrite.Shared/Requests/CreateSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/CreateSessionRequest.cs index cd956f78..af4a4fdd 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/CreateSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/CreateSessionRequest.cs @@ -1,8 +1,8 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; using PinguApps.Appwrite.Shared.Utils; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for creating a session diff --git a/src/PinguApps.Appwrite.Shared/Requests/DeleteAuthenticatorRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteAuthenticatorRequest.cs similarity index 82% rename from src/PinguApps.Appwrite.Shared/Requests/DeleteAuthenticatorRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/DeleteAuthenticatorRequest.cs index 21fd9b78..6da7bc16 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/DeleteAuthenticatorRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteAuthenticatorRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for deleting an authenticator diff --git a/src/PinguApps.Appwrite.Shared/Requests/DeleteIdentityRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteIdentityRequest.cs similarity index 76% rename from src/PinguApps.Appwrite.Shared/Requests/DeleteIdentityRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/DeleteIdentityRequest.cs index 75d09c82..fc22f432 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/DeleteIdentityRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteIdentityRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for deleting an identity diff --git a/src/PinguApps.Appwrite.Shared/Requests/DeleteSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteSessionRequest.cs similarity index 80% rename from src/PinguApps.Appwrite.Shared/Requests/DeleteSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/DeleteSessionRequest.cs index 1d5cbd29..017f2a95 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/DeleteSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/DeleteSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for deleting a session (logging out of current session) diff --git a/src/PinguApps.Appwrite.Shared/Requests/GetSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/GetSessionRequest.cs similarity index 78% rename from src/PinguApps.Appwrite.Shared/Requests/GetSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/GetSessionRequest.cs index e287dbd3..bf140823 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/GetSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/GetSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for getting a session diff --git a/src/PinguApps.Appwrite.Shared/Requests/Account/ListIdentitiesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/ListIdentitiesRequest.cs new file mode 100644 index 00000000..de62e869 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/ListIdentitiesRequest.cs @@ -0,0 +1,6 @@ +using PinguApps.Appwrite.Shared.Requests.Account.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Account; +public class ListIdentitiesRequest : QueryBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Account/ListLogsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/ListLogsRequest.cs new file mode 100644 index 00000000..03241030 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/ListLogsRequest.cs @@ -0,0 +1,6 @@ +using PinguApps.Appwrite.Shared.Requests.Account.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Account; +public class ListLogsRequest : QueryBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdateEmailRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateEmailRequest.cs similarity index 82% rename from src/PinguApps.Appwrite.Shared/Requests/UpdateEmailRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdateEmailRequest.cs index 69c81bfe..ef056314 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdateEmailRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateEmailRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a users email diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdateMagicUrlSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMagicUrlSessionRequest.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/UpdateMagicUrlSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMagicUrlSessionRequest.cs index 17f44363..c197fbd6 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdateMagicUrlSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMagicUrlSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a magic url session diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdateMfaRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMfaRequest.cs similarity index 74% rename from src/PinguApps.Appwrite.Shared/Requests/UpdateMfaRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMfaRequest.cs index 3290ecc8..9cdc2703 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdateMfaRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateMfaRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating Mfa diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdateNameRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateNameRequest.cs similarity index 76% rename from src/PinguApps.Appwrite.Shared/Requests/UpdateNameRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdateNameRequest.cs index 073ec102..5038b649 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdateNameRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateNameRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a users name diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdatePasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePasswordRequest.cs similarity index 83% rename from src/PinguApps.Appwrite.Shared/Requests/UpdatePasswordRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePasswordRequest.cs index 8b85783a..455653db 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdatePasswordRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePasswordRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a users password diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneRequest.cs similarity index 84% rename from src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneRequest.cs index 2697ea02..2544b87c 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a users phone diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneSessionRequest.cs similarity index 86% rename from src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneSessionRequest.cs index abca37a6..c6da06ef 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating the phone session. diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneVerificationConfirmationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneVerificationConfirmationRequest.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneVerificationConfirmationRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneVerificationConfirmationRequest.cs index 71ebb31e..e056ca64 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdatePhoneVerificationConfirmationRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePhoneVerificationConfirmationRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a phone verification confirmation diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdatePreferencesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePreferencesRequest.cs similarity index 80% rename from src/PinguApps.Appwrite.Shared/Requests/UpdatePreferencesRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePreferencesRequest.cs index 73f11915..1c699fea 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdatePreferencesRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdatePreferencesRequest.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a users preferences diff --git a/src/PinguApps.Appwrite.Shared/Requests/UpdateSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateSessionRequest.cs similarity index 78% rename from src/PinguApps.Appwrite.Shared/Requests/UpdateSessionRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/UpdateSessionRequest.cs index 5ce7651a..fb7871a3 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/UpdateSessionRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/UpdateSessionRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for updating a session diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/AddAuthenticatorRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/AddAuthenticatorRequestValidator.cs similarity index 84% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/AddAuthenticatorRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/AddAuthenticatorRequestValidator.cs index 31429f21..9fb67cac 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/AddAuthenticatorRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/AddAuthenticatorRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeConfirmationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeConfirmationRequestValidator.cs similarity index 88% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeConfirmationRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeConfirmationRequestValidator.cs index 12c24390..549123f2 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeConfirmationRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeConfirmationRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeRequestValidator.cs similarity index 86% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeRequestValidator.cs index 6b37b876..92d4a8f1 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/Create2faChallengeRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/Create2faChallengeRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateAccountRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateAccountRequestValidator.cs similarity index 93% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateAccountRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateAccountRequestValidator.cs index 3cee018f..5a7c6286 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateAccountRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateAccountRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailPasswordSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailPasswordSessionRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailPasswordSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailPasswordSessionRequestValidator.cs index 3250d0a5..e5bcdd01 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailPasswordSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailPasswordSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailTokenRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailTokenRequestValidator.cs similarity index 91% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailTokenRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailTokenRequestValidator.cs index fdaeef41..51dd5e8e 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailTokenRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailTokenRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationConfirmationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationConfirmationRequestValidator.cs similarity index 91% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationConfirmationRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationConfirmationRequestValidator.cs index da2e8067..b12fd45d 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationConfirmationRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationConfirmationRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationRequestValidator.cs similarity index 88% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationRequestValidator.cs index 67501c44..0896f0a7 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateEmailVerificationRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateEmailVerificationRequestValidator.cs @@ -1,7 +1,7 @@ using System; using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateMagicUrlTokenRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateMagicUrlTokenRequestValidator.cs similarity index 93% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateMagicUrlTokenRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateMagicUrlTokenRequestValidator.cs index 9148446f..62294926 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateMagicUrlTokenRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateMagicUrlTokenRequestValidator.cs @@ -1,7 +1,7 @@ using System; using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2SessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2SessionRequestValidator.cs similarity index 94% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2SessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2SessionRequestValidator.cs index 3619a34e..9a83befe 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2SessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2SessionRequestValidator.cs @@ -1,7 +1,7 @@ using System; using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2TokenRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2TokenRequestValidator.cs similarity index 94% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2TokenRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2TokenRequestValidator.cs index dbffb8a1..36e1e37c 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateOauth2TokenRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateOauth2TokenRequestValidator.cs @@ -1,7 +1,7 @@ using System; using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs similarity index 93% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs index cb7811b1..4e4c4999 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryConfirmationRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryRequestValidator.cs index 3fd1c6a5..1d6004b2 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePasswordRecoveryRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePasswordRecoveryRequestValidator.cs @@ -1,7 +1,7 @@ using System; using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePhoneTokenRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePhoneTokenRequestValidator.cs similarity index 93% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePhoneTokenRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePhoneTokenRequestValidator.cs index 4130c42a..b3954fb2 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreatePhoneTokenRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreatePhoneTokenRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateSessionRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/CreateSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateSessionRequestValidator.cs index c4768f39..26f7dc96 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/CreateSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/CreateSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteAuthenticatorRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteAuthenticatorRequestValidator.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteAuthenticatorRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteAuthenticatorRequestValidator.cs index 6954a40a..e40a985b 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteAuthenticatorRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteAuthenticatorRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteIdentityRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteIdentityRequestValidator.cs similarity index 85% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteIdentityRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteIdentityRequestValidator.cs index 790ec7cd..42e37c7e 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteIdentityRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteIdentityRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteSessionRequestValidator.cs similarity index 84% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteSessionRequestValidator.cs index 4ca59e00..1e32642d 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/DeleteSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/DeleteSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/GetSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/GetSessionRequestValidator.cs similarity index 83% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/GetSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/GetSessionRequestValidator.cs index 3720a164..cf3e960f 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/GetSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/GetSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListIdentitiesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListIdentitiesRequestValidator.cs new file mode 100644 index 00000000..410251a2 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListIdentitiesRequestValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; +public class ListIdentitiesRequestValidator : AbstractValidator +{ + public ListIdentitiesRequestValidator() + { + Include(new QueryBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListLogsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListLogsRequestValidator.cs new file mode 100644 index 00000000..7e2b957e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/ListLogsRequestValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; +public class ListLogsRequestValidator : AbstractValidator +{ + public ListLogsRequestValidator() + { + Include(new QueryBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateEmailRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateEmailRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateEmailRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateEmailRequestValidator.cs index 17bc51da..ead33774 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateEmailRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateEmailRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMagicUrlSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMagicUrlSessionRequestValidator.cs similarity index 91% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMagicUrlSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMagicUrlSessionRequestValidator.cs index f51395fe..5b96e66f 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMagicUrlSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMagicUrlSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMfaRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMfaRequestValidator.cs similarity index 83% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMfaRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMfaRequestValidator.cs index dcd45348..7208288c 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateMfaRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateMfaRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateNameRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateNameRequestValidator.cs similarity index 86% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateNameRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateNameRequestValidator.cs index 2e296b05..cb2f3603 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateNameRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateNameRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePasswordRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePasswordRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePasswordRequestValidator.cs index a1e40711..0639f457 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePasswordRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePasswordRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneRequestValidator.cs similarity index 90% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneRequestValidator.cs index 806ace48..0324267a 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneSessionRequestValidator.cs similarity index 91% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneSessionRequestValidator.cs index de0b2004..13018105 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs similarity index 91% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs index 522694fe..4e79efee 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePhoneVerificationConfirmationRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePreferencesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePreferencesRequestValidator.cs similarity index 85% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePreferencesRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePreferencesRequestValidator.cs index 827be9d6..ee6bcc81 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdatePreferencesRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdatePreferencesRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateSessionRequestValidator.cs similarity index 84% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateSessionRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateSessionRequestValidator.cs index 9dcd7157..e4f4105c 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/UpdateSessionRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/UpdateSessionRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/VerifyAuthenticatorRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/VerifyAuthenticatorRequestValidator.cs similarity index 87% rename from src/PinguApps.Appwrite.Shared/Requests/Validators/VerifyAuthenticatorRequestValidator.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/Validators/VerifyAuthenticatorRequestValidator.cs index ecba2802..2fa6da20 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/Validators/VerifyAuthenticatorRequestValidator.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/Validators/VerifyAuthenticatorRequestValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace PinguApps.Appwrite.Shared.Requests.Validators; +namespace PinguApps.Appwrite.Shared.Requests.Account.Validators; /// /// Validator for diff --git a/src/PinguApps.Appwrite.Shared/Requests/VerifyAuthenticatorRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Account/VerifyAuthenticatorRequest.cs similarity index 82% rename from src/PinguApps.Appwrite.Shared/Requests/VerifyAuthenticatorRequest.cs rename to src/PinguApps.Appwrite.Shared/Requests/Account/VerifyAuthenticatorRequest.cs index 81e7cec8..010b41d1 100644 --- a/src/PinguApps.Appwrite.Shared/Requests/VerifyAuthenticatorRequest.cs +++ b/src/PinguApps.Appwrite.Shared/Requests/Account/VerifyAuthenticatorRequest.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; -using PinguApps.Appwrite.Shared.Requests.Validators; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; -namespace PinguApps.Appwrite.Shared.Requests; +namespace PinguApps.Appwrite.Shared.Requests.Account; /// /// The request for Verifying an authenticator diff --git a/src/PinguApps.Appwrite.Shared/Requests/QueryBaseRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/QueryBaseRequest.cs new file mode 100644 index 00000000..f60af00f --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/QueryBaseRequest.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using FluentValidation; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Requests; + +/// +/// The base request but also containing Queries +/// +/// The request type +/// The request validator type +public abstract class QueryBaseRequest : BaseRequest + where TRequest : class + where TValidator : IValidator, new() +{ + /// + /// Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. + /// + [JsonPropertyName("queries")] + public virtual List? Queries { get; set; } = null; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/QuerySearchBaseRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/QuerySearchBaseRequest.cs new file mode 100644 index 00000000..dff037c5 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/QuerySearchBaseRequest.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests; + +/// +/// The base request but also containing queries and search +/// +/// The request type +/// The request validator type +public abstract class QuerySearchBaseRequest : QueryBaseRequest + where TRequest : class + where TValidator : IValidator, new() +{ + /// + /// Search term to filter your list results. Max length: 256 chars + /// + [JsonPropertyName("search")] + public string? Search { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateMfaRecoveryCodesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateMfaRecoveryCodesRequest.cs new file mode 100644 index 00000000..06056357 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateMfaRecoveryCodesRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating mfa recovery codes +/// +public class CreateMfaRecoveryCodesRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateSessionRequest.cs new file mode 100644 index 00000000..bb59e1fa --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateSessionRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a session +/// +public class CreateSessionRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateTokenRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateTokenRequest.cs new file mode 100644 index 00000000..682efd96 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateTokenRequest.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a token +/// +public class CreateTokenRequest : UserIdBaseRequest +{ + /// + /// Token length in characters. The default length is 6 characters + /// + [JsonPropertyName("length")] + public int? Length { get; set; } + + /// + /// Token expiration period in seconds. The default expiration is 15 minutes + /// + [JsonPropertyName("expire")] + public int? Expire { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserJwtRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserJwtRequest.cs new file mode 100644 index 00000000..2eeafac8 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserJwtRequest.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating user's JWT +/// +public class CreateUserJwtRequest : UserIdBaseRequest +{ + /// + /// Session ID. Use the string recent to use the most recent session. Defaults to the most recent session + /// + [JsonPropertyName("sessionId")] + public string? SessionId { get; set; } + + /// + /// Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds + /// + [JsonPropertyName("duration")] + public int? Duration { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserRequest.cs new file mode 100644 index 00000000..e8967efe --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserRequest.cs @@ -0,0 +1,34 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for Creating a user +/// +public class CreateUserRequest : UserIdBaseRequest +{ + /// + /// User email + /// + [JsonPropertyName("email")] + public string? Email { get; set; } + + /// + /// Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212 + /// + [JsonPropertyName("phone")] + public string? Phone { get; set; } + + /// + /// Plain text user password. Must be at least 8 chars + /// + [JsonPropertyName("password")] + public string? Password { get; set; } + + /// + /// User name. Max length: 128 chars + /// + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserTargetRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserTargetRequest.cs new file mode 100644 index 00000000..0ae20f86 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserTargetRequest.cs @@ -0,0 +1,41 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Enums; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a target for a user +/// +public class CreateUserTargetRequest : UserIdBaseRequest +{ + /// + /// Target ID. Choose a custom ID or generate a random ID with ID.unique(). Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + /// + [JsonPropertyName("targetId")] + public string TargetId { get; set; } = string.Empty; + + /// + /// The target provider type. Can be one of the following: , , + /// + [JsonPropertyName("providerType")] + public TargetProviderType ProviderType { get; set; } + + /// + /// The target identifier (token, email, phone etc.) + /// + [JsonPropertyName("identifier")] + public string Identifier { get; set; } = string.Empty; + + /// + /// Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used. + /// + [JsonPropertyName("providerId")] + public string? ProviderId { get; set; } + + /// + /// Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23 + /// + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithArgon2PasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithArgon2PasswordRequest.cs new file mode 100644 index 00000000..242d4f0e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithArgon2PasswordRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with argon2 password +/// +public class CreateUserWithArgon2PasswordRequest : CreateUserWithPasswordBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithBcryptPasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithBcryptPasswordRequest.cs new file mode 100644 index 00000000..fe438951 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithBcryptPasswordRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with bcrypt password +/// +public class CreateUserWithBcryptPasswordRequest : CreateUserWithPasswordBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithMd5PasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithMd5PasswordRequest.cs new file mode 100644 index 00000000..a68c75b0 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithMd5PasswordRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with md5 password +/// +public class CreateUserWithMd5PasswordRequest : CreateUserWithPasswordBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPasswordBaseRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPasswordBaseRequest.cs new file mode 100644 index 00000000..0e8df96b --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPasswordBaseRequest.cs @@ -0,0 +1,38 @@ +using System.Text.Json.Serialization; +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The base request containing userId, email, password and name +/// +/// The request type +/// The request validator type +public class CreateUserWithPasswordBaseRequest : BaseRequest + where TRequest : class + where TValidator : IValidator, new() +{ + /// + /// User ID. Choose a custom ID or generate a random ID with . Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + /// + [JsonPropertyName("userId")] + public string UserId { get; set; } = string.Empty; + + /// + /// User Email + /// + [JsonPropertyName("email")] + public string Email { get; set; } = string.Empty; + + /// + /// User password hashed + /// + [JsonPropertyName("password")] + public string Password { get; set; } = string.Empty; + + /// + /// User name. Max length: 128 chars + /// + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPhpassPasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPhpassPasswordRequest.cs new file mode 100644 index 00000000..fc925a7f --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithPhpassPasswordRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with phpass password +/// +public class CreateUserWithPhpassPasswordRequest : CreateUserWithPasswordBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptModifiedPasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptModifiedPasswordRequest.cs new file mode 100644 index 00000000..28ce4e51 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptModifiedPasswordRequest.cs @@ -0,0 +1,28 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with scrypt modified password +/// +public class CreateUserWithScryptModifiedPasswordRequest : CreateUserWithPasswordBaseRequest +{ + /// + /// Optional salt used to hash password + /// + [JsonPropertyName("passwordSalt")] + public string PasswordSalt { get; set; } = string.Empty; + + /// + /// Salt separator used to hash password + /// + [JsonPropertyName("passwordSaltSeparator")] + public string PasswordSaltSeparator { get; set; } = string.Empty; + + /// + /// Signer key used to hash password + /// + [JsonPropertyName("passwordSignerKey")] + public string PasswordSignerKey { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptPasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptPasswordRequest.cs new file mode 100644 index 00000000..61a1e2b9 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithScryptPasswordRequest.cs @@ -0,0 +1,40 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with scrypt password +/// +public class CreateUserWithScryptPasswordRequest : CreateUserWithPasswordBaseRequest +{ + /// + /// Optional salt used to hash password + /// + [JsonPropertyName("passwordSalt")] + public string PasswordSalt { get; set; } = string.Empty; + + /// + /// Optional CPU cost used to hash password + /// + [JsonPropertyName("passwordCpu")] + public int PasswordCpu { get; set; } + + /// + /// Optional memory cost used to hash password + /// + [JsonPropertyName("passwordMemory")] + public int PasswordMemory { get; set; } + + /// + /// Optional parallelization cost used to hash password + /// + [JsonPropertyName("passwordParallel")] + public int PasswordParallel { get; set; } + + /// + /// Optional hash length used to hash password + /// + [JsonPropertyName("passwordLength")] + public int PasswordLength { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithShaPasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithShaPasswordRequest.cs new file mode 100644 index 00000000..eb1a4240 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/CreateUserWithShaPasswordRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for creating a user with sha password +/// +public class CreateUserWithShaPasswordRequest : CreateUserWithPasswordBaseRequest +{ + /// + /// Optional SHA version used to hash password. Allowed values are: sha1, sha224, sha256, sha384, sha512/224, sha512/256, sha512, sha3-224, sha3-256, sha3-384, sha3-512 + /// + [JsonPropertyName("passwordVersion")] + public string? PasswordVersion { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteAuthenticatorRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteAuthenticatorRequest.cs new file mode 100644 index 00000000..42b042b9 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteAuthenticatorRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for deleting an authenticator +/// +public class DeleteAuthenticatorRequest : UserIdBaseRequest +{ + /// + /// Type of authenticator + /// + [JsonPropertyName("type")] + public string Type { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteIdentityRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteIdentityRequest.cs new file mode 100644 index 00000000..0da34a3d --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteIdentityRequest.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; +public class DeleteIdentityRequest : BaseRequest +{ + /// + /// Identity ID + /// + [JsonPropertyName("identityId")] + public string IdentityId { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserRequest.cs new file mode 100644 index 00000000..992d0be1 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for deleting a user +/// +public class DeleteUserRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionRequest.cs new file mode 100644 index 00000000..2b740039 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for deleting a user's session +/// +public class DeleteUserSessionRequest : UserIdBaseRequest +{ + /// + /// Session Id + /// + [JsonPropertyName("sessionId")] + public string SessionId { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionsRequest.cs new file mode 100644 index 00000000..e7d8ec33 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserSessionsRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for deleting a user's sessions +/// +public class DeleteUserSessionsRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserTargetRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserTargetRequest.cs new file mode 100644 index 00000000..839ccfa3 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/DeleteUserTargetRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for deleting a users target +/// +public class DeleteUserTargetRequest : UserIdBaseRequest +{ + /// + /// Target ID + /// + [JsonPropertyName("targetId")] + public string TargetId { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/GetMfaRecoveryCodesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/GetMfaRecoveryCodesRequest.cs new file mode 100644 index 00000000..abb4b68e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/GetMfaRecoveryCodesRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for getting mfa recovery codes +/// +public class GetMfaRecoveryCodesRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserPreferencesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserPreferencesRequest.cs new file mode 100644 index 00000000..97914936 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserPreferencesRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for getting a user's preferences +/// +public class GetUserPreferencesRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserRequest.cs new file mode 100644 index 00000000..82f44b2c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for getting a user +/// +public class GetUserRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserTargetRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserTargetRequest.cs new file mode 100644 index 00000000..347ba470 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/GetUserTargetRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for getting a user's target +/// +public class GetUserTargetRequest : UserIdBaseRequest +{ + /// + /// Target ID + /// + [JsonPropertyName("targetId")] + public string TargetId { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListFactorsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListFactorsRequest.cs new file mode 100644 index 00000000..16c2a00c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListFactorsRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing mfa factors +/// +public class ListFactorsRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListIdentitiesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListIdentitiesRequest.cs new file mode 100644 index 00000000..853dcbb0 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListIdentitiesRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing a user's identities +/// +public class ListIdentitiesRequest : QuerySearchBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserLogsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserLogsRequest.cs new file mode 100644 index 00000000..2cdc9662 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserLogsRequest.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing user's logs +/// +public class ListUserLogsRequest : UserIdBaseRequest +{ + /// + /// Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. Only supported methods are limit and offset + /// + [JsonPropertyName("queries")] + public virtual List? Queries { get; set; } = null; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserMembershipsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserMembershipsRequest.cs new file mode 100644 index 00000000..93b50ab8 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserMembershipsRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing user's memberships +/// +public class ListUserMembershipsRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserSessionsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserSessionsRequest.cs new file mode 100644 index 00000000..9b1f20df --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserSessionsRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing users's sessions +/// +public class ListUserSessionsRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserTargetsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserTargetsRequest.cs new file mode 100644 index 00000000..e7f6362c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUserTargetsRequest.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing a user's targets +/// +public class ListUserTargetsRequest : UserIdBaseRequest +{ + /// + /// Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter by the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels + /// + [JsonPropertyName("queries")] + public virtual List? Queries { get; set; } = null; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/ListUsersRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUsersRequest.cs new file mode 100644 index 00000000..b6182923 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/ListUsersRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for listing users +/// +public class ListUsersRequest : QuerySearchBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/RegenerateMfaRecoveryCodesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/RegenerateMfaRecoveryCodesRequest.cs new file mode 100644 index 00000000..7ab69a87 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/RegenerateMfaRecoveryCodesRequest.cs @@ -0,0 +1,10 @@ +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for regenerating mfa recovery codes +/// +public class RegenerateMfaRecoveryCodesRequest : UserIdBaseRequest +{ +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailRequest.cs new file mode 100644 index 00000000..f128b43c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's email +/// +public class UpdateEmailRequest : UserIdBaseRequest +{ + /// + /// User email + /// + [JsonPropertyName("email")] + public string Email { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailVerificationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailVerificationRequest.cs new file mode 100644 index 00000000..263eee0e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateEmailVerificationRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's email verification +/// +public class UpdateEmailVerificationRequest : UserIdBaseRequest +{ + /// + /// User email verification status + /// + [JsonPropertyName("emailVerification")] + public bool EmailVerification { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateMfaRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateMfaRequest.cs new file mode 100644 index 00000000..a458effa --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateMfaRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's Mfa +/// +public class UpdateMfaRequest : UserIdBaseRequest +{ + /// + /// Enable or disable MFA on a user account + /// + [JsonPropertyName("mfa")] + public bool Mfa { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateNameRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateNameRequest.cs new file mode 100644 index 00000000..214314cc --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateNameRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's name +/// +public class UpdateNameRequest : UserIdBaseRequest +{ + /// + /// User name. Max length: 128 chars + /// + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePasswordRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePasswordRequest.cs new file mode 100644 index 00000000..014fc937 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePasswordRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's password +/// +public class UpdatePasswordRequest : UserIdBaseRequest +{ + /// + /// New user password. Must be at least 8 chars + /// + [JsonPropertyName("password")] + public string Password { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneRequest.cs new file mode 100644 index 00000000..d8ffed86 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's phone +/// +public class UpdatePhoneRequest : UserIdBaseRequest +{ + /// + /// User phone number. Format this number with a leading '+' and a country code, e.g., +16175551212 + /// + [JsonPropertyName("number")] + public string PhoneNumber { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneVerificationRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneVerificationRequest.cs new file mode 100644 index 00000000..600df4b8 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdatePhoneVerificationRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's phone verification +/// +public class UpdatePhoneVerificationRequest : UserIdBaseRequest +{ + /// + /// User phone verification status + /// + [JsonPropertyName("phoneVerification")] + public bool PhoneVerification { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserLabelsRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserLabelsRequest.cs new file mode 100644 index 00000000..8233548d --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserLabelsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's labels +/// +public class UpdateUserLabelsRequest : UserIdBaseRequest +{ + /// + /// Array of user labels. Replaces the previous labels. Maximum of 1000 labels are allowed, each up to 36 alphanumeric characters long. + /// + [JsonPropertyName("labels")] + public List Labels { get; set; } = []; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserPreferencesRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserPreferencesRequest.cs new file mode 100644 index 00000000..eedc27cd --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserPreferencesRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's preferences +/// +public class UpdateUserPreferencesRequest : UserIdBaseRequest +{ + /// + /// Prefs key-value JSON object + /// + [JsonPropertyName("prefs")] + public IDictionary Preferences { get; set; } = new Dictionary(); +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserStatusRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserStatusRequest.cs new file mode 100644 index 00000000..52570840 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserStatusRequest.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user's status +/// +public class UpdateUserStatusRequest : UserIdBaseRequest +{ + /// + /// User Status. To activate the user pass true and to block the user pass false. + /// + [JsonPropertyName("status")] + public bool Status { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs new file mode 100644 index 00000000..83f4ee60 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UpdateUserTargertRequest.cs @@ -0,0 +1,34 @@ +using System.Text.Json.Serialization; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The request for updating a user target +/// +public class UpdateUserTargertRequest : UserIdBaseRequest +{ + /// + /// Target ID + /// + [JsonPropertyName("targetId")] + public string TargetId { get; set; } = string.Empty; + + /// + /// The target identifier (token, email, phone etc.) + /// + [JsonPropertyName("identifier")] + public string? Identifier { get; set; } + + /// + /// Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used + /// + [JsonPropertyName("providerId")] + public string? ProviderId { get; set; } + + /// + /// Target name. Max length: 128 chars. For example: My Awesome App Galaxy S23. + /// + [JsonPropertyName("name")] + public string? Name { get; set; } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/UserIdBaseRequest.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/UserIdBaseRequest.cs new file mode 100644 index 00000000..b18ad376 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/UserIdBaseRequest.cs @@ -0,0 +1,20 @@ +using System.Text.Json.Serialization; +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users; + +/// +/// The base request but also containing UserId +/// +/// The request type +/// The request validator type +public abstract class UserIdBaseRequest : BaseRequest + where TRequest : class + where TValidator : IValidator, new() +{ + /// + /// User ID. Choose a custom ID or generate a random ID with . Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + /// + [JsonPropertyName("userId")] + public string UserId { get; set; } = string.Empty; +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateMfaRecoveryCodesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateMfaRecoveryCodesRequestValidator.cs new file mode 100644 index 00000000..37824462 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateMfaRecoveryCodesRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateMfaRecoveryCodesRequestValidator : AbstractValidator +{ + public CreateMfaRecoveryCodesRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateSessionRequestValidator.cs new file mode 100644 index 00000000..d4c935d1 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateSessionRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateSessionRequestValidator : AbstractValidator +{ + public CreateSessionRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateTokenRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateTokenRequestValidator.cs new file mode 100644 index 00000000..f32d3332 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateTokenRequestValidator.cs @@ -0,0 +1,20 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateTokenRequestValidator : AbstractValidator +{ + public CreateTokenRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Length) + .GreaterThan(0) + .WithMessage("Token length must be greater than 0.") + .When(x => x.Length.HasValue); + + RuleFor(x => x.Expire) + .GreaterThan(0) + .WithMessage("Token expiration must be greater than 0 seconds.") + .When(x => x.Expire.HasValue); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserJwtRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserJwtRequestValidator.cs new file mode 100644 index 00000000..952b1c39 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserJwtRequestValidator.cs @@ -0,0 +1,20 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserJwtRequestValidator : AbstractValidator +{ + public CreateUserJwtRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.SessionId) + .NotEmpty() + .When(x => x.SessionId is not null) + .WithMessage("Session ID must be null or a non-empty string."); + + RuleFor(x => x.Duration) + .GreaterThanOrEqualTo(0).WithMessage("Duration must be at least 0 seconds.") + .LessThanOrEqualTo(3600).WithMessage("Duration must be at most 3600 seconds.") + .When(x => x.Duration.HasValue); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserRequestValidator.cs new file mode 100644 index 00000000..73d70729 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserRequestValidator.cs @@ -0,0 +1,33 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserRequestValidator : AbstractValidator +{ + public CreateUserRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(request => request.Email) + .EmailAddress() + .When(x => x.Email is not null) + .WithMessage("Invalid email format."); + + RuleFor(request => request.Phone) + .Matches(@"^\+\d{1,15}$") + .When(x => x.Phone is not null) + .WithMessage("Phone number must be in the format +123456789."); + + RuleFor(request => request.Password) + .MinimumLength(8) + .When(x => x.Password is not null) + .WithMessage("Password must be at least 8 characters long."); + + RuleFor(request => request.Name) + .NotEmpty() + .When(x => x.Name is not null) + .WithMessage("Name must not be an empty string.") + .MaximumLength(128) + .When(x => x.Name is not null) + .WithMessage("Name must not exceed 128 characters."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserTargetRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserTargetRequestValidator.cs new file mode 100644 index 00000000..d81f85f0 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserTargetRequestValidator.cs @@ -0,0 +1,36 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserTargetRequestValidator : AbstractValidator +{ + public CreateUserTargetRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.TargetId) + .NotEmpty() + .WithMessage("TargetId is required.") + .Matches("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$") + .WithMessage("TargetId must be 1-36 characters long and can contain letters, numbers, periods, hyphens, and underscores. It cannot start with a special character."); + + RuleFor(x => x.ProviderType) + .IsInEnum() + .WithMessage("ProviderType must be a valid enum value."); + + RuleFor(x => x.Identifier) + .NotEmpty() + .WithMessage("Identifier is required."); + + RuleFor(x => x.ProviderId) + .NotEmpty() + .When(x => x.ProviderId is not null) + .WithMessage("Identifier must either be null or have a non empty string value."); + + RuleFor(x => x.Name) + .NotEmpty() + .When(x => x.Name is not null) + .WithMessage("Name must either be null or have a non empty string value.") + .MaximumLength(128) + .WithMessage("Name must be at most 128 characters long."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithArgon2PasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithArgon2PasswordRequestValidator.cs new file mode 100644 index 00000000..ad894bd6 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithArgon2PasswordRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithArgon2PasswordRequestValidator : AbstractValidator +{ + public CreateUserWithArgon2PasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithBcryptPasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithBcryptPasswordRequestValidator.cs new file mode 100644 index 00000000..76791250 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithBcryptPasswordRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithBcryptPasswordRequestValidator : AbstractValidator +{ + public CreateUserWithBcryptPasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithMd5PasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithMd5PasswordRequestValidator.cs new file mode 100644 index 00000000..0da7bd1b --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithMd5PasswordRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithMd5PasswordRequestValidator : AbstractValidator +{ + public CreateUserWithMd5PasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPasswordBaseRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPasswordBaseRequestValidator.cs new file mode 100644 index 00000000..aa559b1a --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPasswordBaseRequestValidator.cs @@ -0,0 +1,28 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithPasswordBaseRequestValidator : AbstractValidator> + where TRequest : class + where TValidator : IValidator, new() +{ + public CreateUserWithPasswordBaseRequestValidator() + { + RuleFor(x => x.UserId) + .NotEmpty().WithMessage("UserId is required.") + .Matches("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$").WithMessage("UserId can only contain a-z, A-Z, 0-9, period, hyphen, and underscore, and can't start with a special char. Max length is 36 chars."); + + RuleFor(x => x.Email) + .NotEmpty().WithMessage("Email is required.") + .EmailAddress().WithMessage("Invalid email format."); + + RuleFor(x => x.Password) + .NotEmpty().WithMessage("Password is required."); + + RuleFor(x => x.Name) + .NotEmpty() + .When(x => x.Name is not null) + .WithMessage("Name must not be an empty string.") + .MaximumLength(128) + .WithMessage("Name must be at most 128 characters long."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPhpassPasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPhpassPasswordRequestValidator.cs new file mode 100644 index 00000000..6d8ceaa5 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithPhpassPasswordRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithPhpassPasswordRequestValidator : AbstractValidator +{ + public CreateUserWithPhpassPasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptModifiedPasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptModifiedPasswordRequestValidator.cs new file mode 100644 index 00000000..32109d7f --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptModifiedPasswordRequestValidator.cs @@ -0,0 +1,22 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithScryptModifiedPasswordRequestValidator : AbstractValidator +{ + public CreateUserWithScryptModifiedPasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + + RuleFor(x => x.PasswordSalt) + .NotEmpty() + .WithMessage("PasswordSalt is required."); + + RuleFor(x => x.PasswordSaltSeparator) + .NotEmpty() + .WithMessage("PasswordSaltSeparator is required."); + + RuleFor(x => x.PasswordSignerKey) + .NotEmpty() + .WithMessage("PasswordSignerKey is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptPasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptPasswordRequestValidator.cs new file mode 100644 index 00000000..87701f4e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithScryptPasswordRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithScryptPasswordRequestValidator : AbstractValidator +{ + public CreateUserWithScryptPasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + + RuleFor(x => x.PasswordSalt) + .NotEmpty() + .WithMessage("PasswordSalt is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithShaPasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithShaPasswordRequestValidator.cs new file mode 100644 index 00000000..89cc0a09 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/CreateUserWithShaPasswordRequestValidator.cs @@ -0,0 +1,26 @@ +using System; +using System.Linq; +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class CreateUserWithShaPasswordRequestValidator : AbstractValidator +{ + private static readonly string[] AllowedPasswordVersions = + { + "sha1", "sha224", "sha256", "sha384", "sha512/224", "sha512/256", "sha512", "sha3-224", "sha3-256", "sha3-384", "sha3-512" + }; + + public CreateUserWithShaPasswordRequestValidator() + { + Include(new CreateUserWithPasswordBaseRequestValidator()); + + RuleFor(x => x.PasswordVersion) + .Must(BeAValidPasswordVersion) + .WithMessage("Invalid password version."); + } + + private bool BeAValidPasswordVersion(string? passwordVersion) + { + return passwordVersion is null || AllowedPasswordVersions.Contains(passwordVersion); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteAuthenticatorRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteAuthenticatorRequestValidator.cs new file mode 100644 index 00000000..8860418c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteAuthenticatorRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteAuthenticatorRequestValidator : AbstractValidator +{ + public DeleteAuthenticatorRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Type) + .NotEmpty() + .WithMessage("Type is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteIdentityRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteIdentityRequestValidator.cs new file mode 100644 index 00000000..aa42cc63 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteIdentityRequestValidator.cs @@ -0,0 +1,12 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteIdentityRequestValidator : AbstractValidator +{ + public DeleteIdentityRequestValidator() + { + RuleFor(x => x.IdentityId) + .NotEmpty() + .WithMessage("IdentityId is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserRequestValidator.cs new file mode 100644 index 00000000..59554051 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteUserRequestValidator : AbstractValidator +{ + public DeleteUserRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionRequestValidator.cs new file mode 100644 index 00000000..3c5e5470 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteUserSessionRequestValidator : AbstractValidator +{ + public DeleteUserSessionRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.SessionId) + .NotEmpty() + .WithMessage("SessionId is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionsRequestValidator.cs new file mode 100644 index 00000000..c5efe326 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserSessionsRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteUserSessionsRequestValidator : AbstractValidator +{ + public DeleteUserSessionsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserTargetRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserTargetRequestValidator.cs new file mode 100644 index 00000000..35a483df --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/DeleteUserTargetRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class DeleteUserTargetRequestValidator : AbstractValidator +{ + public DeleteUserTargetRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.TargetId) + .NotEmpty() + .WithMessage("Target ID is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetMfaRecoveryCodesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetMfaRecoveryCodesRequestValidator.cs new file mode 100644 index 00000000..348a1ca5 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetMfaRecoveryCodesRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class GetMfaRecoveryCodesRequestValidator : AbstractValidator +{ + public GetMfaRecoveryCodesRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserPreferencesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserPreferencesRequestValidator.cs new file mode 100644 index 00000000..6a90ec03 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserPreferencesRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class GetUserPreferencesRequestValidator : AbstractValidator +{ + public GetUserPreferencesRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserRequestValidator.cs new file mode 100644 index 00000000..d809af12 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class GetUserRequestValidator : AbstractValidator +{ + public GetUserRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserTargetRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserTargetRequestValidator.cs new file mode 100644 index 00000000..462e7dcc --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/GetUserTargetRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class GetUserTargetRequestValidator : AbstractValidator +{ + public GetUserTargetRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.TargetId) + .NotEmpty() + .WithMessage("TargetId is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListFactorsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListFactorsRequestValidator.cs new file mode 100644 index 00000000..1593e40c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListFactorsRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListFactorsRequestValidator : AbstractValidator +{ + public ListFactorsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListIdentitiesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListIdentitiesRequestValidator.cs new file mode 100644 index 00000000..2885851a --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListIdentitiesRequestValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListIdentitiesRequestValidator : AbstractValidator +{ + public ListIdentitiesRequestValidator() + { + Include(new QuerySearchBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserLogsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserLogsRequestValidator.cs new file mode 100644 index 00000000..df0c756e --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserLogsRequestValidator.cs @@ -0,0 +1,20 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListUserLogsRequestValidator : AbstractValidator +{ + public ListUserLogsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Queries) + .Must(queries => queries is null || queries.Count <= 100) + .WithMessage("A maximum of 100 queries are allowed.") + .ForEach(queryRule => queryRule + .Must(query => query.GetQueryString().Length <= 4096) + .WithMessage("Each query must be at most 4096 characters long.") + .Must(x => x.Method == "limit" || x.Method == "offset") + .WithMessage("Only supported query methods are limit and offset") + ); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserMembershipsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserMembershipsRequestValidator.cs new file mode 100644 index 00000000..d31e7a47 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserMembershipsRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListUserMembershipsRequestValidator : AbstractValidator +{ + public ListUserMembershipsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserSessionsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserSessionsRequestValidator.cs new file mode 100644 index 00000000..abeaa794 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserSessionsRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListUserSessionsRequestValidator : AbstractValidator +{ + public ListUserSessionsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserTargetsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserTargetsRequestValidator.cs new file mode 100644 index 00000000..fb91c1fc --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUserTargetsRequestValidator.cs @@ -0,0 +1,29 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListUserTargetsRequestValidator : AbstractValidator +{ + public ListUserTargetsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Queries) + .Must(queries => queries is null || queries.Count <= 100) + .WithMessage("A maximum of 100 queries are allowed.") + .ForEach(queryRule => queryRule + .Must(query => query.GetQueryString().Length <= 4096) + .WithMessage("Each query must be at most 4096 characters long.") + .Must(x => x.Attribute is null || + x.Attribute == "name" || + x.Attribute == "email" || + x.Attribute == "phone" || + x.Attribute == "status" || + x.Attribute == "passwordUpdate" || + x.Attribute == "registration" || + x.Attribute == "emailVerification" || + x.Attribute == "phoneVerification" || + x.Attribute == "labels") + .WithMessage("Only supported query attributes are name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels.") + ); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUsersRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUsersRequestValidator.cs new file mode 100644 index 00000000..21a370a9 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/ListUsersRequestValidator.cs @@ -0,0 +1,11 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Validators; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class ListUsersRequestValidator : AbstractValidator +{ + public ListUsersRequestValidator() + { + Include(new QuerySearchBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/RegenerateMfaRecoveryCodesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/RegenerateMfaRecoveryCodesRequestValidator.cs new file mode 100644 index 00000000..66326f5f --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/RegenerateMfaRecoveryCodesRequestValidator.cs @@ -0,0 +1,10 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class RegenerateMfaRecoveryCodesRequestValidator : AbstractValidator +{ + public RegenerateMfaRecoveryCodesRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailRequestValidator.cs new file mode 100644 index 00000000..3d16d57c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateEmailRequestValidator : AbstractValidator +{ + public UpdateEmailRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Email) + .NotEmpty().WithMessage("Email is required.") + .EmailAddress().WithMessage("Invalid email format."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailVerificationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailVerificationRequestValidator.cs new file mode 100644 index 00000000..c39ae55d --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateEmailVerificationRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateEmailVerificationRequestValidator : AbstractValidator +{ + public UpdateEmailVerificationRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.EmailVerification) + .NotNull() + .WithMessage("Email verification status is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateMfaRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateMfaRequestValidator.cs new file mode 100644 index 00000000..fb168b8c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateMfaRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateMfaRequestValidator : AbstractValidator +{ + public UpdateMfaRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Mfa) + .NotNull() + .WithMessage("Mfa must be specified."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateNameRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateNameRequestValidator.cs new file mode 100644 index 00000000..b2e1775a --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateNameRequestValidator.cs @@ -0,0 +1,16 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateNameRequestValidator : AbstractValidator +{ + public UpdateNameRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Name) + .NotEmpty() + .WithMessage("Name is required.") + .MaximumLength(128) + .WithMessage("Name must be at most 128 characters long."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePasswordRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePasswordRequestValidator.cs new file mode 100644 index 00000000..4a4c1d49 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePasswordRequestValidator.cs @@ -0,0 +1,16 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdatePasswordRequestValidator : AbstractValidator +{ + public UpdatePasswordRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Password) + .NotEmpty() + .WithMessage("Password is required.") + .MinimumLength(8) + .WithMessage("Password must be at least 8 characters long."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneRequestValidator.cs new file mode 100644 index 00000000..499095f0 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneRequestValidator.cs @@ -0,0 +1,16 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdatePhoneRequestValidator : AbstractValidator +{ + public UpdatePhoneRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.PhoneNumber) + .NotEmpty() + .WithMessage("Phone number is required.") + .Matches(@"^\+\d{1,15}$") + .WithMessage("Phone number must be in the format '+[country code][number]', e.g., +16175551212."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneVerificationRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneVerificationRequestValidator.cs new file mode 100644 index 00000000..280b0e9f --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdatePhoneVerificationRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdatePhoneVerificationRequestValidator : AbstractValidator +{ + public UpdatePhoneVerificationRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.PhoneVerification) + .NotNull() + .WithMessage("Phone verification status is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserLabelsRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserLabelsRequestValidator.cs new file mode 100644 index 00000000..92e39587 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserLabelsRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateUserLabelsRequestValidator : AbstractValidator +{ + public UpdateUserLabelsRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Labels) + .NotNull().WithMessage("Labels cannot be null.") + .Must(labels => labels.Count <= 1000).WithMessage("A maximum of 1000 labels are allowed.") + .ForEach(labelRule => labelRule + .NotEmpty().WithMessage("Label cannot be empty.") + .MaximumLength(36).WithMessage("Label must be at most 36 characters long.") + .Matches("^[a-zA-Z0-9]*$").WithMessage("Label must be alphanumeric.") + ); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserPreferencesRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserPreferencesRequestValidator.cs new file mode 100644 index 00000000..5d64b69b --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserPreferencesRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateUserPreferencesRequestValidator : AbstractValidator +{ + public UpdateUserPreferencesRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Preferences) + .NotNull() + .WithMessage("Preferences cannot be null."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserStatusRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserStatusRequestValidator.cs new file mode 100644 index 00000000..f6b0eaad --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserStatusRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateUserStatusRequestValidator : AbstractValidator +{ + public UpdateUserStatusRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.Status) + .NotNull() + .WithMessage("Status is required."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserTargertRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserTargertRequestValidator.cs new file mode 100644 index 00000000..9c7527a6 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UpdateUserTargertRequestValidator.cs @@ -0,0 +1,31 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UpdateUserTargertRequestValidator : AbstractValidator +{ + public UpdateUserTargertRequestValidator() + { + Include(new UserIdBaseRequestValidator()); + + RuleFor(x => x.TargetId) + .NotEmpty() + .WithMessage("Target ID is required."); + + RuleFor(x => x.Identifier) + .NotEmpty() + .WithMessage("Identifier must either be null or a non empty string.") + .When(x => x.Identifier != null); + + RuleFor(x => x.ProviderId) + .NotEmpty() + .WithMessage("Provider must either be null or a non empty string.") + .When(x => x.ProviderId != null); + + RuleFor(x => x.Name) + .MaximumLength(128) + .WithMessage("Name cannot exceed 128 characters.") + .NotEmpty() + .WithMessage("Name must either be null or a non empty string.") + .When(x => x.Name != null); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UserIdBaseRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UserIdBaseRequestValidator.cs new file mode 100644 index 00000000..2ac3901c --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Users/Validators/UserIdBaseRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Users.Validators; +public class UserIdBaseRequestValidator : AbstractValidator> + where TRequest : class + where TValidator : IValidator, new() +{ + public UserIdBaseRequestValidator() + { + RuleFor(x => x.UserId) + .NotEmpty().WithMessage("UserId is required.") + .Matches("^[a-zA-Z0-9][a-zA-Z0-9._-]{0,35}$").WithMessage("UserId can only contain a-z, A-Z, 0-9, period, hyphen, and underscore, and can't start with a special char. Max length is 36 chars."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/QueryBaseRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Validators/QueryBaseRequestValidator.cs new file mode 100644 index 00000000..0981f1fe --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Validators/QueryBaseRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Validators; +public class QueryBaseRequestValidator : AbstractValidator> + where TRequest : class + where TValidator : IValidator, new() +{ + public QueryBaseRequestValidator() + { + RuleFor(x => x.Queries) + .Must(queries => queries is null || queries.Count <= 100).WithMessage("A maximum of 100 queries are allowed.") + .ForEach(query => query.Must(q => q.GetQueryString().Length <= 4096).WithMessage("Each query can be a maximum of 4096 characters long.")); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Requests/Validators/QuerySearchBaseRequestValidator.cs b/src/PinguApps.Appwrite.Shared/Requests/Validators/QuerySearchBaseRequestValidator.cs new file mode 100644 index 00000000..0ddcedb4 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Requests/Validators/QuerySearchBaseRequestValidator.cs @@ -0,0 +1,16 @@ +using FluentValidation; + +namespace PinguApps.Appwrite.Shared.Requests.Validators; +public class QuerySearchBaseRequestValidator : AbstractValidator> + where TRequest : class + where TValidator : IValidator, new() +{ + public QuerySearchBaseRequestValidator() + { + Include(new QueryBaseRequestValidator()); + + RuleFor(request => request.Search) + .MaximumLength(256) + .WithMessage("Search term must not exceed 256 characters."); + } +} diff --git a/src/PinguApps.Appwrite.Shared/Responses/Membership.cs b/src/PinguApps.Appwrite.Shared/Responses/Membership.cs new file mode 100644 index 00000000..2046f3aa --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Responses/Membership.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace PinguApps.Appwrite.Shared.Responses; + +/// +/// An Appwrite Membership object +/// +/// Membership ID +/// Membership creation date in ISO 8601 format +/// Membership update date in ISO 8601 format +/// User ID +/// User name +/// User email address +/// Team ID +/// Team name +/// Date, the user has been invited to join the team in ISO 8601 format +/// Date, the user has accepted the invitation to join the team in ISO 8601 format +/// User confirmation status, true if the user has joined the team or false otherwise +/// Multi factor authentication status, true if the user has MFA enabled or false otherwise +/// User list of roles +public record Membership( + [property: JsonPropertyName("$id")] string Id, + [property: JsonPropertyName("$createdAt")] DateTime CreatedAt, + [property: JsonPropertyName("$updatedAt")] DateTime UpdatedAt, + [property: JsonPropertyName("userId")] string UserId, + [property: JsonPropertyName("userName")] string UserName, + [property: JsonPropertyName("userEmail")] string UserEmail, + [property: JsonPropertyName("teamId")] string TeamId, + [property: JsonPropertyName("teamName")] string TeamName, + [property: JsonPropertyName("invited")] DateTime Invited, + [property: JsonPropertyName("joined")] DateTime Joined, + [property: JsonPropertyName("confirm")] bool Confirm, + [property: JsonPropertyName("mfa")] bool Mfa, + [property: JsonPropertyName("roles")] List Roles +); diff --git a/src/PinguApps.Appwrite.Shared/Responses/MembershipsList.cs b/src/PinguApps.Appwrite.Shared/Responses/MembershipsList.cs new file mode 100644 index 00000000..447387c7 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Responses/MembershipsList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace PinguApps.Appwrite.Shared.Responses; + +/// +/// An Appwrite MembershipsList object +/// +/// Total number of memberships documents that matched your query +/// List of memberships. Can be one of: +public record MembershipsList( + [property: JsonPropertyName("total")] int Total, + [property: JsonPropertyName("memberships")] List Memberships +); diff --git a/src/PinguApps.Appwrite.Shared/Responses/TargetList.cs b/src/PinguApps.Appwrite.Shared/Responses/TargetList.cs new file mode 100644 index 00000000..33e28a1b --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Responses/TargetList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace PinguApps.Appwrite.Shared.Responses; + +/// +/// An Appwrite Target List object +/// +/// Total number of targets documents that matched your query +/// List of targets. Can be one of: +public record TargetList( + [property: JsonPropertyName("total")] int Total, + [property: JsonPropertyName("targets")] IReadOnlyList Targets +); diff --git a/src/PinguApps.Appwrite.Shared/Responses/UsersList.cs b/src/PinguApps.Appwrite.Shared/Responses/UsersList.cs new file mode 100644 index 00000000..b5112231 --- /dev/null +++ b/src/PinguApps.Appwrite.Shared/Responses/UsersList.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace PinguApps.Appwrite.Shared.Responses; + +/// +/// An Apwrite Users List object +/// +/// Total number of users documents that matched your query +/// List of users. Can be one of: +public record UsersList( + [property: JsonPropertyName("total")] int Total, + [property: JsonPropertyName("users")] IReadOnlyList Users +); diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.AddAuthenticator.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.AddAuthenticator.cs index 09bf07f5..92d300d4 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.AddAuthenticator.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.AddAuthenticator.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create.cs index c8e57e36..5b69eaed 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallenge.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallenge.cs index 8c2163f2..46516628 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallenge.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallenge.cs @@ -2,7 +2,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallengeConfirmation.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallengeConfirmation.cs index d1af2a74..c9e72441 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallengeConfirmation.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.Create2faChallengeConfirmation.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using PinguApps.Appwrite.Shared.Utils; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailPasswordSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailPasswordSession.cs index c237f09d..8f11e27f 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailPasswordSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailPasswordSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailToken.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailToken.cs index f0b456ec..bd0a0bd1 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailToken.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerification.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerification.cs index ff598a4e..bb868ad6 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerification.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerification.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerificationConfirmation.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerificationConfirmation.cs index 4acef7d7..88fce1cd 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerificationConfirmation.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateEmailVerificationConfirmation.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateMagicUrlToken.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateMagicUrlToken.cs index 5a5ec516..66295770 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateMagicUrlToken.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateMagicUrlToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Session.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Session.cs index 67aa69d1..88256806 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Session.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Session.cs @@ -1,4 +1,4 @@ -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; namespace PinguApps.Appwrite.Client.Tests.Clients.Account; public partial class AccountClientTests diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Token.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Token.cs index 23f88b5c..9d86f327 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Token.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateOauth2Token.cs @@ -1,4 +1,4 @@ -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; namespace PinguApps.Appwrite.Client.Tests.Clients.Account; public partial class AccountClientTests diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecovery.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecovery.cs index 5f214cb4..bd3b0456 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecovery.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecovery.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecoveryConfirmation.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecoveryConfirmation.cs index 7004e245..db0659e7 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecoveryConfirmation.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePasswordRecoveryConfirmation.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePhoneToken.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePhoneToken.cs index 20ca556e..80bc8769 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePhoneToken.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreatePhoneToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateSesssion.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateSesssion.cs index 9c285c37..08942734 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateSesssion.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.CreateSesssion.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteAuthenticator.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteAuthenticator.cs index ed80a453..09de6479 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteAuthenticator.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteAuthenticator.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteIdentity.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteIdentity.cs index 8b7daafc..465cbda5 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteIdentity.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteIdentity.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteSession.cs index 98861d41..35f74492 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.DeleteSession.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.GetSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.GetSession.cs index 9c7ba436..c31ef18f 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.GetSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.GetSession.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListIdentities.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListIdentities.cs index 5dbc0f3a..19443d73 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListIdentities.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListIdentities.cs @@ -1,5 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using PinguApps.Appwrite.Shared.Utils; using RichardSzalay.MockHttp; @@ -11,6 +12,8 @@ public partial class AccountClientTests public async Task ListIdentities_ShouldReturnSuccess_WhenApiCallSucceeds() { // Arrange + var request = new ListIdentitiesRequest(); + _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/identities") .ExpectedHeaders(true) .Respond(Constants.AppJson, Constants.IdentitiesListResponse); @@ -18,7 +21,7 @@ public async Task ListIdentities_ShouldReturnSuccess_WhenApiCallSucceeds() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListIdentities(); + var result = await _appwriteClient.Account.ListIdentities(request); // Assert Assert.True(result.Success); @@ -29,6 +32,10 @@ public async Task ListIdentities_ShouldProvideQueries_WhenQueriesProvided() { // Arrange var query = Query.Limit(5); + var request = new ListIdentitiesRequest() + { + Queries = [query] + }; _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/identities") .ExpectedHeaders(true) @@ -38,7 +45,7 @@ public async Task ListIdentities_ShouldProvideQueries_WhenQueriesProvided() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListIdentities([query]); + var result = await _appwriteClient.Account.ListIdentities(request); // Assert Assert.True(result.Success); @@ -47,8 +54,11 @@ public async Task ListIdentities_ShouldProvideQueries_WhenQueriesProvided() [Fact] public async Task ListIdentities_ShouldReturnError_WhenSessionIsNull() { + // Arrange + var request = new ListIdentitiesRequest(); + // Act - var result = await _appwriteClient.Account.ListLogs(); + var result = await _appwriteClient.Account.ListIdentities(request); // Assert Assert.True(result.IsError); @@ -60,6 +70,8 @@ public async Task ListIdentities_ShouldReturnError_WhenSessionIsNull() public async Task ListIdentities_ShouldHandleException_WhenApiCallFails() { // Arrange + var request = new ListIdentitiesRequest(); + _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/identities") .ExpectedHeaders(true) .Respond(HttpStatusCode.BadRequest, Constants.AppJson, Constants.AppwriteError); @@ -67,7 +79,7 @@ public async Task ListIdentities_ShouldHandleException_WhenApiCallFails() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListIdentities(); + var result = await _appwriteClient.Account.ListIdentities(request); // Assert Assert.True(result.IsError); @@ -78,6 +90,8 @@ public async Task ListIdentities_ShouldHandleException_WhenApiCallFails() public async Task ListIdentities_ShouldReturnErrorResponse_WhenExceptionOccurs() { // Arrange + var request = new ListIdentitiesRequest(); + _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/identities") .ExpectedHeaders(true) .Throw(new HttpRequestException("An error occurred")); @@ -85,7 +99,7 @@ public async Task ListIdentities_ShouldReturnErrorResponse_WhenExceptionOccurs() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListIdentities(); + var result = await _appwriteClient.Account.ListIdentities(request); // Assert Assert.False(result.Success); diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListLogs.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListLogs.cs index 0e10c60c..b2922fc6 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListLogs.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.ListLogs.cs @@ -1,5 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using PinguApps.Appwrite.Shared.Utils; using RichardSzalay.MockHttp; @@ -11,6 +12,8 @@ public partial class AccountClientTests public async Task ListLogs_ShouldReturnSuccess_WhenApiCallSucceeds() { // Arrange + var request = new ListLogsRequest(); + _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/logs") .ExpectedHeaders(true) .Respond(Constants.AppJson, Constants.LogsListResponse); @@ -18,7 +21,7 @@ public async Task ListLogs_ShouldReturnSuccess_WhenApiCallSucceeds() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListLogs(); + var result = await _appwriteClient.Account.ListLogs(request); // Assert Assert.True(result.Success); @@ -29,6 +32,10 @@ public async Task ListLogs_ShouldProvideQueries_WhenQueriesProvided() { // Arrange var query = Query.Limit(5); + var request = new ListLogsRequest + { + Queries = [query] + }; _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/logs") .ExpectedHeaders(true) @@ -38,7 +45,7 @@ public async Task ListLogs_ShouldProvideQueries_WhenQueriesProvided() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListLogs([query]); + var result = await _appwriteClient.Account.ListLogs(request); // Assert Assert.True(result.Success); @@ -47,8 +54,11 @@ public async Task ListLogs_ShouldProvideQueries_WhenQueriesProvided() [Fact] public async Task ListLogs_ShouldReturnError_WhenSessionIsNull() { + // Arrange + var request = new ListLogsRequest(); + // Act - var result = await _appwriteClient.Account.ListLogs(); + var result = await _appwriteClient.Account.ListLogs(request); // Assert Assert.True(result.IsError); @@ -59,6 +69,9 @@ public async Task ListLogs_ShouldReturnError_WhenSessionIsNull() [Fact] public async Task ListLogs_ShouldHandleException_WhenApiCallFails() { + // Arrange + var request = new ListLogsRequest(); + // Arrange _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/logs") .ExpectedHeaders(true) @@ -67,7 +80,7 @@ public async Task ListLogs_ShouldHandleException_WhenApiCallFails() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListLogs(); + var result = await _appwriteClient.Account.ListLogs(request); // Assert Assert.True(result.IsError); @@ -77,6 +90,9 @@ public async Task ListLogs_ShouldHandleException_WhenApiCallFails() [Fact] public async Task ListLogs_ShouldReturnErrorResponse_WhenExceptionOccurs() { + // Arrange + var request = new ListLogsRequest(); + // Arrange _mockHttp.Expect(HttpMethod.Get, $"{Constants.Endpoint}/account/logs") .ExpectedHeaders(true) @@ -85,7 +101,7 @@ public async Task ListLogs_ShouldReturnErrorResponse_WhenExceptionOccurs() _appwriteClient.SetSession(Constants.Session); // Act - var result = await _appwriteClient.Account.ListLogs(); + var result = await _appwriteClient.Account.ListLogs(request); // Assert Assert.False(result.Success); diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateEmail.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateEmail.cs index acbe26d8..4527b331 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateEmail.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateEmail.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMagicUrlSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMagicUrlSession.cs index 5b2f2f0a..92d96718 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMagicUrlSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMagicUrlSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMfa.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMfa.cs index 4a78658b..74cea47b 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMfa.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateMfa.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateName.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateName.cs index 5dcd0a13..45323ee7 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateName.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateName.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePassword.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePassword.cs index 13b74ac5..574ff7ef 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePassword.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePassword.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhone.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhone.cs index a9fa0ef0..5d1b7a06 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhone.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhone.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneSession.cs index 3cd12043..114edc97 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneVerificationConfirmation.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneVerificationConfirmation.cs index 18615033..80ca72f4 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneVerificationConfirmation.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePhoneVerificationConfirmation.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePreferences.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePreferences.cs index 70d92f56..fe6cae01 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePreferences.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdatePreferences.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateSession.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateSession.cs index 87c5a8a3..a5995d5e 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateSession.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.UpdateSession.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using PinguApps.Appwrite.Shared.Utils; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.VerifyAuthenticator.cs b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.VerifyAuthenticator.cs index 4b2bcb8c..509628f9 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.VerifyAuthenticator.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Clients/Account/AccountClientTests.VerifyAuthenticator.cs @@ -1,6 +1,6 @@ using System.Net; using PinguApps.Appwrite.Client.Clients; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Client.Tests/Handlers/HeaderHandlerTests.cs b/tests/PinguApps.Appwrite.Client.Tests/Handlers/HeaderHandlerTests.cs index 89259ef9..caeda2d8 100644 --- a/tests/PinguApps.Appwrite.Client.Tests/Handlers/HeaderHandlerTests.cs +++ b/tests/PinguApps.Appwrite.Client.Tests/Handlers/HeaderHandlerTests.cs @@ -1,6 +1,7 @@ using Moq; using Moq.Protected; using PinguApps.Appwrite.Client.Handlers; +using PinguApps.Appwrite.Shared; using PinguApps.Appwrite.Shared.Tests; namespace PinguApps.Appwrite.Client.Tests.Handlers; @@ -20,7 +21,9 @@ public async Task SendAsync_AddsRequiredHeaders() .ReturnsAsync(new HttpResponseMessage()) .Verifiable(); - var headerHandler = new HeaderHandler(Constants.ProjectId) + var config = new Config(Constants.Endpoint, Constants.ProjectId); + + var headerHandler = new HeaderHandler(config) { InnerHandler = mockInnerHandler.Object }; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Handlers/HeaderHandlerTests.cs b/tests/PinguApps.Appwrite.Server.Tests/Handlers/HeaderHandlerTests.cs index 9be219e4..07977a80 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Handlers/HeaderHandlerTests.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Handlers/HeaderHandlerTests.cs @@ -1,6 +1,7 @@ using Moq; using Moq.Protected; using PinguApps.Appwrite.Server.Handlers; +using PinguApps.Appwrite.Shared; using PinguApps.Appwrite.Shared.Tests; namespace PinguApps.Appwrite.Server.Tests.Handlers; @@ -20,7 +21,9 @@ public async Task SendAsync_AddsRequiredHeaders() .ReturnsAsync(new HttpResponseMessage()) .Verifiable(); - var headerHandler = new HeaderHandler(Constants.ProjectId, Constants.ApiKey) + var config = new Config(Constants.Endpoint, Constants.ProjectId, Constants.ApiKey); + + var headerHandler = new HeaderHandler(config) { InnerHandler = mockInnerHandler.Object }; @@ -41,4 +44,15 @@ public async Task SendAsync_AddsRequiredHeaders() ItExpr.IsAny() ); } + + [Fact] + public void Constructor_ShouldThrowArgumentNullException_WhenApiKeyIsNull() + { + // Arrange + var config = new Config(Constants.Endpoint, Constants.ProjectId, null); + + // Act & Assert + var exception = Assert.Throws(() => new HeaderHandler(config)); + Assert.Equal("config.ApiKey", exception.ParamName); + } } diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.Create.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.Create.cs index cd78a877..fb551f77 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.Create.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.Create.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailPasswordSession.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailPasswordSession.cs index 0ca83383..0d903797 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailPasswordSession.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailPasswordSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailToken.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailToken.cs index 5e91c88b..1403562b 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailToken.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateEmailToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateMagicUrlToken.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateMagicUrlToken.cs index 722272fa..a6a81463 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateMagicUrlToken.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateMagicUrlToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Session.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Session.cs index cf1e08b9..6e81bf87 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Session.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Session.cs @@ -1,4 +1,4 @@ -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; namespace PinguApps.Appwrite.Server.Tests.Servers.Account; public partial class AccountServerTests diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Token.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Token.cs index 4ed981fd..1224df73 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Token.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateOauth2Token.cs @@ -1,4 +1,4 @@ -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; namespace PinguApps.Appwrite.Server.Tests.Servers.Account; public partial class AccountServerTests diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreatePhoneToken.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreatePhoneToken.cs index d0a5d8fc..29cdee8d 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreatePhoneToken.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreatePhoneToken.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateSession.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateSession.cs index a71095b6..ec27da24 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateSession.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.CreateSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdateMagicUrlSession.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdateMagicUrlSession.cs index 8e4b1eaa..cea45a3d 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdateMagicUrlSession.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdateMagicUrlSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdatePhoneSession.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdatePhoneSession.cs index b8568ecc..22094fbc 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdatePhoneSession.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.UpdatePhoneSession.cs @@ -1,5 +1,5 @@ using System.Net; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; using PinguApps.Appwrite.Shared.Tests; using RichardSzalay.MockHttp; diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.cs index 46ec5b65..0c505338 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/Account/AccountServerTests.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.DependencyInjection; -using PinguApps.Appwrite.Server.Servers; +using PinguApps.Appwrite.Server.Clients; using PinguApps.Appwrite.Shared.Tests; using Refit; using RichardSzalay.MockHttp; @@ -8,7 +8,7 @@ namespace PinguApps.Appwrite.Server.Tests.Servers.Account; public partial class AccountServerTests { private readonly MockHttpMessageHandler _mockHttp; - private readonly IAppwriteServer _appwriteServer; + private readonly IAppwriteClient _appwriteServer; public AccountServerTests() { @@ -22,6 +22,6 @@ public AccountServerTests() var serviceProvider = services.BuildServiceProvider(); - _appwriteServer = serviceProvider.GetRequiredService(); + _appwriteServer = serviceProvider.GetRequiredService(); } } diff --git a/tests/PinguApps.Appwrite.Server.Tests/Servers/AppwriteServerTests.cs b/tests/PinguApps.Appwrite.Server.Tests/Servers/AppwriteServerTests.cs index 05bbba79..46c7045d 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/Servers/AppwriteServerTests.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/Servers/AppwriteServerTests.cs @@ -1,5 +1,5 @@ using Moq; -using PinguApps.Appwrite.Server.Servers; +using PinguApps.Appwrite.Server.Clients; namespace PinguApps.Appwrite.Server.Tests.Servers; public class AppwriteServerTests @@ -8,10 +8,12 @@ public class AppwriteServerTests public void Constructor_AssignsAccountServerCorrectly() { // Arrange - var mockAccountServer = new Mock(); + var mockAccountClient = new Mock(); + var mockUsersClient = new Mock(); // Act - var appwriteServer = new AppwriteServer(mockAccountServer.Object); + var appwriteServer = new AppwriteClient(mockAccountClient.Object, mockUsersClient.Object); // Assert - Assert.Equal(mockAccountServer.Object, appwriteServer.Account); + Assert.Equal(mockAccountClient.Object, appwriteServer.Account); + Assert.Equal(mockUsersClient.Object, appwriteServer.Users); } } diff --git a/tests/PinguApps.Appwrite.Server.Tests/ServiceCollectionExtensionsTests.cs b/tests/PinguApps.Appwrite.Server.Tests/ServiceCollectionExtensionsTests.cs index e578c769..0cb4ccd2 100644 --- a/tests/PinguApps.Appwrite.Server.Tests/ServiceCollectionExtensionsTests.cs +++ b/tests/PinguApps.Appwrite.Server.Tests/ServiceCollectionExtensionsTests.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.DependencyInjection; +using PinguApps.Appwrite.Server.Clients; using PinguApps.Appwrite.Server.Handlers; using PinguApps.Appwrite.Server.Internals; -using PinguApps.Appwrite.Server.Servers; using PinguApps.Appwrite.Shared.Tests; namespace PinguApps.Appwrite.Server.Tests; @@ -28,8 +28,9 @@ public void AddAppwriteServer_RegistersExpectedServices() Assert.NotNull(accountApi); // Assert services are registered - Assert.NotNull(provider.GetService()); - Assert.NotNull(provider.GetService()); + Assert.NotNull(provider.GetService()); + Assert.NotNull(provider.GetService()); + Assert.NotNull(provider.GetService()); } // Additional tests can be added to verify different configurations or overloads of AddAppwriteServer diff --git a/tests/PinguApps.Appwrite.Shared.Tests/ConfigTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/ConfigTests.cs index c9317bd2..aed25f67 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/ConfigTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/ConfigTests.cs @@ -7,12 +7,14 @@ public void Config_ShouldInitializeProperties() // Arrange var endpoint = "https://example.com"; var projectId = "project123"; + var apiKey = "myKey"; // Act - var config = new Config(endpoint, projectId); + var config = new Config(endpoint, projectId, apiKey); // Assert Assert.Equal(endpoint, config.Endpoint); Assert.Equal(projectId, config.ProjectId); + Assert.Equal(apiKey, config.ApiKey); } } diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Constants.cs b/tests/PinguApps.Appwrite.Shared.Tests/Constants.cs index 18df3b68..08bf47b0 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Constants.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Constants.cs @@ -249,4 +249,94 @@ public static class Constants ] } """; + + public const string UsersListResponse = """ + { + "total": 5, + "users": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "John Doe", + "password": "$argon2id$v=19$m=2048,t=4,p=3$aUZjLnliVWRINmFNTWMudg$5S+x+7uA31xFnrHFT47yFwcJeaP0w92L/4LdgrVRXxE", + "hash": "argon2", + "hashOptions": { + "type": "argon2", + "memoryCost": 65536, + "timeCost": 4, + "threads": 3 + }, + "registration": "2020-10-15T06:38:00.000+00:00", + "status": true, + "labels": [ + "vip" + ], + "passwordUpdate": "2020-10-15T06:38:00.000+00:00", + "email": "john@appwrite.io", + "phone": "+4930901820", + "emailVerification": true, + "phoneVerification": true, + "mfa": true, + "prefs": {}, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Aegon apple token", + "userId": "259125845563242502", + "providerId": "259125845563242502", + "providerType": "email", + "identifier": "token" + } + ], + "accessedAt": "2020-10-15T06:38:00.000+00:00" + } + ] + } + """; + + public const string MembershipsListResponse = """ + { + "total": 5, + "memberships": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "userId": "5e5ea5c16897e", + "userName": "John Doe", + "userEmail": "john@appwrite.io", + "teamId": "5e5ea5c16897e", + "teamName": "VIP", + "invited": "2020-10-15T06:38:00.000+00:00", + "joined": "2020-10-15T06:38:00.000+00:00", + "confirm": false, + "mfa": false, + "roles": [ + "owner" + ] + } + ] + } + """; + + public const string TargetListResponse = """ + { + "total": 5, + "targets": [ + { + "$id": "259125845563242502", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Aegon apple token", + "userId": "259125845563242502", + "providerId": "259125845563242502", + "providerType": "email", + "identifier": "token" + } + ] + } + """; } diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/AddAuthenticatorRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/AddAuthenticatorRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/AddAuthenticatorRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/AddAuthenticatorRequestTests.cs index 96ef335a..b985df7d 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/AddAuthenticatorRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/AddAuthenticatorRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class AddAuthenticatorRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeConfirmationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeConfirmationRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeConfirmationRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeConfirmationRequestTests.cs index 0137b81e..462daeeb 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeConfirmationRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeConfirmationRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class Create2faChallengeConfirmationRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeRequestTests.cs index 616ae8f6..7e04575c 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Create2faChallengeRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/Create2faChallengeRequestTests.cs @@ -1,8 +1,8 @@ using FluentValidation; using PinguApps.Appwrite.Shared.Enums; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class Create2faChallengeRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateAccountRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateAccountRequestTests.cs index 2ea80a7d..2886a310 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateAccountRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateAccountRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailPasswordSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailPasswordSessionRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailPasswordSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailPasswordSessionRequestTests.cs index 5e0294fe..51f21061 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailPasswordSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailPasswordSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateEmailPasswordSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailTokenRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailTokenRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailTokenRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailTokenRequestTests.cs index 0fcd571d..3ceb2ed3 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailTokenRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailTokenRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateEmailTokenRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestConfirmationTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestConfirmationTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestConfirmationTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestConfirmationTests.cs index 3781ee7a..3d87d957 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestConfirmationTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestConfirmationTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateEmailVerificationRequestConfirmationTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestTests.cs index 255af5a6..49d4799d 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateEmailVerificationRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateEmailVerificationRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateEmailVerificationRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateMagicUrlTokenRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateMagicUrlTokenRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateMagicUrlTokenRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateMagicUrlTokenRequestTests.cs index efcffa18..920b4d01 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateMagicUrlTokenRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateMagicUrlTokenRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateMagicUrlTokenRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2SessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2SessionRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2SessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2SessionRequestTests.cs index 3dd3e37a..7bdd117a 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2SessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2SessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateOauth2SessionRequestTests { public class TestableCreateOauth2SessionRequest : CreateOauth2SessionRequest diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2TokenRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2TokenRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2TokenRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2TokenRequestTests.cs index a909c0dd..55dfb9da 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateOauth2TokenRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateOauth2TokenRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateOauth2TokenRequestTests { public class TestableCreateOauth2TokenRequest : CreateOauth2TokenRequest diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryConfirmationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryConfirmationRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryConfirmationRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryConfirmationRequestTests.cs index 3ba3a869..f620db16 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryConfirmationRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryConfirmationRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreatePasswordRecoveryConfirmationRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryTests.cs index 177d4022..198ee50e 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePasswordRecoveryTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePasswordRecoveryTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreatePasswordRecoveryTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePhoneTokenRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePhoneTokenRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePhoneTokenRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePhoneTokenRequestTests.cs index bc622c4d..ae92205c 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreatePhoneTokenRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreatePhoneTokenRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreatePhoneTokenRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateSessionRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateSessionRequestTests.cs index 6884a1bc..744dfb1a 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/CreateSessionRequestTests.cs @@ -1,8 +1,8 @@  using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class CreateSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteAuthenticatorRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteAuthenticatorRequestTests.cs similarity index 97% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteAuthenticatorRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteAuthenticatorRequestTests.cs index c5bf4f88..4417d436 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteAuthenticatorRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteAuthenticatorRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class DeleteAuthenticatorRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteIdentityRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteIdentityRequestTests.cs similarity index 94% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteIdentityRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteIdentityRequestTests.cs index 360578b5..5e9ee9e3 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteIdentityRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteIdentityRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class DeleteIdentityRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteSessionRequestTests.cs similarity index 94% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteSessionRequestTests.cs index e2ce4e62..16fbef05 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/DeleteSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/DeleteSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class DeleteSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/GetSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/GetSessionRequestTests.cs similarity index 94% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/GetSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/GetSessionRequestTests.cs index 2e51758b..a61b2eb1 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/GetSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/GetSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class GetSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListIdentitiesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListIdentitiesRequestTests.cs new file mode 100644 index 00000000..bbc0e65a --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListIdentitiesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Account; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; +public class ListIdentitiesRequestTests : QueryBaseRequestTests +{ + protected override ListIdentitiesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListLogsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListLogsRequestTests.cs new file mode 100644 index 00000000..8b563003 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/ListLogsRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Account; +using PinguApps.Appwrite.Shared.Requests.Account.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; +public class ListLogsRequestTests : QueryBaseRequestTests +{ + protected override ListLogsRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryParamBaseRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/QueryParamBaseRequestTests.cs similarity index 98% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryParamBaseRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/QueryParamBaseRequestTests.cs index ab4d35cc..d756585d 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryParamBaseRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/QueryParamBaseRequestTests.cs @@ -2,7 +2,7 @@ using PinguApps.Appwrite.Shared.Attributes; using PinguApps.Appwrite.Shared.Requests; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class QueryParamBaseRequestTests { private class TestRequest : QueryParamBaseRequest diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateEmailRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateEmailRequestTests.cs index ec08e031..3899acc4 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateEmailRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateEmailRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdateEmailRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMagicUrlSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMagicUrlSessionRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMagicUrlSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMagicUrlSessionRequestTests.cs index c582caf0..48484b47 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMagicUrlSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMagicUrlSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdateMagicUrlSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMfaRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMfaRequestTests.cs similarity index 88% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMfaRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMfaRequestTests.cs index ce37cb0c..435a4761 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateMfaRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateMfaRequestTests.cs @@ -1,6 +1,6 @@ -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdateMfaRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateNameRequestTests.cs similarity index 94% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateNameRequestTests.cs index 0ad91c61..a4de07f7 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateNameRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateNameRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdateNameRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePasswordRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePasswordRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePasswordRequestTests.cs index cd91ad9e..fe693c1f 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePasswordRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePasswordRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdatePasswordRequestTests { diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneRequestTests.cs index 1458cccd..91a3f802 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdatePhoneRequestTests { diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneSessionRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneSessionRequestTests.cs index 34ce439a..a397f07f 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdatePhoneSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneVerificationConfirmationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneVerificationConfirmationRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneVerificationConfirmationRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneVerificationConfirmationRequestTests.cs index 3c99e75a..e3bdc7be 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePhoneVerificationConfirmationRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePhoneVerificationConfirmationRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdatePhoneVerificationConfirmationRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePreferencesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePreferencesRequestTests.cs similarity index 95% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePreferencesRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePreferencesRequestTests.cs index 931ce327..6544633f 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdatePreferencesRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdatePreferencesRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdatePreferencesRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateSessionRequestTests.cs similarity index 94% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateSessionRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateSessionRequestTests.cs index 7987085e..2c856aac 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/UpdateSessionRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/UpdateSessionRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class UpdateSessionRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/VerifyAuthenticatorRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/VerifyAuthenticatorRequestTests.cs similarity index 96% rename from tests/PinguApps.Appwrite.Shared.Tests/Requests/VerifyAuthenticatorRequestTests.cs rename to tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/VerifyAuthenticatorRequestTests.cs index 0afe6d1e..9f5f29c6 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/VerifyAuthenticatorRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Account/VerifyAuthenticatorRequestTests.cs @@ -1,7 +1,7 @@ using FluentValidation; -using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Requests.Account; -namespace PinguApps.Appwrite.Shared.Tests.Requests; +namespace PinguApps.Appwrite.Shared.Tests.Requests.Account; public class VerifyAuthenticatorRequestTests { [Fact] diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryBaseRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryBaseRequestTests.cs new file mode 100644 index 00000000..f763f177 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/QueryBaseRequestTests.cs @@ -0,0 +1,132 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests; +public abstract class QueryBaseRequestTests + where TRequest : QueryBaseRequest + where TValidator : AbstractValidator, new() +{ + protected abstract TRequest CreateValidRequest { get; } + + [Fact] + public void QueryBase_Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = CreateValidRequest; + + // Assert + Assert.Null(request.Queries); + } + + [Fact] + public void QueryBase_Properties_CanBeSet() + { + // Arrange + var attributeName = "attributeName"; + var value = "value"; + List queries = [Query.Equal(attributeName, value)]; + var request = CreateValidRequest; + + // Act + request.Queries = queries; + + // Assert + Assert.Collection(request.Queries, query => + { + Assert.Equal(attributeName, query.Attribute); + Assert.NotNull(query.Values); + Assert.Collection(query.Values, v => + { + Assert.Equal(value, v); + }); + Assert.Equal("equal", query.Method); + }); + } + + [Fact] + public void QueryBase_IsValid_WithValidData_ReturnsTrue() + { + // Arrange + var request = CreateValidRequest; + request.Queries = [Query.Equal("attributeName", "value")]; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Fact] + public void QueryBase_IsValid_WithNullQueries_ReturnsTrue() + { + // Arrange + var request = CreateValidRequest; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Fact] + public void QueryBase_IsValid_WithInvalidData_QueryTooLarge_ReturnsFalse() + { + // Arrange + var request = CreateValidRequest; + request.Queries = [Query.Equal("attributeName", new string('a', 4097))]; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void QueryBase_IsValid_WithInvalidData_TooManyQueries_ReturnsFalse() + { + // Arrange + var request = CreateValidRequest; + request.Queries = Enumerable.Range(0, 101) + .Select(_ => Query.Equal("attributeName", "value")) + .ToList(); + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void QueryBase_Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.Queries = Enumerable.Range(0, 101) + .Select(_ => Query.Equal("attributeName", "value")) + .ToList(); + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void QueryBase_Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.Queries = Enumerable.Range(0, 101) + .Select(_ => Query.Equal("attributeName", "value")) + .ToList(); + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/QuerySearchBaseRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/QuerySearchBaseRequestTests.cs new file mode 100644 index 00000000..31e39c48 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/QuerySearchBaseRequestTests.cs @@ -0,0 +1,75 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests; + +namespace PinguApps.Appwrite.Shared.Tests.Requests; +public abstract class QuerySearchBaseRequestTests : QueryBaseRequestTests + where TRequest : QuerySearchBaseRequest, new() + where TValidator : AbstractValidator, new() +{ + [Fact] + public void QuerySearchBase_SearchProperty_CanBeSet() + { + // Arrange + var searchValue = "test search"; + var request = CreateValidRequest; + + // Act + request.Search = searchValue; + + // Assert + Assert.Equal(searchValue, request.Search); + } + + [Fact] + public void QuerySearchBase_IsValid_WithValidSearch_ReturnsTrue() + { + // Arrange + var request = CreateValidRequest; + request.Search = "valid search term"; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Fact] + public void QuerySearchBase_IsValid_WithSearchTooLong_ReturnsFalse() + { + // Arrange + var request = CreateValidRequest; + request.Search = new string('a', 257); // 257 characters, exceeding the limit + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void QuerySearchBase_Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.Search = new string('a', 257); // 257 characters, exceeding the limit + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void QuerySearchBase_Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.Search = new string('a', 257); // 257 characters, exceeding the limit + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateMfaRecoveryCodesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateMfaRecoveryCodesRequestTests.cs new file mode 100644 index 00000000..d43fe2f4 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateMfaRecoveryCodesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateMfaRecoveryCodesRequestTests : UserIdBaseRequestTests +{ + protected override CreateMfaRecoveryCodesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateSessionRequestTests.cs new file mode 100644 index 00000000..80c9b04f --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateSessionRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateSessionRequestTests : UserIdBaseRequestTests +{ + protected override CreateSessionRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateTokenRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateTokenRequestTests.cs new file mode 100644 index 00000000..d857a582 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateTokenRequestTests.cs @@ -0,0 +1,121 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateTokenRequestTests : UserIdBaseRequestTests +{ + protected override CreateTokenRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateTokenRequest(); + + // Assert + Assert.Null(request.Length); + Assert.Null(request.Expire); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new CreateTokenRequest(); + + // Act + request.Length = 8; + request.Expire = 1800; // 30 minutes + + // Assert + Assert.Equal(8, request.Length); + Assert.Equal(1800, request.Expire); + } + + public static TheoryData ValidRequestsData = new() + { + new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Length = 6, + Expire = 900 // 15 minutes + }, + new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Length = 100, + Expire = 86400 // 24 hours + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(CreateTokenRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Length = -1 + }, + new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Expire = -1 + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(CreateTokenRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Length = -1, + Expire = -1 + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateTokenRequest + { + UserId = IdUtils.GenerateUniqueId(), + Length = -1, + Expire = -1 + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserJwtRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserJwtRequestTests.cs new file mode 100644 index 00000000..5658773c --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserJwtRequestTests.cs @@ -0,0 +1,114 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserJwtRequestTests : UserIdBaseRequestTests +{ + protected override CreateUserJwtRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserJwtRequest(); + + // Assert + Assert.Null(request.SessionId); + Assert.Null(request.Duration); + } + + [Fact] + public void Properties_CanBeSet() + { + var sessionId = "recent"; + var duration = 1200; + + // Arrange + var request = new CreateUserJwtRequest(); + + // Act + request.SessionId = sessionId; + request.Duration = duration; + + // Assert + Assert.Equal(sessionId, request.SessionId); + Assert.Equal(duration, request.Duration); + } + + [Theory] + [InlineData(null, null)] + [InlineData("recent", 1200)] + [InlineData("validSessionId", 3600)] + public void IsValid_WithValidData_ReturnsTrue(string? sessionId, int? duration) + { + // Arrange + var request = new CreateUserJwtRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = sessionId, + Duration = duration + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData("", 1200)] // Invalid SessionId + [InlineData("recent", -1)] // Invalid Duration + [InlineData("recent", 3601)] // Invalid Duration + public void IsValid_WithInvalidData_ReturnsFalse(string? sessionId, int? duration) + { + // Arrange + var request = new CreateUserJwtRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = sessionId, + Duration = duration + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserJwtRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = "", + Duration = -1 + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserJwtRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = "", + Duration = -1 + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserRequestTests.cs new file mode 100644 index 00000000..ef54e679 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserRequestTests.cs @@ -0,0 +1,145 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserRequestTests : UserIdBaseRequestTests +{ + protected override CreateUserRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserRequest(); + + // Assert + Assert.Null(request.Email); + Assert.Null(request.Phone); + Assert.Null(request.Password); + Assert.Null(request.Name); + } + + [Fact] + public void Properties_CanBeSet() + { + var email = "pingu@example.com"; + var phone = "+4412345678901"; + var password = "ThisIsMySecretPassword"; + var name = "Pingu"; + + // Arrange + var request = new CreateUserRequest(); + + // Act + request.Email = email; + request.Phone = phone; + request.Password = password; + request.Name = name; + + // Assert + Assert.Equal(email, request.Email); + Assert.Equal(phone, request.Phone); + Assert.Equal(password, request.Password); + Assert.Equal(name, request.Name); + } + + [Theory] + [InlineData(null, null, null, null)] + [InlineData("pingu@example.com", null, null, null)] + [InlineData(null, "+4412345678901", null, null)] + [InlineData(null, null, "MyPa55w0rd!", null)] + [InlineData(null, null, null, "My Name")] + public void IsValid_WithValidData_ReturnsTrue(string? email, string? phone, string? password, string? name) + { + // Arrange + var request = new CreateUserRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = email, + Phone = phone, + Password = password, + Name = name + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static IEnumerable GetInvalidData() + { + yield return new object?[] { "", null, null, null }; + yield return new object?[] { "not an email", null, null, null }; + yield return new object?[] { null, "", null, null }; + yield return new object?[] { null, "1234567890", null, null }; + yield return new object?[] { null, "+456123aaa", null, null }; + yield return new object?[] { null, "+456123!!!", null, null }; + yield return new object?[] { null, "+1234567890123456789", null, null }; + yield return new object?[] { null, null, "", null }; + yield return new object?[] { null, null, "tooFew", null }; + yield return new object?[] { null, null, null, "" }; + yield return new object?[] { null, null, null, new string('a', 129) }; + } + + [Theory] + [MemberData(nameof(GetInvalidData))] + public void IsValid_WithInvalidData_ReturnsFalse(string? email, string? phone, string? password, string? name) + { + // Arrange + var request = new CreateUserRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = email, + Phone = phone, + Password = password, + Name = name + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "not an email", + Phone = "123", + Password = "short", + Name = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "not an email", + Phone = "123", + Password = "short", + Name = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserTargetRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserTargetRequestTests.cs new file mode 100644 index 00000000..16cc996a --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserTargetRequestTests.cs @@ -0,0 +1,246 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Enums; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserTargetRequestTests : UserIdBaseRequestTests +{ + protected override CreateUserTargetRequest CreateValidRequest => new() + { + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = IdUtils.GenerateUniqueId() + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserTargetRequest(); + + // Assert + Assert.Equal(string.Empty, request.TargetId); + Assert.Equal(TargetProviderType.Email, request.ProviderType); + Assert.Equal(string.Empty, request.Identifier); + Assert.Null(request.ProviderId); + Assert.Null(request.Name); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new CreateUserTargetRequest(); + + // Act + request.TargetId = "validTargetId"; + request.ProviderType = TargetProviderType.Sms; + request.Identifier = "identifier"; + request.ProviderId = "providerId"; + request.Name = "Valid Name"; + + // Assert + Assert.Equal("validTargetId", request.TargetId); + Assert.Equal(TargetProviderType.Sms, request.ProviderType); + Assert.Equal("identifier", request.Identifier); + Assert.Equal("providerId", request.ProviderId); + Assert.Equal("Valid Name", request.Name); + } + + public static TheoryData ValidRequestsData = new() + { + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = "validTargetId", + ProviderType = TargetProviderType.Sms, + Identifier = "identifier", + ProviderId = "providerId", + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = "validTargetId", + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = null, + Name = null + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Push, + Identifier = IdUtils.GenerateUniqueId(), + ProviderId = null, + Name = null + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(CreateUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = + [ + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty, + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = null!, + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = "Invalid Symbols!!!", + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = ".startsWithValidSymbol", + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = new string('a', 37), + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = (TargetProviderType)999, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = string.Empty, + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = null!, + ProviderId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = string.Empty, + Name = "Valid Name" + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = string.Empty + }, + new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderType = TargetProviderType.Email, + Identifier = "identifier", + ProviderId = IdUtils.GenerateUniqueId(), + Name = new string('a', 129) + } + ]; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(CreateUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty, + ProviderType = TargetProviderType.Email, + Identifier = string.Empty, + ProviderId = string.Empty, + Name = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty, + ProviderType = TargetProviderType.Email, + Identifier = string.Empty, + ProviderId = string.Empty, + Name = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithArgon2PasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithArgon2PasswordRequestTests.cs new file mode 100644 index 00000000..b3aa627d --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithArgon2PasswordRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithArgon2PasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithArgon2PasswordRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithBcryptPasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithBcryptPasswordRequestTests.cs new file mode 100644 index 00000000..db435278 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithBcryptPasswordRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithBcryptPasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithBcryptPasswordRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithMd5PasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithMd5PasswordRequestTests.cs new file mode 100644 index 00000000..7d2147f6 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithMd5PasswordRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithMd5PasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithMd5PasswordRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPasswordBaseRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPasswordBaseRequestTests.cs new file mode 100644 index 00000000..c36a6634 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPasswordBaseRequestTests.cs @@ -0,0 +1,132 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public abstract class CreateUserWithPasswordBaseRequestTests + where TRequest : CreateUserWithPasswordBaseRequest + where TValidator : AbstractValidator, new() +{ + protected abstract TRequest CreateValidRequest { get; } + + [Fact] + public void CreateUserWithPasswordBase_Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = CreateValidRequest; + + // Assert + Assert.Equal(string.Empty, request.UserId); + Assert.Equal(string.Empty, request.Email); + Assert.Equal(string.Empty, request.Password); + Assert.Null(request.Name); + } + + [Fact] + public void CreateUserWithPasswordBase_Properties_CanBeSet() + { + // Arrange + var userId = IdUtils.GenerateUniqueId(); + var email = "pingu@example.com"; + var password = "MySuperSecretPassword"; + var name = "My Name"; + var request = CreateValidRequest; + + // Act + request.UserId = userId; + request.Email = email; + request.Password = password; + request.Name = name; + + // Assert + Assert.Equal(userId, request.UserId); + Assert.Equal(email, request.Email); + Assert.Equal(password, request.Password); + Assert.Equal(name, request.Name); + } + + [Theory] + [InlineData("anId", "pingu@example.com", "MySuperSecretPassword123!", null)] + [InlineData("with.Some-Symbols_too", "pingu@example.com", "MySuperSecretPassword123!", "My Name")] + public void CreateUserWithPasswordBase_IsValid_WithValidData_ReturnsTrue(string userId, string email, string password, string? name) + { + // Arrange + var request = CreateValidRequest; + request.UserId = userId; + request.Email = email; + request.Password = password; + request.Name = name; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + // Need to rework these - as null is not ok for email and password + public static IEnumerable CreateUserWithPasswordBase_GetInvalidData() + { + yield return new object?[] { null, "pingu@example.com", "MySuperSecretPassword", null }; + yield return new object?[] { "", "pingu@example.com", "MySuperSecretPassword", null }; + yield return new object?[] { "invalid chars!", "pingu@example.com", "MySuperSecretPassword", null }; + yield return new object?[] { ".startsWithSymbol", "pingu@example.com", "MySuperSecretPassword", null }; + yield return new object?[] { new string('a', 37), "pingu@example.com", "MySuperSecretPassword", null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), null, "MySuperSecretPassword", null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "", "MySuperSecretPassword", null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "not an email", "MySuperSecretPassword", null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "pingu@example.com", null, null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "pingu@example.com", "", null }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "pingu@example.com", "MySuperSecretPassword", "" }; + yield return new object?[] { IdUtils.GenerateUniqueId(), "pingu@example.com", "MySuperSecretPassword", new string('a', 129) }; + } + + [Theory] + [MemberData(nameof(CreateUserWithPasswordBase_GetInvalidData))] + public void CreateUserWithPasswordBase_IsValid_WithInvalidData_ReturnsFalse(string? userId, string? email, string? password, string? name) + { + // Arrange + var request = CreateValidRequest; + request.UserId = userId!; + request.Email = email!; + request.Password = password!; + request.Name = name; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void CreateUserWithPasswordBase_Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.UserId = IdUtils.GenerateUniqueId(); + request.Email = "not an email"; + request.Password = ""; + request.Name = new string('a', 129); + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void CreateUserWithPasswordBase_Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.UserId = IdUtils.GenerateUniqueId(); + request.Email = "not an email"; + request.Password = ""; + request.Name = new string('a', 129); + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPhpassPasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPhpassPasswordRequestTests.cs new file mode 100644 index 00000000..7590130d --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithPhpassPasswordRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithPhpassPasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithPhpassPasswordRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptModifiedPasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptModifiedPasswordRequestTests.cs new file mode 100644 index 00000000..98d31bfc --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptModifiedPasswordRequestTests.cs @@ -0,0 +1,136 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithScryptModifiedPasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithScryptModifiedPasswordRequest CreateValidRequest => new() + { + PasswordSalt = "MySalt", + PasswordSaltSeparator = ",", + PasswordSignerKey = "MyKey" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserWithScryptModifiedPasswordRequest(); + + // Assert + Assert.Equal(string.Empty, request.PasswordSalt); + Assert.Equal(string.Empty, request.PasswordSaltSeparator); + Assert.Equal(string.Empty, request.PasswordSignerKey); + } + + [Fact] + public void Properties_CanBeSet() + { + var salt = "MySalt"; + var seperator = "MySeperator"; + var signerKey = "MySignerKey"; + + // Arrange + var request = new CreateUserWithScryptModifiedPasswordRequest(); + + // Act + request.PasswordSalt = salt; + request.PasswordSaltSeparator = seperator; + request.PasswordSignerKey = signerKey; + + // Assert + Assert.Equal(salt, request.PasswordSalt); + Assert.Equal(seperator, request.PasswordSaltSeparator); + Assert.Equal(signerKey, request.PasswordSignerKey); + } + + [Theory] + [InlineData("any salt should work", "MySeperator", "MySignerKey")] + public void IsValid_WithValidData_ReturnsTrue(string salt, string seperator, string signerKey) + { + // Arrange + var request = new CreateUserWithScryptModifiedPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = salt, + PasswordSaltSeparator = seperator, + PasswordSignerKey = signerKey + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData(null, "MySeperator", "MyKey")] + [InlineData("", "MySeperator", "MyKey")] + [InlineData("MySalt", null, "MyKey")] + [InlineData("MySalt", "", "MyKey")] + [InlineData("MySalt", "MySeparator", null)] + [InlineData("MySalt", "MySeparator", "")] + public void IsValid_WithInvalidData_ReturnsFalse(string? salt, string? seperator, string? signerKey) + { + // Arrange + var request = new CreateUserWithScryptModifiedPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = salt!, + PasswordSaltSeparator = seperator!, + PasswordSignerKey = signerKey! + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserWithScryptModifiedPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = "", + PasswordSaltSeparator = "", + PasswordSignerKey = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserWithScryptModifiedPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = "", + PasswordSaltSeparator = "", + PasswordSignerKey = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptPasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptPasswordRequestTests.cs new file mode 100644 index 00000000..9b261ab4 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithScryptPasswordRequestTests.cs @@ -0,0 +1,139 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithScryptPasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithScryptPasswordRequest CreateValidRequest => new() + { + PasswordSalt = "passwordSalt" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserWithScryptPasswordRequest(); + + // Assert + Assert.Equal(string.Empty, request.PasswordSalt); + Assert.Equal(0, request.PasswordCpu); + Assert.Equal(0, request.PasswordMemory); + Assert.Equal(0, request.PasswordParallel); + Assert.Equal(0, request.PasswordLength); + } + + [Fact] + public void Properties_CanBeSet() + { + var salt = "MySalt"; + var cpu = 1; + var memory = 2; + var parallel = 3; + var length = 4; + + // Arrange + var request = new CreateUserWithScryptPasswordRequest(); + + // Act + request.PasswordSalt = salt; + request.PasswordCpu = cpu; + request.PasswordMemory = memory; + request.PasswordParallel = parallel; + request.PasswordLength = length; + + // Assert + Assert.Equal(salt, request.PasswordSalt); + Assert.Equal(cpu, request.PasswordCpu); + Assert.Equal(memory, request.PasswordMemory); + Assert.Equal(parallel, request.PasswordParallel); + Assert.Equal(length, request.PasswordLength); + } + + [Theory] + [InlineData("any salt should work", 0, 0, 0, 0)] + [InlineData("symbols-_.", 1, 2, 3, 4)] + public void IsValid_WithValidData_ReturnsTrue(string salt, int cpu, int memory, int parallel, int length) + { + // Arrange + var request = new CreateUserWithScryptPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = salt, + PasswordCpu = cpu, + PasswordMemory = memory, + PasswordParallel = parallel, + PasswordLength = length + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData(null, 0, 0, 0, 0)] + [InlineData("", 0, 0, 0, 0)] + public void IsValid_WithInvalidData_ReturnsFalse(string? salt, int cpu, int memory, int parallel, int length) + { + // Arrange + var request = new CreateUserWithScryptPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = salt!, + PasswordCpu = cpu, + PasswordMemory = memory, + PasswordParallel = parallel, + PasswordLength = length + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserWithScryptPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserWithScryptPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordSalt = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithShaPasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithShaPasswordRequestTests.cs new file mode 100644 index 00000000..e4239000 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/CreateUserWithShaPasswordRequestTests.cs @@ -0,0 +1,123 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class CreateUserWithShaPasswordRequestTests : CreateUserWithPasswordBaseRequestTests +{ + protected override CreateUserWithShaPasswordRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new CreateUserWithShaPasswordRequest(); + + // Assert + Assert.Null(request.PasswordVersion); + } + + [Fact] + public void Properties_CanBeSet() + { + var version = "sha1"; + + // Arrange + var request = new CreateUserWithShaPasswordRequest(); + + // Act + request.PasswordVersion = version; + + // Assert + Assert.Equal(version, request.PasswordVersion); + } + + [Theory] + [InlineData(null)] + [InlineData("sha1")] + [InlineData("sha224")] + [InlineData("sha256")] + [InlineData("sha384")] + [InlineData("sha512/224")] + [InlineData("sha512/256")] + [InlineData("sha512")] + [InlineData("sha3-224")] + [InlineData("sha3-256")] + [InlineData("sha3-384")] + [InlineData("sha3-512")] + public void IsValid_WithValidData_ReturnsTrue(string? version) + { + // Arrange + var request = new CreateUserWithShaPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordVersion = version + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData("")] + [InlineData("Invalid")] + [InlineData("sha")] + public void IsValid_WithInvalidData_ReturnsFalse(string? version) + { + // Arrange + var request = new CreateUserWithShaPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordVersion = version + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateUserWithShaPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordVersion = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateUserWithShaPasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "pingu@example.com", + Password = "MyPassword", + PasswordVersion = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteAuthenticatorRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteAuthenticatorRequestTests.cs new file mode 100644 index 00000000..ecc34837 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteAuthenticatorRequestTests.cs @@ -0,0 +1,114 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteAuthenticatorRequestTests : UserIdBaseRequestTests +{ + protected override DeleteAuthenticatorRequest CreateValidRequest => new() + { + Type = "totp" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new DeleteAuthenticatorRequest(); + + // Assert + Assert.Equal(string.Empty, request.Type); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var type = "totp"; + + var request = new DeleteAuthenticatorRequest(); + + // Act + request.Type = type; + + // Assert + Assert.Equal(type, request.Type); + } + + public static TheoryData ValidRequestsData = new() + { + new DeleteAuthenticatorRequest + { + UserId = IdUtils.GenerateUniqueId(), + Type = "totp" + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(DeleteAuthenticatorRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new DeleteAuthenticatorRequest + { + UserId = IdUtils.GenerateUniqueId(), + Type = string.Empty + }, + new DeleteAuthenticatorRequest + { + UserId = IdUtils.GenerateUniqueId(), + Type = null! + }, + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(DeleteAuthenticatorRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new DeleteAuthenticatorRequest + { + UserId = IdUtils.GenerateUniqueId(), + Type = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new DeleteAuthenticatorRequest + { + UserId = IdUtils.GenerateUniqueId(), + Type = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteIdentityRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteIdentityRequestTests.cs new file mode 100644 index 00000000..50bc6781 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteIdentityRequestTests.cs @@ -0,0 +1,96 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteIdentityRequestTests +{ + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new DeleteIdentityRequest(); + + // Assert + Assert.Equal(string.Empty, request.IdentityId); + } + + [Fact] + public void Properties_CanBeSet() + { + var id = "newId"; + + // Arrange + var request = new DeleteIdentityRequest(); + + // Act + request.IdentityId = id; + + // Assert + Assert.Equal(id, request.IdentityId); + } + + [Theory] + [InlineData("any Id should work")] + [InlineData("symbols-_.")] + public void IsValid_WithValidData_ReturnsTrue(string id) + { + // Arrange + var request = new DeleteIdentityRequest + { + IdentityId = id + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public void IsValid_WithInvalidData_ReturnsFalse(string? id) + { + // Arrange + var request = new DeleteIdentityRequest + { + IdentityId = id! + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new DeleteIdentityRequest + { + IdentityId = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new DeleteIdentityRequest + { + IdentityId = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserRequestTests.cs new file mode 100644 index 00000000..774e04d6 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteUserRequestTests : UserIdBaseRequestTests +{ + protected override DeleteUserRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionRequestTests.cs new file mode 100644 index 00000000..92d00788 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionRequestTests.cs @@ -0,0 +1,114 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteUserSessionRequestTests : UserIdBaseRequestTests +{ + protected override DeleteUserSessionRequest CreateValidRequest => new() + { + SessionId = IdUtils.GenerateUniqueId() + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new DeleteUserSessionRequest(); + + // Assert + Assert.Equal(string.Empty, request.SessionId); + } + + [Fact] + public void Properties_CanBeSet() + { + var sessionId = IdUtils.GenerateUniqueId(); + + // Arrange + var request = new DeleteUserSessionRequest(); + + // Act + request.SessionId = sessionId; + + // Assert + Assert.Equal(sessionId, request.SessionId); + } + + public static TheoryData ValidRequestsData = + [ + new DeleteUserSessionRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = IdUtils.GenerateUniqueId() + } + ]; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(DeleteUserSessionRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = + [ + new DeleteUserSessionRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = string.Empty + }, + new DeleteUserSessionRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = null! + }, + ]; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(DeleteUserSessionRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new DeleteUserSessionRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new DeleteUserSessionRequest + { + UserId = IdUtils.GenerateUniqueId(), + SessionId = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionsRequestTests.cs new file mode 100644 index 00000000..69abf1c3 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserSessionsRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteUserSessionsRequestTests : UserIdBaseRequestTests +{ + protected override DeleteUserSessionsRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserTargetRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserTargetRequestTests.cs new file mode 100644 index 00000000..331a2fdd --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/DeleteUserTargetRequestTests.cs @@ -0,0 +1,112 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class DeleteUserTargetRequestTests : UserIdBaseRequestTests +{ + protected override DeleteUserTargetRequest CreateValidRequest => new() + { + TargetId = IdUtils.GenerateUniqueId() + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new DeleteUserTargetRequest(); + + // Assert + Assert.Equal(string.Empty, request.TargetId); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new DeleteUserTargetRequest(); + + // Act + request.TargetId = "validTargetId"; + + // Assert + Assert.Equal("validTargetId", request.TargetId); + } + + public static TheoryData ValidRequestsData = new() + { + new DeleteUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId() + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(DeleteUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new DeleteUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = null! + }, + new DeleteUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(DeleteUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new DeleteUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new DeleteUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetMfaRecoveryCodesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetMfaRecoveryCodesRequestTests.cs new file mode 100644 index 00000000..c0cd87fd --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetMfaRecoveryCodesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class GetMfaRecoveryCodesRequestTests : UserIdBaseRequestTests +{ + protected override GetMfaRecoveryCodesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserPreferencesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserPreferencesRequestTests.cs new file mode 100644 index 00000000..c62f9643 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserPreferencesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class GetUserPreferencesRequestTests : UserIdBaseRequestTests +{ + protected override GetUserPreferencesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserRequestTests.cs new file mode 100644 index 00000000..1bc4a0bc --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class GetUserRequestTests : UserIdBaseRequestTests +{ + protected override GetUserRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserTargetRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserTargetRequestTests.cs new file mode 100644 index 00000000..2c8e1b05 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/GetUserTargetRequestTests.cs @@ -0,0 +1,112 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class GetUserTargetRequestTests : UserIdBaseRequestTests +{ + protected override GetUserTargetRequest CreateValidRequest => new() + { + TargetId = IdUtils.GenerateUniqueId() + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new GetUserTargetRequest(); + + // Assert + Assert.Equal(string.Empty, request.TargetId); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new GetUserTargetRequest(); + + // Act + request.TargetId = "validTargetId"; + + // Assert + Assert.Equal("validTargetId", request.TargetId); + } + + public static TheoryData ValidRequestsData = new() + { + new GetUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId() + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(GetUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new GetUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = null! + }, + new GetUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(GetUserTargetRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new GetUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new GetUserTargetRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListFactorsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListFactorsRequestTests.cs new file mode 100644 index 00000000..bc6ade1f --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListFactorsRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListFactorsRequestTests : UserIdBaseRequestTests +{ + protected override ListFactorsRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListIdentitiesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListIdentitiesRequestTests.cs new file mode 100644 index 00000000..91bcc789 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListIdentitiesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListIdentitiesRequestTests : QuerySearchBaseRequestTests +{ + protected override ListIdentitiesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserLogsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserLogsRequestTests.cs new file mode 100644 index 00000000..f0fead63 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserLogsRequestTests.cs @@ -0,0 +1,133 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListUserLogsRequestTests : UserIdBaseRequestTests +{ + protected override ListUserLogsRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new ListUserLogsRequest(); + + // Assert + Assert.Null(request.Queries); + } + + [Fact] + public void Properties_CanBeSet() + { + var queries = new List { Query.Limit(10) }; + + // Arrange + var request = new ListUserLogsRequest(); + + // Act + request.Queries = queries; + + // Assert + Assert.Single(request.Queries, queries[0]); + } + + public static TheoryData?> ValidQueriesData = + [ + null, + [Query.Limit(10)], + [Query.Offset(10)] + ]; + + [Theory] + [MemberData(nameof(ValidQueriesData))] + public void IsValid_WithValidData_ReturnsTrue(List? queries) + { + // Arrange + var request = new ListUserLogsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = queries + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData?> InvalidQueriesData = + [ + Enumerable.Range(0,101).Select(x => Query.Limit(x)).ToList(), + [Query.And([])], + [Query.Between("a", 0, 1)], + [Query.Contains("a", "a")], + [Query.CursorAfter("a")], + [Query.CursorBefore("a")], + [Query.EndsWith("a", "a")], + [Query.Equal("a", "a")], + [Query.GreaterThan("a", "a")], + [Query.IsNotNull("a")], + [Query.IsNull("a")], + [Query.LessThan("a", "a")], + [Query.LessThanEqual("a", "a")], + [Query.NotEqual("a", "a")], + [Query.Or([])], + [Query.OrderAsc("a")], + [Query.OrderDesc("a")], + [Query.Search("a", "a")], + [Query.Select([])], + [Query.StartsWith("a", "a")] + ]; + + [Theory] + [MemberData(nameof(InvalidQueriesData))] + public void IsValid_WithInvalidData_ReturnsFalse(List? queries) + { + // Arrange + var request = new ListUserLogsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = queries + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new ListUserLogsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = [Query.StartsWith("a", "a")] + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new ListUserLogsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = [Query.StartsWith("a", "a")] + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserMembershipsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserMembershipsRequestTests.cs new file mode 100644 index 00000000..d6167db3 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserMembershipsRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListUserMembershipsRequestTests : UserIdBaseRequestTests +{ + protected override ListUserMembershipsRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserSessionsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserSessionsRequestTests.cs new file mode 100644 index 00000000..65504df4 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserSessionsRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListUserSessionsRequestTests : UserIdBaseRequestTests +{ + protected override ListUserSessionsRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserTargetsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserTargetsRequestTests.cs new file mode 100644 index 00000000..6b3c96e4 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUserTargetsRequestTests.cs @@ -0,0 +1,378 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListUserTargetsRequestTests : UserIdBaseRequestTests +{ + protected override ListUserTargetsRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new ListUserTargetsRequest(); + + // Assert + Assert.Null(request.Queries); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var queries = new List + { + Query.Equal("name", "John") + }; + var request = new ListUserTargetsRequest(); + + // Act + request.Queries = queries; + + // Assert + Assert.Equal(queries, request.Queries); + } + + public static TheoryData ValidRequestsData = new() + { + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = null + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.And( + [ + Query.Equal("name", "Pingu"), + Query.Contains("email", "example.com") + ]) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Between("name", "p", "pz") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Contains("name", "Pin") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.CursorAfter(IdUtils.GenerateUniqueId()) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.CursorBefore(IdUtils.GenerateUniqueId()) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.EndsWith("name", "gu") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("name", "Pingu") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.GreaterThan("name", "Pin") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.GreaterThanEqual("name", "Pin") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.IsNotNull("name") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.IsNull("name") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.LessThan("name", "Pim") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.LessThanEqual("name", "Pim") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Limit(10) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.NotEqual("name", "ugniP") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Offset(10) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Or( + [ + Query.Equal("name", "Pingu"), + Query.Contains("email", "example.com") + ]) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.OrderAsc("name") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.OrderDesc("name") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Search("name", "pin") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Select(["name"]) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.StartsWith("name", "pin") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("email", "pingu@example.com") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("phone", "+44123456789") + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("status", true) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("passwordUpdate", true) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("registration", true) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("emailVerification", true) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("phoneVerification", true) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("labels", "Admin") + ] + }, + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(ListUserTargetsRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = Enumerable.Range(0, 101).Select(x => Query.Offset(x)).ToList() + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("name", new string('a', 4097)) + ] + }, + new ListUserTargetsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Queries = + [ + Query.Equal("NotAValidAttribute", "Pingu") + ] + }, + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(ListUserTargetsRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new ListUserTargetsRequest + { + UserId = string.Empty, + Queries = + [ + Query.Equal("name", new string('a', 4097)) + ] + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new ListUserTargetsRequest + { + UserId = string.Empty, + Queries = + [ + Query.Equal("name", new string('a', 4097)) + ] + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUsersRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUsersRequestTests.cs new file mode 100644 index 00000000..71ff8c99 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/ListUsersRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class ListUsersRequestTests : QuerySearchBaseRequestTests +{ + protected override ListUsersRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/RegenerateMfaRecoveryCodesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/RegenerateMfaRecoveryCodesRequestTests.cs new file mode 100644 index 00000000..7da40efd --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/RegenerateMfaRecoveryCodesRequestTests.cs @@ -0,0 +1,8 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class RegenerateMfaRecoveryCodesRequestTests : UserIdBaseRequestTests +{ + protected override RegenerateMfaRecoveryCodesRequest CreateValidRequest => new(); +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailRequestTests.cs new file mode 100644 index 00000000..475c0052 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailRequestTests.cs @@ -0,0 +1,108 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateEmailRequestTests : UserIdBaseRequestTests +{ + protected override UpdateEmailRequest CreateValidRequest => new() + { + Email = "pingu@example.com" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateEmailRequest(); + + // Assert + Assert.Equal(string.Empty, request.Email); + } + + [Fact] + public void Properties_CanBeSet() + { + var email = "pingu@example.com"; + + // Arrange + var request = new UpdateEmailRequest(); + + // Act + request.Email = email; + + // Assert + Assert.Equal(email, request.Email); + } + + [Theory] + [InlineData("valid@example.com")] + [InlineData("another.valid@example.com")] + public void IsValid_WithValidData_ReturnsTrue(string email) + { + // Arrange + var request = new UpdateEmailRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = email + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("invalid-email")] + public void IsValid_WithInvalidData_ReturnsFalse(string? email) + { + // Arrange + var request = new UpdateEmailRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = email! + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateEmailRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateEmailRequest + { + UserId = IdUtils.GenerateUniqueId(), + Email = "" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailVerificationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailVerificationRequestTests.cs new file mode 100644 index 00000000..3df6eea3 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateEmailVerificationRequestTests.cs @@ -0,0 +1,57 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateEmailVerificationRequestTests : UserIdBaseRequestTests +{ + protected override UpdateEmailVerificationRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateEmailVerificationRequest(); + + // Assert + Assert.False(request.EmailVerification); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new UpdateEmailVerificationRequest(); + + // Act + request.EmailVerification = true; + + // Assert + Assert.True(request.EmailVerification); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateEmailVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + EmailVerification = true + }, + new UpdateEmailVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + EmailVerification = false + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateEmailVerificationRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateMfaRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateMfaRequestTests.cs new file mode 100644 index 00000000..4cdacbbe --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateMfaRequestTests.cs @@ -0,0 +1,59 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateMfaRequestTests : UserIdBaseRequestTests +{ + protected override UpdateMfaRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateMfaRequest(); + + // Assert + Assert.False(request.Mfa); + } + + [Fact] + public void Properties_CanBeSet() + { + var mfa = true; + + // Arrange + var request = new UpdateMfaRequest(); + + // Act + request.Mfa = mfa; + + // Assert + Assert.Equal(mfa, request.Mfa); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateMfaRequest + { + UserId = IdUtils.GenerateUniqueId(), + Mfa = true + }, + new UpdateMfaRequest + { + UserId = IdUtils.GenerateUniqueId(), + Mfa = false + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateMfaRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateNameRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateNameRequestTests.cs new file mode 100644 index 00000000..3cab8724 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateNameRequestTests.cs @@ -0,0 +1,124 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateNameRequestTests : UserIdBaseRequestTests +{ + protected override UpdateNameRequest CreateValidRequest => new() + { + Name = "pingu" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateNameRequest(); + + // Assert + Assert.Equal(string.Empty, request.Name); + } + + [Fact] + public void Properties_CanBeSet() + { + var name = "New Name"; + + // Arrange + var request = new UpdateNameRequest(); + + // Act + request.Name = name; + + // Assert + Assert.Equal(name, request.Name); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = "Valid Name" + }, + new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = new string('a', 128) + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateNameRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = string.Empty + }, + new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = null! + }, + new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = new string('a', 129) + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(UpdateNameRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateNameRequest + { + UserId = IdUtils.GenerateUniqueId(), + Name = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePasswordRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePasswordRequestTests.cs new file mode 100644 index 00000000..92dd89a8 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePasswordRequestTests.cs @@ -0,0 +1,124 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdatePasswordRequestTests : UserIdBaseRequestTests +{ + protected override UpdatePasswordRequest CreateValidRequest => new() + { + Password = "MyPassword" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdatePasswordRequest(); + + // Assert + Assert.Equal(string.Empty, request.Password); + } + + [Fact] + public void Properties_CanBeSet() + { + var password = "NewPassword123"; + + // Arrange + var request = new UpdatePasswordRequest(); + + // Act + request.Password = password; + + // Assert + Assert.Equal(password, request.Password); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = "ValidPassword123" + }, + new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = "AnotherValidPassword456" + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdatePasswordRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = string.Empty + }, + new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = null! + }, + new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = "short" + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(UpdatePasswordRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdatePasswordRequest + { + UserId = IdUtils.GenerateUniqueId(), + Password = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneRequestTests.cs new file mode 100644 index 00000000..6492540a --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneRequestTests.cs @@ -0,0 +1,139 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdatePhoneRequestTests : UserIdBaseRequestTests +{ + protected override UpdatePhoneRequest CreateValidRequest => new() + { + PhoneNumber = "+16175551212" + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdatePhoneRequest(); + + // Assert + Assert.Equal(string.Empty, request.PhoneNumber); + } + + [Fact] + public void Properties_CanBeSet() + { + var phoneNumber = "+16175551212"; + + // Arrange + var request = new UpdatePhoneRequest(); + + // Act + request.PhoneNumber = phoneNumber; + + // Assert + Assert.Equal(phoneNumber, request.PhoneNumber); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "+16175551212" + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "+441632960961" + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdatePhoneRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = string.Empty + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = null! + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "6175551212" + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "+161755512121234567" + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "+text" + }, + new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = "+123456.9" + }, + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(UpdatePhoneRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdatePhoneRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneNumber = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneVerificationRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneVerificationRequestTests.cs new file mode 100644 index 00000000..d0115d1d --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdatePhoneVerificationRequestTests.cs @@ -0,0 +1,58 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdatePhoneVerificationRequestTests : UserIdBaseRequestTests +{ + protected override UpdatePhoneVerificationRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdatePhoneVerificationRequest(); + + // Assert + Assert.False(request.PhoneVerification); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new UpdatePhoneVerificationRequest(); + + // Act + request.PhoneVerification = true; + + // Assert + Assert.NotNull(request.UserId); + Assert.True(request.PhoneVerification); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdatePhoneVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneVerification = true + }, + new UpdatePhoneVerificationRequest + { + UserId = IdUtils.GenerateUniqueId(), + PhoneVerification = false + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdatePhoneVerificationRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserLabelsRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserLabelsRequestTests.cs new file mode 100644 index 00000000..a4a525dc --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserLabelsRequestTests.cs @@ -0,0 +1,120 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateUserLabelsRequestTests : UserIdBaseRequestTests +{ + protected override UpdateUserLabelsRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateUserLabelsRequest(); + + // Assert + Assert.NotNull(request.Labels); + Assert.Empty(request.Labels); + } + + [Fact] + public void Properties_CanBeSet() + { + var labels = new List { "Label1", "Label2", "Label3" }; + + // Arrange + var request = new UpdateUserLabelsRequest(); + + // Act + request.Labels = labels; + + // Assert + Assert.Collection(request.Labels, + x => Assert.Equal(labels[0], x), + x => Assert.Equal(labels[1], x), + x => Assert.Equal(labels[2], x)); + } + + public static IEnumerable ValidLabelsData => + [ + [new List { "Label1", "Label2", "Label3" }], + [new List { "A", "B", "C" }], + [new List()] + ]; + + [Theory] + [MemberData(nameof(ValidLabelsData))] + public void IsValid_WithValidData_ReturnsTrue(List labels) + { + // Arrange + var request = new UpdateUserLabelsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Labels = labels + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static IEnumerable InvalidLabelsData => + [ + [new List { "", "Label2", "Label3" }], // Invalid Label (empty string) + [new List { "Label1", "Label2", new string('a', 37) }], // Invalid Label (too long) + [new List { "Label1", "Label2", "Invalid@Label" }] // Invalid Label (non-alphanumeric) + ]; + + [Theory] + [MemberData(nameof(InvalidLabelsData))] + public void IsValid_WithInvalidData_ReturnsFalse(List labels) + { + // Arrange + var request = new UpdateUserLabelsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Labels = labels + }; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateUserLabelsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Labels = new List { "", "@@@" } + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateUserLabelsRequest + { + UserId = IdUtils.GenerateUniqueId(), + Labels = new List { "", "@@@" } + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserPreferencesRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserPreferencesRequestTests.cs new file mode 100644 index 00000000..bf6fe526 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserPreferencesRequestTests.cs @@ -0,0 +1,132 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateUserPreferencesRequestTests : UserIdBaseRequestTests +{ + protected override UpdateUserPreferencesRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateUserPreferencesRequest(); + + // Assert + Assert.NotNull(request.Preferences); + Assert.Empty(request.Preferences); + } + + [Fact] + public void Properties_CanBeSet() + { + var preferences = new Dictionary + { + { "theme", "dark" }, + { "notifications", "enabled" } + }; + + // Arrange + var request = new UpdateUserPreferencesRequest(); + + // Act + request.Preferences = preferences; + + // Assert + Assert.Collection(request.Preferences, + item => + { + Assert.Equal("theme", item.Key); + Assert.Equal("dark", item.Value); + }, + item => + { + Assert.Equal("notifications", item.Key); + Assert.Equal("enabled", item.Value); + } + ); + Assert.Equal(preferences, request.Preferences); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateUserPreferencesRequest + { + UserId = IdUtils.GenerateUniqueId(), + Preferences = new Dictionary + { + { "theme", "dark" }, + { "notifications", "enabled" } + } + }, + new UpdateUserPreferencesRequest + { + UserId = IdUtils.GenerateUniqueId(), + Preferences = new Dictionary() + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateUserPreferencesRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new UpdateUserPreferencesRequest + { + UserId = IdUtils.GenerateUniqueId(), + Preferences = null! + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(UpdateUserPreferencesRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateUserPreferencesRequest + { + UserId = IdUtils.GenerateUniqueId(), + Preferences = null! + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateUserPreferencesRequest + { + UserId = IdUtils.GenerateUniqueId(), + Preferences = null! + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserStatusRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserStatusRequestTests.cs new file mode 100644 index 00000000..3f661c1e --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserStatusRequestTests.cs @@ -0,0 +1,57 @@ +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateUserStatusRequestTests : UserIdBaseRequestTests +{ + protected override UpdateUserStatusRequest CreateValidRequest => new(); + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateUserStatusRequest(); + + // Assert + Assert.False(request.Status); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new UpdateUserStatusRequest(); + + // Act + request.Status = true; + + // Assert + Assert.True(request.Status); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateUserStatusRequest + { + UserId = IdUtils.GenerateUniqueId(), + Status = true + }, + new UpdateUserStatusRequest + { + UserId = IdUtils.GenerateUniqueId(), + Status = false + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateUserStatusRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserTargertRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserTargertRequestTests.cs new file mode 100644 index 00000000..b5d61b42 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UpdateUserTargertRequestTests.cs @@ -0,0 +1,148 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; +using PinguApps.Appwrite.Shared.Requests.Users.Validators; +using PinguApps.Appwrite.Shared.Utils; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public class UpdateUserTargertRequestTests : UserIdBaseRequestTests +{ + protected override UpdateUserTargertRequest CreateValidRequest => new() + { + TargetId = IdUtils.GenerateUniqueId() + }; + + [Fact] + public void Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = new UpdateUserTargertRequest(); + + // Assert + Assert.Equal(string.Empty, request.TargetId); + Assert.Null(request.Identifier); + Assert.Null(request.ProviderId); + Assert.Null(request.Name); + } + + [Fact] + public void Properties_CanBeSet() + { + // Arrange + var request = new UpdateUserTargertRequest(); + + // Act + request.TargetId = "validTargetId"; + request.Identifier = "validIdentifier"; + request.ProviderId = "validProviderId"; + request.Name = "Valid Name"; + + // Assert + Assert.Equal("validTargetId", request.TargetId); + Assert.Equal("validIdentifier", request.Identifier); + Assert.Equal("validProviderId", request.ProviderId); + Assert.Equal("Valid Name", request.Name); + } + + public static TheoryData ValidRequestsData = new() + { + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + Identifier = "validIdentifier", + ProviderId = "validProviderId", + Name = "Valid Name" + } + }; + + [Theory] + [MemberData(nameof(ValidRequestsData))] + public void IsValid_WithValidData_ReturnsTrue(UpdateUserTargertRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + public static TheoryData InvalidRequestsData = new() + { + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = null! + }, + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }, + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + Identifier = string.Empty + }, + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + ProviderId = string.Empty + }, + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + Name = string.Empty + }, + new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = IdUtils.GenerateUniqueId(), + Name = new string('a', 129) + } + }; + + [Theory] + [MemberData(nameof(InvalidRequestsData))] + public void IsValid_WithInvalidData_ReturnsFalse(UpdateUserTargertRequest request) + { + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new UpdateUserTargertRequest + { + UserId = IdUtils.GenerateUniqueId(), + TargetId = string.Empty + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UserIdBaseRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UserIdBaseRequestTests.cs new file mode 100644 index 00000000..9baff4fc --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/Users/UserIdBaseRequestTests.cs @@ -0,0 +1,92 @@ +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests.Users; + +namespace PinguApps.Appwrite.Shared.Tests.Requests.Users; +public abstract class UserIdBaseRequestTests + where TRequest : UserIdBaseRequest + where TValidator : AbstractValidator, new() +{ + protected abstract TRequest CreateValidRequest { get; } + + [Fact] + public void UserIdBase_Constructor_InitializesWithExpectedValues() + { + // Arrange & Act + var request = CreateValidRequest; + + // Assert + Assert.Equal(string.Empty, request.UserId); + } + + [Fact] + public void UserIdBase_Properties_CanBeSet() + { + // Arrange + var userIdValue = "validUserId"; + var request = CreateValidRequest; + + // Act + request.UserId = userIdValue; + + // Assert + Assert.Equal(userIdValue, request.UserId); + } + + [Fact] + public void UserIdBase_IsValid_WithValidUserId_ReturnsTrue() + { + // Arrange + var request = CreateValidRequest; + request.UserId = "valid_User-Id."; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData("invalid chars!")] + [InlineData(".startsWithSymbol")] + [InlineData("ThisIdHasTooManyCharactersAsTheLimitIs36")] + public void UserIdBase_IsValid_WithInvalidData_ReturnsFalse(string? userId) + { + // Arrange + var request = CreateValidRequest; + request.UserId = userId!; + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void UserIdBase_Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.UserId = string.Empty; // Invalid UserId + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void UserIdBase_Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = CreateValidRequest; + request.UserId = string.Empty; // Invalid UserId + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Responses/MembershipListTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Responses/MembershipListTests.cs new file mode 100644 index 00000000..54e87fd5 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Responses/MembershipListTests.cs @@ -0,0 +1,77 @@ +using System.Text.Json; +using PinguApps.Appwrite.Shared.Responses; + +namespace PinguApps.Appwrite.Shared.Tests.Responses; +public class MembershipListTests +{ + [Fact] + public void Constructor_AssignsPropertiesCorrectly() + { + // Arrange + var total = 5; + var id = "5e5ea5c16897e"; + var createdAt = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var updatedAt = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var userId = "5e5ea5c16897e"; + var userName = "John Doe"; + var userEmail = "john@appwrite.io"; + var teamId = "5e5ea5c16897e"; + var teamName = "VIP"; + var invited = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var joined = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var confirm = false; + var mfa = false; + var roles = new List { "owner" }; + + // Act + var membership = new Membership(id, createdAt, updatedAt, userId, userName, userEmail, teamId, teamName, invited, joined, confirm, mfa, roles); + var membershipsList = new MembershipsList(total, new List { membership }); + + // Assert + Assert.Equal(total, membershipsList.Total); + Assert.Single(membershipsList.Memberships); + var extractedMembership = membershipsList.Memberships[0]; + + Assert.Equal(id, extractedMembership.Id); + Assert.Equal(createdAt, extractedMembership.CreatedAt); + Assert.Equal(updatedAt, extractedMembership.UpdatedAt); + Assert.Equal(userId, extractedMembership.UserId); + Assert.Equal(userName, extractedMembership.UserName); + Assert.Equal(userEmail, extractedMembership.UserEmail); + Assert.Equal(teamId, extractedMembership.TeamId); + Assert.Equal(teamName, extractedMembership.TeamName); + Assert.Equal(invited, extractedMembership.Invited); + Assert.Equal(joined, extractedMembership.Joined); + Assert.Equal(confirm, extractedMembership.Confirm); + Assert.Equal(mfa, extractedMembership.Mfa); + Assert.Equal(roles, extractedMembership.Roles); + } + + [Fact] + public void CanBeDeserialized_FromJson() + { + // Act + var membershipsList = JsonSerializer.Deserialize(Constants.MembershipsListResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + // Assert + Assert.NotNull(membershipsList); + Assert.Equal(5, membershipsList.Total); + Assert.Single(membershipsList.Memberships); + var membership = membershipsList.Memberships[0]; + + Assert.Equal("5e5ea5c16897e", membership.Id); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), membership.CreatedAt.ToUniversalTime()); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), membership.UpdatedAt.ToUniversalTime()); + Assert.Equal("5e5ea5c16897e", membership.UserId); + Assert.Equal("John Doe", membership.UserName); + Assert.Equal("john@appwrite.io", membership.UserEmail); + Assert.Equal("5e5ea5c16897e", membership.TeamId); + Assert.Equal("VIP", membership.TeamName); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), membership.Invited.ToUniversalTime()); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), membership.Joined.ToUniversalTime()); + Assert.False(membership.Confirm); + Assert.False(membership.Mfa); + Assert.Single(membership.Roles); + Assert.Equal("owner", membership.Roles[0]); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Responses/TargetListTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Responses/TargetListTests.cs new file mode 100644 index 00000000..16687504 --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Responses/TargetListTests.cs @@ -0,0 +1,62 @@ +using System.Text.Json; +using PinguApps.Appwrite.Shared.Enums; +using PinguApps.Appwrite.Shared.Responses; + +namespace PinguApps.Appwrite.Shared.Tests.Responses; +public class TargetListTests +{ + [Fact] + public void Constructor_AssignsPropertiesCorrectly() + { + // Arrange + var total = 5; + var id = "259125845563242502"; + var createdAt = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var updatedAt = DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(); + var name = "Aegon apple token"; + var userId = "259125845563242502"; + var providerId = "259125845563242502"; + var providerType = TargetProviderType.Email; + var identifier = "token"; + + // Act + var target = new Target(id, createdAt, updatedAt, name, userId, providerId, providerType, identifier); + var targetList = new TargetList(total, new List { target }); + + // Assert + Assert.Equal(total, targetList.Total); + Assert.Single(targetList.Targets); + var extractedTarget = targetList.Targets[0]; + + Assert.Equal(id, extractedTarget.Id); + Assert.Equal(createdAt, extractedTarget.CreatedAt); + Assert.Equal(updatedAt, extractedTarget.UpdatedAt); + Assert.Equal(name, extractedTarget.Name); + Assert.Equal(userId, extractedTarget.UserId); + Assert.Equal(providerId, extractedTarget.ProviderId); + Assert.Equal(providerType, extractedTarget.ProviderType); + Assert.Equal(identifier, extractedTarget.Identifier); + } + + [Fact] + public void CanBeDeserialized_FromJson() + { + // Act + var targetList = JsonSerializer.Deserialize(Constants.TargetListResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + // Assert + Assert.NotNull(targetList); + Assert.Equal(5, targetList.Total); + Assert.Single(targetList.Targets); + var target = targetList.Targets[0]; + + Assert.Equal("259125845563242502", target.Id); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), target.CreatedAt.ToUniversalTime()); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), target.UpdatedAt.ToUniversalTime()); + Assert.Equal("Aegon apple token", target.Name); + Assert.Equal("259125845563242502", target.UserId); + Assert.Equal("259125845563242502", target.ProviderId); + Assert.Equal(TargetProviderType.Email, target.ProviderType); + Assert.Equal("token", target.Identifier); + } +} diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Responses/UserListTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Responses/UserListTests.cs new file mode 100644 index 00000000..3841556e --- /dev/null +++ b/tests/PinguApps.Appwrite.Shared.Tests/Responses/UserListTests.cs @@ -0,0 +1,109 @@ +using System.Text.Json; +using PinguApps.Appwrite.Shared.Enums; +using PinguApps.Appwrite.Shared.Responses; + +namespace PinguApps.Appwrite.Shared.Tests.Responses; +public class UserListTests +{ + [Fact] + public void Constructor_AssignsPropertiesCorrectly() + { + // Arrange + var total = 5; + var id = "5e5ea5c16897e"; + var createdAt = DateTime.UtcNow; + var updatedAt = DateTime.UtcNow; + var name = "John Doe"; + var password = "$argon2id$v=19$m=2048,t=4,p=3$aUZjLnliVWRINmFNTWMudg$5S+x+7uA31xFnrHFT47yFwcJeaP0w92L/4LdgrVRXxE"; + var hash = "argon2"; + var hashOptions = new HashOptions("argon2", 65536, 4, 3); + var registration = DateTime.UtcNow; + var status = true; + var labels = new List { "vip" }; + var passwordUpdate = DateTime.UtcNow; + var email = "john@appwrite.io"; + var phone = "+4930901820"; + var emailVerification = true; + var phoneVerification = true; + var mfa = true; + var prefs = new Dictionary(); + var targets = new List { new Target("259125845563242502", DateTime.UtcNow, DateTime.UtcNow, "Aegon apple token", "259125845563242502", "259125845563242502", TargetProviderType.Email, "token") }; + var accessedAt = DateTime.UtcNow; + + // Act + var user = new User(id, createdAt, updatedAt, name, password, hash, hashOptions, registration, status, labels, passwordUpdate, email, phone, emailVerification, phoneVerification, mfa, prefs, targets, accessedAt); + var usersList = new UsersList(total, new List { user }); + + // Assert + Assert.Equal(total, usersList.Total); + Assert.Single(usersList.Users); + var extractedUser = usersList.Users[0]; + + Assert.Equal(id, extractedUser.Id); + Assert.Equal(createdAt.ToUniversalTime(), extractedUser.CreatedAt.ToUniversalTime()); + Assert.Equal(updatedAt.ToUniversalTime(), extractedUser.UpdatedAt.ToUniversalTime()); + Assert.Equal(name, extractedUser.Name); + Assert.Equal(password, extractedUser.Password); + Assert.Equal(hash, extractedUser.Hash); + Assert.Equal(hashOptions, extractedUser.HashOptions); + Assert.Equal(registration.ToUniversalTime(), extractedUser.Registration.ToUniversalTime()); + Assert.Equal(status, extractedUser.Status); + Assert.Equal(labels, extractedUser.Labels); + Assert.Equal(passwordUpdate.ToUniversalTime(), extractedUser.PasswordUpdate.ToUniversalTime()); + Assert.Equal(email, extractedUser.Email); + Assert.Equal(phone, extractedUser.Phone); + Assert.Equal(emailVerification, extractedUser.EmailVerification); + Assert.Equal(phoneVerification, extractedUser.PhoneVerification); + Assert.Equal(mfa, extractedUser.Mfa); + Assert.Equal(prefs, extractedUser.Prefs); + Assert.Equal(targets, extractedUser.Targets); + Assert.Equal(accessedAt.ToUniversalTime(), extractedUser.AccessedAt.ToUniversalTime()); + } + + [Fact] + public void CanBeDeserialized_FromJson() + { + // Act + var usersList = JsonSerializer.Deserialize(Constants.UsersListResponse, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + // Assert + Assert.NotNull(usersList); + Assert.Equal(5, usersList.Total); + Assert.Single(usersList.Users); + var user = usersList.Users[0]; + + Assert.Equal("5e5ea5c16897e", user.Id); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), user.CreatedAt.ToUniversalTime()); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), user.UpdatedAt.ToUniversalTime()); + Assert.Equal("John Doe", user.Name); + Assert.Equal("$argon2id$v=19$m=2048,t=4,p=3$aUZjLnliVWRINmFNTWMudg$5S+x+7uA31xFnrHFT47yFwcJeaP0w92L/4LdgrVRXxE", user.Password); + Assert.Equal("argon2", user.Hash); + Assert.NotNull(user.HashOptions); + Assert.Equal("argon2", user.HashOptions.Type); + Assert.Equal(65536, user.HashOptions.MemoryCost); + Assert.Equal(4, user.HashOptions.TimeCost); + Assert.Equal(3, user.HashOptions.Threads); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), user.Registration.ToUniversalTime()); + Assert.True(user.Status); + Assert.Single(user.Labels); + Assert.Equal("vip", user.Labels[0]); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), user.PasswordUpdate.ToUniversalTime()); + Assert.Equal("john@appwrite.io", user.Email); + Assert.Equal("+4930901820", user.Phone); + Assert.True(user.EmailVerification); + Assert.True(user.PhoneVerification); + Assert.True(user.Mfa); + Assert.NotNull(user.Prefs); + Assert.Single(user.Targets); + var target = user.Targets[0]; + Assert.Equal("259125845563242502", target.Id); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), target.CreatedAt.ToUniversalTime()); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), target.UpdatedAt.ToUniversalTime()); + Assert.Equal("Aegon apple token", target.Name); + Assert.Equal("259125845563242502", target.UserId); + Assert.Equal("259125845563242502", target.ProviderId); + Assert.Equal(TargetProviderType.Email, target.ProviderType); + Assert.Equal("token", target.Identifier); + Assert.Equal(DateTime.Parse("2020-10-15T06:38:00.000+00:00").ToUniversalTime(), user.AccessedAt.ToUniversalTime()); + } +}