112 lines
3.1 KiB
C#
112 lines
3.1 KiB
C#
namespace Workflow.Tests.Condition;
|
|
|
|
using System.Text.Json;
|
|
using FluentAssertions;
|
|
using Workflow.Domain.Expressions.Comparators;
|
|
using Xunit;
|
|
|
|
public class CollectionComparatorTests
|
|
{
|
|
private readonly CollectionComparator _sut = new();
|
|
|
|
[Fact]
|
|
public void Compare_In_ValueInArray_ReturnsTrue()
|
|
{
|
|
var array = JsonDocument.Parse("""["pending", "review", "approved"]""").RootElement;
|
|
_sut.Compare("review", "in", array).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_ValueNotInArray_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("""["pending", "review"]""").RootElement;
|
|
_sut.Compare("rejected", "in", array).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_NumericValue_ReturnsTrue()
|
|
{
|
|
var array = JsonDocument.Parse("[1, 3, 5, 7]").RootElement;
|
|
_sut.Compare(5, "in", array).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_EmptyArray_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("[]").RootElement;
|
|
_sut.Compare("value", "in", array).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_CommaSeparatedString_ReturnsTrue()
|
|
{
|
|
_sut.Compare("review", "in", "pending,review,approved").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_CommaSeparatedString_ReturnsFalse()
|
|
{
|
|
_sut.Compare("rejected", "in", "pending,review").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NullField_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("""["value"]""").RootElement;
|
|
_sut.Compare(null, "in", array).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NullCondition_ReturnsFalse()
|
|
{
|
|
_sut.Compare("value", "in", null).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_UnsupportedOperator_ReturnsFalse()
|
|
{
|
|
_sut.Compare("value", "==", "something").Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_In_NumericValueNotInArray_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("[1, 3, 5, 7]").RootElement;
|
|
_sut.Compare(4, "in", array).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NotIn_ValueNotInArray_ReturnsTrue()
|
|
{
|
|
var array = JsonDocument.Parse("""["pending", "review"]""").RootElement;
|
|
_sut.Compare("rejected", "notIn", array).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NotIn_ValueInArray_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("""["pending", "review", "approved"]""").RootElement;
|
|
_sut.Compare("review", "notIn", array).Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NotIn_EmptyArray_ReturnsTrue()
|
|
{
|
|
var array = JsonDocument.Parse("[]").RootElement;
|
|
_sut.Compare("value", "notIn", array).Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NotIn_CommaSeparatedString_ReturnsTrue()
|
|
{
|
|
_sut.Compare("rejected", "notIn", "pending,review").Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Compare_NotIn_NullField_ReturnsFalse()
|
|
{
|
|
var array = JsonDocument.Parse("""["value"]""").RootElement;
|
|
_sut.Compare(null, "notIn", array).Should().BeFalse();
|
|
}
|
|
}
|