-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, "[email protected]", "Password", null)] | ||
[InlineData("321654987", "[email protected]", "12345678", "Pingu")] | ||
[InlineData("a.s-d_f", "[email protected]", "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^", "[email protected]", "Password", "Pingu")] | ||
[InlineData(".bad", "[email protected]", "Password", "Pingu")] | ||
[InlineData("_bad", "[email protected]", "Password", "Pingu")] | ||
[InlineData("-bad", "[email protected]", "Password", "Pingu")] | ||
[InlineData("", "[email protected]", "Password", "Pingu")] | ||
[InlineData("1234567890123456789012345678901234567", "[email protected]", "Password", "Pingu")] | ||
[InlineData(null, "not an email", "Password", "Pingu")] | ||
[InlineData(null, "", "Password", "Pingu")] | ||
[InlineData(null, "[email protected]", "short", "Pingu")] | ||
[InlineData(null, "[email protected]", "", "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<ValidationException>(() => 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); | ||
} | ||
} |