Skip to content

Commit

Permalink
Added create session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 15, 2024
1 parent f6f54eb commit 2f14b2c
Showing 1 changed file with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

using FluentValidation;
using PinguApps.Appwrite.Shared.Requests;

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

// Assert
Assert.NotEmpty(request.UserId);
Assert.Equal(string.Empty, request.Secret);
}

[Fact]
public void Properties_CanBeSet()
{
var userId = "123456";
var secret = "[email protected]";

// Arrange
var request = new CreateSessionRequest();

// Act
request.UserId = userId;
request.Secret = secret;

// Assert
Assert.Equal(userId, request.UserId);
Assert.Equal(secret, request.Secret);
}

[Fact]
public void IsValid_WithValidData_ReturnsTrue()
{
// Arrange
var request = new CreateSessionRequest
{
UserId = "123456",
Secret = "654321"
};

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

// Assert
Assert.True(isValid);
}

[Theory]
[InlineData("badChar^", "654321")]
[InlineData(".bad", "654321")]
[InlineData("_bad", "654321")]
[InlineData("-bad", "654321")]
[InlineData("", "654321")]
[InlineData("1234567890123456789012345678901234567", "654321")]
[InlineData("123456", "")]
public void IsValid_WithInvalidData_ReturnsFalse(string userId, string secret)
{
// Arrange
var request = new CreateSessionRequest
{
UserId = userId,
Secret = secret
};

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

// Assert
Assert.False(isValid);
}

[Fact]
public void Validate_WithThrowOnFailuresTrue_ThrowsValidationExceptionOnFailure()
{
// Arrange
var request = new CreateSessionRequest
{
UserId = ".badChar^",
Secret = ""
};

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

[Fact]
public void Validate_WithThrowOnFailuresFalse_ReturnsInvalidResultOnFailure()
{
// Arrange
var request = new CreateSessionRequest
{
UserId = ".badChar^",
Secret = ""
};

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

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

0 comments on commit 2f14b2c

Please sign in to comment.