Skip to content

Commit

Permalink
added shared tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Aug 10, 2024
1 parent f0b0ea1 commit 8ec32ef
Showing 1 changed file with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using FluentValidation;
using PinguApps.Appwrite.Shared.Requests;

namespace PinguApps.Appwrite.Shared.Tests.Requests;
public class CreatePasswordRecoveryTests
{
[Fact]
public void Constructor_InitializesWithExpectedValues()
{
// Arrange & Act
var request = new CreatePasswordRecoveryRequest();

// Assert
Assert.Equal(string.Empty, request.Email);
Assert.Equal(string.Empty, request.Url);
}

[Fact]
public void Properties_CanBeSet()
{
var url = "https://localhost:1234/abc";
var email = "[email protected]";

// Arrange
var request = new CreatePasswordRecoveryRequest();

// Act
request.Url = url;
request.Email = email;

// Assert
Assert.Equal(url, request.Url);
Assert.Equal(email, request.Email);
}

[Fact]
public void IsValid_WithValidData_ReturnsTrue()
{
// Arrange
var request = new CreatePasswordRecoveryRequest
{
Email = "[email protected]",
Url = "https://localhost:1234/abc"
};

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

// Assert
Assert.True(isValid);
}

[Theory]
[InlineData(null, "https://localhost:1234/abc")]
[InlineData("", "https://localhost:1234/abc")]
[InlineData("Not an email", "https://localhost:1234/abc")]
[InlineData("[email protected]", null)]
[InlineData("[email protected]", "")]
[InlineData("[email protected]", "Not a URL")]
public void IsValid_WithInvalidData_ReturnsFalse(string? email, string? url)
{
// Arrange
var request = new CreatePasswordRecoveryRequest
{
Email = email!,
Url = url!
};

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

// Assert
Assert.False(isValid);
}

[Fact]
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure()
{
// Arrange
var request = new CreatePasswordRecoveryRequest
{
Email = "",
Url = ""
};

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

[Fact]
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure()
{
// Arrange
var request = new CreatePasswordRecoveryRequest
{
Email = "",
Url = ""
};

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

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

0 comments on commit 8ec32ef

Please sign in to comment.