work-flow/tests/Workflow.Tests/Condition/ValueComparatorRegistryTests.cs
向宁 fc4ecbbacc feat: add gRPC auth, condition comparators, seed data, EF migrations
- 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
2026-05-20 20:28:35 +08:00

95 lines
2.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 返回 falseStringComparator 兜底
_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();
}
}