174 lines
4.3 KiB
C#
174 lines
4.3 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"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_EqualsIgnoreCase_MixedCase_ReturnsTrue()
|
|
{
|
|
_sut.Compare("Hello", "equalsIgnoreCase", "hello").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_EqualsIgnoreCase_DifferentString_ReturnsFalse()
|
|
{
|
|
_sut.Compare("Hello", "equalsIgnoreCase", "world").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_ContainsIgnoreCase_ReturnsTrue()
|
|
{
|
|
_sut.Compare("Hello World", "containsIgnoreCase", "WORLD").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_ContainsIgnoreCase_ReturnsFalse()
|
|
{
|
|
_sut.Compare("Hello World", "containsIgnoreCase", "xyz").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_StartsWithIgnoreCase_ReturnsTrue()
|
|
{
|
|
_sut.Compare("Hello World", "startsWithIgnoreCase", "HELLO").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_StartsWithIgnoreCase_ReturnsFalse()
|
|
{
|
|
_sut.Compare("Hello World", "startsWithIgnoreCase", "world").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_EndsWithIgnoreCase_ReturnsTrue()
|
|
{
|
|
_sut.Compare("Hello World", "endsWithIgnoreCase", "WORLD").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_EndsWithIgnoreCase_ReturnsFalse()
|
|
{
|
|
_sut.Compare("Hello World", "endsWithIgnoreCase", "hello").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_EqualsIgnoreCase_NullField_ReturnsFalse()
|
|
{
|
|
_sut.Compare(null, "equalsIgnoreCase", "hello").Should().BeFalse();
|
|
}
|
|
}
|