Adds pagination and filtering to the API

This commit is contained in:
BinaryAlley committed 2026-08-16 03:10:47 -07:00
1 parent ad984910a2
commit ce4ebf36bc
59 files changed
+4423 -242

No files matched your search

@@ -0,0 +1,94 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Specifications;
using Lumina.Application.Fixtures.Common.Specifications;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
#endregion
namespace Lumina.Application.UnitTests.Common.Specifications;
/// <summary>
/// Contains unit tests for the <see cref="AndFilterSpecification{T}"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AndFilterSpecificationTests
{
[Fact]
public void ToExpression_WhenBothSpecificationsSatisfyCriteria_ShouldReturnExpressionThatEvaluatesToTrue()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
AndFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.True(predicate(20));
}
[Fact]
public void ToExpression_WhenOnlyLeftSpecificationSatisfiesCriteria_ShouldReturnExpressionThatEvaluatesToFalse()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
AndFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.False(predicate(8));
}
[Fact]
public void ToExpression_WhenNeitherSpecificationSatisfiesCriteria_ShouldReturnExpressionThatEvaluatesToFalse()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
AndFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.False(predicate(2));
}
[Fact]
public void IsSatisfiedBy_WhenBothSpecificationsAreSatisfied_ShouldReturnTrue()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysTrueFilterSpecificationFixture<int> right = new();
AndFilterSpecification<int> specification = new(left, right);
// Act
bool result = specification.IsSatisfiedBy(0);
// Assert
Assert.True(result);
}
[Fact]
public void IsSatisfiedBy_WhenEitherSpecificationIsNotSatisfied_ShouldReturnFalse()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
AndFilterSpecification<int> specification = new(left, right);
// Act
bool result = specification.IsSatisfiedBy(0);
// Assert
Assert.False(result);
}
}
@@ -0,0 +1,130 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Specifications;
using Lumina.Application.Fixtures.Common.Specifications;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
#endregion
namespace Lumina.Application.UnitTests.Common.Specifications;
/// <summary>
/// Contains unit tests for the <see cref="FilterSpecification{T}"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FilterSpecificationTests
{
[Fact]
public void ToExpression_WhenCalledOnConcreteSpecification_ShouldReturnExpressionMatchingCriteria()
{
// Arrange
GreaterThanFilterSpecificationFixture specification = new(10);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.True(predicate(15));
Assert.False(predicate(5));
}
[Fact]
public void IsSatisfiedBy_WhenEntitySatisfiesCriteria_ShouldReturnTrue()
{
// Arrange
GreaterThanFilterSpecificationFixture specification = new(10);
int entity = 20;
// Act
bool result = specification.IsSatisfiedBy(entity);
// Assert
Assert.True(result);
}
[Fact]
public void IsSatisfiedBy_WhenEntityDoesNotSatisfyCriteria_ShouldReturnFalse()
{
// Arrange
GreaterThanFilterSpecificationFixture specification = new(10);
int entity = 5;
// Act
bool result = specification.IsSatisfiedBy(entity);
// Assert
Assert.False(result);
}
[Fact]
public void And_WhenBothSpecificationsAreSatisfied_ShouldReturnSpecificationSatisfiedByEntity()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysTrueFilterSpecificationFixture<int> right = new();
// Act
FilterSpecification<int> combined = left.And(right);
// Assert
Assert.IsType<AndFilterSpecification<int>>(combined);
Assert.True(combined.IsSatisfiedBy(0));
}
[Fact]
public void And_WhenOneSpecificationIsNotSatisfied_ShouldReturnSpecificationNotSatisfiedByEntity()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
// Act
FilterSpecification<int> combined = left.And(right);
// Assert
Assert.False(combined.IsSatisfiedBy(0));
}
[Fact]
public void And_WhenBothSpecificationsAreNotSatisfied_ShouldReturnSpecificationNotSatisfiedByEntity()
{
// Arrange
AlwaysFalseFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
// Act
FilterSpecification<int> combined = left.And(right);
// Assert
Assert.False(combined.IsSatisfiedBy(0));
}
[Fact]
public void Or_WhenAtLeastOneSpecificationIsSatisfied_ShouldReturnSpecificationSatisfiedByEntity()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
// Act
FilterSpecification<int> combined = left.Or(right);
// Assert
Assert.True(combined.IsSatisfiedBy(0));
}
[Fact]
public void Or_WhenNeitherSpecificationIsSatisfied_ShouldReturnSpecificationNotSatisfiedByEntity()
{
// Arrange
AlwaysFalseFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
// Act
FilterSpecification<int> combined = left.Or(right);
// Assert
Assert.False(combined.IsSatisfiedBy(0));
}
}
@@ -0,0 +1,110 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Specifications;
using Lumina.Application.Fixtures.Common.Specifications;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
#endregion
namespace Lumina.Application.UnitTests.Common.Specifications;
/// <summary>
/// Contains unit tests for the <see cref="OrFilterSpecification{T}"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OrFilterSpecificationTests
{
[Fact]
public void ToExpression_WhenOnlyLeftSpecificationSatisfiesCriteria_ShouldReturnExpressionThatEvaluatesToTrue()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
OrFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.True(predicate(8));
}
[Fact]
public void ToExpression_WhenOnlyRightSpecificationSatisfiesCriteria_ShouldReturnExpressionThatEvaluatesToTrue()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(10);
GreaterThanFilterSpecificationFixture right = new(5);
OrFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.True(predicate(8));
}
[Fact]
public void ToExpression_WhenBothSpecificationsSatisfyCriteria_ShouldReturnExpressionThatEvaluatesToTrue()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
OrFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.True(predicate(20));
}
[Fact]
public void ToExpression_WhenNeitherSpecificationSatisfiesCriteria_ShouldReturnExpressionThatEvaluatesToFalse()
{
// Arrange
GreaterThanFilterSpecificationFixture left = new(5);
GreaterThanFilterSpecificationFixture right = new(10);
OrFilterSpecification<int> specification = new(left, right);
// Act
Expression<Func<int, bool>> expression = specification.ToExpression();
Func<int, bool> predicate = expression.Compile();
// Assert
Assert.False(predicate(2));
}
[Fact]
public void IsSatisfiedBy_WhenAtLeastOneSpecificationIsSatisfied_ShouldReturnTrue()
{
// Arrange
AlwaysTrueFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
OrFilterSpecification<int> specification = new(left, right);
// Act
bool result = specification.IsSatisfiedBy(0);
// Assert
Assert.True(result);
}
[Fact]
public void IsSatisfiedBy_WhenNeitherSpecificationIsSatisfied_ShouldReturnFalse()
{
// Arrange
AlwaysFalseFilterSpecificationFixture<int> left = new();
AlwaysFalseFilterSpecificationFixture<int> right = new();
OrFilterSpecification<int> specification = new(left, right);
// Act
bool result = specification.IsSatisfiedBy(0);
// Assert
Assert.False(result);
}
}