Skip to content

Commit

Permalink
Added tests for update email request
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 9, 2024
1 parent 468e600 commit 3e1089c
Showing 1 changed file with 73 additions and 1 deletion.
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 UpdateEmailRequestTests
Expand Down Expand Up @@ -32,4 +33,75 @@ public void Properties_CanBeSet(string email, string password)
Assert.Equal(email, request.Email);
Assert.Equal(password, request.Password);
}

[Theory]
[InlineData("[email protected]", "Password")]
[InlineData("[email protected]", "£$%^&*()")]
public void IsValid_WithValidData_ReturnsTrue(string email, string password)
{
// Arrange
var request = new UpdateEmailRequest
{
Email = email,
Password = password
};

// Act
var isValid = request.IsValid();

// Assert
Assert.True(isValid);
}

[Theory]
[InlineData("not an email", "Password")]
[InlineData("", "Password")]
[InlineData("[email protected]", "short")]
[InlineData("[email protected]", "")]
public void IsValid_WithInvalidData_ReturnsFalse(string email, string password)
{
// Arrange
var request = new UpdateEmailRequest
{
Email = email,
Password = password
};

// Act
var isValid = request.IsValid();

// Assert
Assert.False(isValid);
}

[Fact]
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure()
{
// Arrange
var request = new UpdateEmailRequest
{
Email = "not an email",
Password = "short"
};

// Assert
Assert.Throws<ValidationException>(() => request.Validate(true));
}

[Fact]
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure()
{
// Arrange
var request = new UpdateEmailRequest
{
Email = "not an email",
Password = "short"
};

// Act
var result = request.Validate(false);

// Assert
Assert.False(result.IsValid);
}
}

0 comments on commit 3e1089c

Please sign in to comment.