From 1371474fdc3f4b7d5bb6a9540e809328513c4adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Thu, 29 Oct 2026 03:08:33 +0100 Subject: [PATCH 1/2] test: cover operator null guards and dangling operator descriptions Survivors in the Stryker report (77.21 %) include the ThrowIfNull guards of And/Or/Xor/Not operators and ParenthesisConstraint, and the early return in SetDescription of an operator without right-hand constraint. Add tests for both. Remove the redundant ThrowIfNull(_constraint) in ParenthesisConstraint.IsSatisfiedBy (already guaranteed by the ctor guard, an equivalent mutant). --- .../Constraints/ParenthesisConstraint.cs | 2 -- .../ConstraintTests.cs | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs b/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs index ab10d7a..9387e76 100644 --- a/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs +++ b/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs @@ -16,8 +16,6 @@ internal ParenthesisConstraint(IConstraint constraint) public override bool IsSatisfiedBy(object? value) { - ArgumentNullException.ThrowIfNull(_constraint); - return _constraint.IsSatisfiedBy(value); } diff --git a/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs b/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs index 91b0ecf..5ce5545 100644 --- a/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs +++ b/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs @@ -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 @@ -27,6 +28,25 @@ public static IEnumerable> ChainedInvalidOperationsData() => () => () => _ = Value.Null.Xor.Xor, ]; + [Test] + [MethodDataSource(nameof(NullArgumentData))] + public void Value_NullArgument_ShouldThrowArgumentNullException(Action constraintAction) => + _ = Assert.Throws(constraintAction); + + public static IEnumerable> 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!), + () => () => _ = ((IOperator)Value.Not).SetConstraint(null!), + () => () => _ = new AndOperator(null!), + () => () => _ = new OrOperator(null!), + () => () => _ = new XorOperator(null!), + ]; + [Test] public void Value_WhenNewObject_ShouldThrowNotSupportedException() => _ = Assert.Throws(() => Value.Contains(new object()).IsSatisfiedBy(new object())); @@ -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 .\"", Value.Null.And), // .Or Operators + () => ("\"{Value} is .\"", Value.Null.Or), () => ("\"{Value} is or is .\"", Value.Null.Or.Empty), // .Xor Operators + () => ("\"{Value} is .\"", Value.Null.Xor), () => ("\"{Value} is xor is .\"", Value.Null.Xor.Empty), // .Not.Null () => ("\"{Value} not is .\"", Value.Not.Null), From bb73d5d2a744e80f1223b6fb99e962f5df74c4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Thu, 29 Oct 2026 03:09:18 +0100 Subject: [PATCH 2/2] style: fix analyzer warnings in operator guard tests --- .../Constraints/ParenthesisConstraint.cs | 5 +---- tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs b/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs index 9387e76..4c91fea 100644 --- a/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs +++ b/src/NetEvolve.FluentValue/Constraints/ParenthesisConstraint.cs @@ -14,10 +14,7 @@ internal ParenthesisConstraint(IConstraint constraint) _constraint = (ConstraintBase)constraint; } - public override bool IsSatisfiedBy(object? value) - { - return _constraint.IsSatisfiedBy(value); - } + public override bool IsSatisfiedBy(object? value) => _constraint.IsSatisfiedBy(value); public override void SetDescription(StringBuilder builder) { diff --git a/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs b/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs index 5ce5545..f564744 100644 --- a/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs +++ b/tests/NetEvolve.FluentValue.Tests.Unit/ConstraintTests.cs @@ -41,7 +41,7 @@ public static IEnumerable> NullArgumentData() => () => () => _ = Value.Null.And.SetConstraint(null!), () => () => _ = Value.Null.Or.SetConstraint(null!), () => () => _ = Value.Null.Xor.SetConstraint(null!), - () => () => _ = ((IOperator)Value.Not).SetConstraint(null!), + () => () => _ = Value.Not.SetConstraint(null!), () => () => _ = new AndOperator(null!), () => () => _ = new OrOperator(null!), () => () => _ = new XorOperator(null!),