- gRPC auth service for token validation - Value comparator system (string, numeric, boolean, datetime, collection) - Condition evaluator with strategy chain - Form definition and data improvements - Workflow instance/task endpoints updated - Seed data and EF design-time factory - Test coverage for comparators and handlers
95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
namespace Workflow.Tests.Condition;
|
||
|
||
using FluentAssertions;
|
||
using Workflow.Application.Expressions;
|
||
using Workflow.Domain.Expressions.Comparators;
|
||
using Xunit;
|
||
|
||
public class ValueComparatorRegistryTests
|
||
{
|
||
private readonly ValueComparatorRegistry _registry;
|
||
|
||
public ValueComparatorRegistryTests()
|
||
{
|
||
IValueComparator[] comparators =
|
||
[
|
||
new NumericComparator(),
|
||
new DateTimeComparator(),
|
||
new BooleanComparator(),
|
||
new CollectionComparator(),
|
||
new StringComparator(),
|
||
];
|
||
_registry = new ValueComparatorRegistry(comparators);
|
||
}
|
||
|
||
[Fact]
|
||
public void RegisteredOperators_ContainsAllExpected()
|
||
{
|
||
_registry.RegisteredOperators.Should().Contain(
|
||
"==", "!=", ">", "<", ">=", "<=",
|
||
"contains", "startsWith", "endsWith", "isEmpty", "in");
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_NumericEquals_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare(10, "==", 10).Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_StringEquals_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare("hello", "==", "hello").Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_NumericGreaterThan_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare(10, ">", 5).Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_StringContains_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare("hello world", "contains", "world").Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_UnregisteredOperator_ReturnsFalse()
|
||
{
|
||
_registry.TryCompare(10, "unknown_op", 5).Should().BeFalse();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_NumericFallsThroughToString()
|
||
{
|
||
// "hello" 不是数值,NumericComparator 返回 false,StringComparator 兜底
|
||
_registry.TryCompare("hello", "==", "hello").Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_BoolEquals_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare(true, "==", "true").Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void Constructor_EmptyComparators_NoOperators()
|
||
{
|
||
var registry = new ValueComparatorRegistry([]);
|
||
registry.RegisteredOperators.Should().BeEmpty();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_DateTimeGreaterThan_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare("2024-06-01", ">", "2024-01-01").Should().BeTrue();
|
||
}
|
||
|
||
[Fact]
|
||
public void TryCompare_NumericNotEquals_ReturnsTrue()
|
||
{
|
||
_registry.TryCompare(5, "!=", 10).Should().BeTrue();
|
||
}
|
||
}
|