diff --git a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs b/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs index 9f92b18f..2ea80a7d 100644 --- a/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs +++ b/tests/PinguApps.Appwrite.Shared.Tests/Requests/CreateAccountRequestTests.cs @@ -1,4 +1,5 @@ -using PinguApps.Appwrite.Shared.Requests; +using FluentValidation; +using PinguApps.Appwrite.Shared.Requests; namespace PinguApps.Appwrite.Shared.Tests.Requests; public class CreateAccountRequestTests @@ -35,4 +36,96 @@ public void Properties_CanBeSet(string email, string password, string? name) Assert.Equal(password, request.Password); Assert.Equal(name, request.Name); } + + [Theory] + [InlineData(null, "pingu@example.com", "Password", null)] + [InlineData("321654987", "pingu@example.com", "12345678", "Pingu")] + [InlineData("a.s-d_f", "pingu@example.com", "12345678", "Pingu")] + public void IsValid_WithValidData_ReturnsTrue(string? userId, string email, string password, string? name) + { + // Arrange + var request = new CreateAccountRequest + { + Email = email, + Password = password, + Name = name + }; + + if (userId is not null) + { + request.UserId = userId; + } + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.True(isValid); + } + + [Theory] + [InlineData("badChar^", "pingu@example.com", "Password", "Pingu")] + [InlineData(".bad", "pingu@example.com", "Password", "Pingu")] + [InlineData("_bad", "pingu@example.com", "Password", "Pingu")] + [InlineData("-bad", "pingu@example.com", "Password", "Pingu")] + [InlineData("", "pingu@example.com", "Password", "Pingu")] + [InlineData("1234567890123456789012345678901234567", "pingu@example.com", "Password", "Pingu")] + [InlineData(null, "not an email", "Password", "Pingu")] + [InlineData(null, "", "Password", "Pingu")] + [InlineData(null, "pingu@example.com", "short", "Pingu")] + [InlineData(null, "pingu@example.com", "", "Pingu")] + public void IsValid_WithInvalidData_ReturnsFalse(string? userId, string email, string password, string? name) + { + // Arrange + var request = new CreateAccountRequest + { + Email = email, + Password = password, + Name = name + }; + + if (userId is not null) + { + request.UserId = userId; + } + + // Act + var isValid = request.IsValid(); + + // Assert + Assert.False(isValid); + } + + [Fact] + public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure() + { + // Arrange + var request = new CreateAccountRequest + { + UserId = ".badChar^", + Email = "not an email", + Password = "short" + }; + + // Assert + Assert.Throws(() => request.Validate(true)); + } + + [Fact] + public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure() + { + // Arrange + var request = new CreateAccountRequest + { + UserId = ".badChar^", + Email = "not an email", + Password = "short" + }; + + // Act + var result = request.Validate(false); + + // Assert + Assert.False(result.IsValid); + } }