work-flow/tests/Workflow.Tests/Condition/StringComparatorTests.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

120 lines
2.8 KiB
C#

namespace Workflow.Tests.Condition;
using System.Text.Json;
using FluentAssertions;
using Workflow.Domain.Expressions.Comparators;
using Xunit;
public class StringComparatorTests
{
private readonly StringComparator _sut = new();
[Fact]
public void Compare_Equals_SameString_ReturnsTrue()
{
_sut.Compare("hello", "==", "hello").Should().BeTrue();
}
[Fact]
public void Compare_Equals_DifferentString_ReturnsFalse()
{
_sut.Compare("hello", "==", "world").Should().BeFalse();
}
[Fact]
public void Compare_NotEquals_DifferentString_ReturnsTrue()
{
_sut.Compare("hello", "!=", "world").Should().BeTrue();
}
[Fact]
public void Compare_Contains_True()
{
_sut.Compare("hello world", "contains", "world").Should().BeTrue();
}
[Fact]
public void Compare_Contains_False()
{
_sut.Compare("hello world", "contains", "xyz").Should().BeFalse();
}
[Fact]
public void Compare_Contains_CaseSensitive()
{
_sut.Compare("Hello", "contains", "hello").Should().BeFalse();
}
[Fact]
public void Compare_StartsWith_True()
{
_sut.Compare("hello world", "startsWith", "hello").Should().BeTrue();
}
[Fact]
public void Compare_StartsWith_False()
{
_sut.Compare("hello world", "startsWith", "world").Should().BeFalse();
}
[Fact]
public void Compare_EndsWith_True()
{
_sut.Compare("hello world", "endsWith", "world").Should().BeTrue();
}
[Fact]
public void Compare_EndsWith_False()
{
_sut.Compare("hello world", "endsWith", "hello").Should().BeFalse();
}
[Fact]
public void Compare_IsEmpty_EmptyString_ReturnsTrue()
{
_sut.Compare("", "isEmpty", null).Should().BeTrue();
}
[Fact]
public void Compare_IsEmpty_NullField_ReturnsTrue()
{
_sut.Compare(null, "isEmpty", null).Should().BeTrue();
}
[Fact]
public void Compare_IsEmpty_Whitespace_ReturnsTrue()
{
_sut.Compare(" ", "isEmpty", null).Should().BeTrue();
}
[Fact]
public void Compare_IsEmpty_NonEmpty_ReturnsFalse()
{
_sut.Compare("hello", "isEmpty", null).Should().BeFalse();
}
[Fact]
public void Compare_UnsupportedOperator_ReturnsFalse()
{
_sut.Compare("hello", ">", "world").Should().BeFalse();
}
[Fact]
public void Compare_NullField_Equals_ReturnsFalse()
{
_sut.Compare(null, "==", "hello").Should().BeFalse();
}
[Fact]
public void Compare_Equals_CaseSensitive()
{
_sut.Compare("Hello", "==", "hello").Should().BeFalse();
}
[Fact]
public void Compare_SupportedOperators_ContainsExpected()
{
_sut.SupportedOperators.Should().Contain(["==", "!=", "contains", "startsWith", "endsWith", "isEmpty"]);
}
}