Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ internal ParenthesisConstraint(IConstraint constraint)
_constraint = (ConstraintBase)constraint;
}

public override bool IsSatisfiedBy(object? value)
{
ArgumentNullException.ThrowIfNull(_constraint);

return _constraint.IsSatisfiedBy(value);
}
public override bool IsSatisfiedBy(object? value) => _constraint.IsSatisfiedBy(value);

public override void SetDescription(StringBuilder builder)
{
Expand Down
23 changes: 23 additions & 0 deletions tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using NetEvolve.FluentValue;
using NetEvolve.FluentValue.Operators;
using static System.StringComparison;

public class ConstraintTests
Expand All @@ -27,6 +28,25 @@ public static IEnumerable<Func<Action>> ChainedInvalidOperationsData() =>
() => () => _ = Value.Null.Xor.Xor,
];

[Test]
[MethodDataSource(nameof(NullArgumentData))]
public void Value_NullArgument_ShouldThrowArgumentNullException(Action constraintAction) =>
_ = Assert.Throws<ArgumentNullException>(constraintAction);

public static IEnumerable<Func<Action>> NullArgumentData() =>
[
() => () => _ = Value.Parenthesis(null!),
() => () => _ = Value.Null.And.Parenthesis(null!),
() => () => _ = Value.Not.Parenthesis(null!),
() => () => _ = Value.Null.And.SetConstraint(null!),
() => () => _ = Value.Null.Or.SetConstraint(null!),
() => () => _ = Value.Null.Xor.SetConstraint(null!),
() => () => _ = Value.Not.SetConstraint(null!),
() => () => _ = new AndOperator(null!),
() => () => _ = new OrOperator(null!),
() => () => _ = new XorOperator(null!),
];

[Test]
public void Value_WhenNewObject_ShouldThrowNotSupportedException() =>
_ = Assert.Throws<NotSupportedException>(() => Value.Contains(new object()).IsSatisfiedBy(new object()));
Expand Down Expand Up @@ -259,9 +279,12 @@ public async Task ToString_Theory_Expected(string expected, IConstraint constrai
// .And Operators
() =>
("\"{Value} contains `Hello` and contains `World!`.\"", Value.Contains("Hello").And.Contains("World!")),
() => ("\"{Value} is <null>.\"", Value.Null.And),
// .Or Operators
() => ("\"{Value} is <null>.\"", Value.Null.Or),
() => ("\"{Value} is <null> or is <empty>.\"", Value.Null.Or.Empty),
// .Xor Operators
() => ("\"{Value} is <null>.\"", Value.Null.Xor),
() => ("\"{Value} is <null> xor is <empty>.\"", Value.Null.Xor.Empty),
// .Not.Null
() => ("\"{Value} not is <null>.\"", Value.Not.Null),
Expand Down
Loading