diff --git a/tests/AGENTS.md b/tests/AGENTS.md
index c68ee7b9..8ca3d97e 100644
--- a/tests/AGENTS.md
+++ b/tests/AGENTS.md
@@ -10,4 +10,5 @@
# How to run tests
- `dotnet test` for usual test runs.
-- `dotnet test -- --coverage --coverage-output-format cobertura` for test coverage metrics.
+- `dotnet test -- --coverage --coverage-output-format cobertura --coverage-settings CodeCoverage.config` for test coverage metrics (run from tests/Light.GuardClauses.Tests). The settings file excludes JetBrains.Annotations and Regex source generator output from the report.
+- Line coverage of 100% is not achievable: the closing brace after a call to a `Throw.*` helper is an unreachable sequence point because these helpers never return (285 such lines as of 2026-07-15).
diff --git a/tests/Light.GuardClauses.Tests/CodeCoverage.config b/tests/Light.GuardClauses.Tests/CodeCoverage.config
new file mode 100644
index 00000000..9d05672c
--- /dev/null
+++ b/tests/Light.GuardClauses.Tests/CodeCoverage.config
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ ^JetBrains\.Annotations\..*
+ ^System\.Text\.RegularExpressions\.Generated\..*
+
+
+
+
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/AdditionalSpanAndMemoryGuardsTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/AdditionalSpanAndMemoryGuardsTests.cs
index df77b042..d34c83d5 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/AdditionalSpanAndMemoryGuardsTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/AdditionalSpanAndMemoryGuardsTests.cs
@@ -1,5 +1,6 @@
using System;
using FluentAssertions;
+using Light.GuardClauses.ExceptionFactory;
using Light.GuardClauses.Exceptions;
using Xunit;
@@ -41,9 +42,9 @@ public static void EmptyGuardsCaptureCallerExpressions()
spanAct.Should().Throw().WithParameterName("emptySpan");
readOnlySpanAct.Should().Throw().WithParameterName("emptyReadOnlySpan");
((Action) (() => emptyMemory.MustNotBeEmpty())).Should().Throw()
- .WithParameterName(nameof(emptyMemory));
+ .WithParameterName(nameof(emptyMemory));
((Action) (() => emptyReadOnlyMemory.MustNotBeEmpty())).Should().Throw()
- .WithParameterName(nameof(emptyReadOnlyMemory));
+ .WithParameterName(nameof(emptyReadOnlyMemory));
}
[Fact]
@@ -55,6 +56,22 @@ public static void EmptyGuardFactoriesReceiveEveryShape()
Test.CustomMemoryException(ReadOnlyMemory.Empty, (value, factory) => value.MustNotBeEmpty(factory));
}
+ [Fact]
+ public static void NonEmptyFactoriesDoNotThrowForEveryValidShape()
+ {
+ var array = new[] { 1, 2 };
+ var span = array.AsSpan();
+ ReadOnlySpan readOnlySpan = array;
+ var memory = array.AsMemory();
+ ReadOnlyMemory readOnlyMemory = array;
+ ReadOnlySpanExceptionFactory factory = _ => new ("The factory should not be invoked.");
+
+ (span.MustNotBeEmpty(factory) == span).Should().BeTrue();
+ (readOnlySpan.MustNotBeEmpty(factory) == readOnlySpan).Should().BeTrue();
+ memory.MustNotBeEmpty(factory).Should().Be(memory);
+ readOnlyMemory.MustNotBeEmpty(factory).Should().Be(readOnlyMemory);
+ }
+
[Fact]
public static void RangedLengthGuardsPreserveBoundariesAndShapes()
{
@@ -81,14 +98,44 @@ public static void RangedLengthGuardsPreserveBoundariesAndShapes()
public static void RangedLengthFactoriesReceiveEveryShape()
{
var invalidRange = Range.InclusiveBetween(2, 3);
- Test.CustomSpanException(Span.Empty, invalidRange,
- (value, range, factory) => value.MustHaveLengthIn(range, factory));
- Test.CustomSpanException(ReadOnlySpan.Empty, invalidRange,
- (value, range, factory) => value.MustHaveLengthIn(range, factory));
- Test.CustomMemoryException(Memory.Empty, invalidRange,
- (value, range, factory) => value.MustHaveLengthIn(range, factory));
- Test.CustomMemoryException(ReadOnlyMemory.Empty, invalidRange,
- (value, range, factory) => value.MustHaveLengthIn(range, factory));
+ Test.CustomSpanException(
+ Span.Empty,
+ invalidRange,
+ (value, range, factory) => value.MustHaveLengthIn(range, factory)
+ );
+ Test.CustomSpanException(
+ ReadOnlySpan.Empty,
+ invalidRange,
+ (value, range, factory) => value.MustHaveLengthIn(range, factory)
+ );
+ Test.CustomMemoryException(
+ Memory.Empty,
+ invalidRange,
+ (value, range, factory) => value.MustHaveLengthIn(range, factory)
+ );
+ Test.CustomMemoryException(
+ ReadOnlyMemory.Empty,
+ invalidRange,
+ (value, range, factory) => value.MustHaveLengthIn(range, factory)
+ );
+ }
+
+ [Fact]
+ public static void RangedLengthFactoriesDoNotThrowForEveryValidShape()
+ {
+ var array = new[] { 1, 2, 3 };
+ var validRange = Range.InclusiveBetween(3, 3);
+ var span = array.AsSpan();
+ ReadOnlySpan readOnlySpan = array;
+ var memory = array.AsMemory();
+ ReadOnlyMemory readOnlyMemory = array;
+ ReadOnlySpanExceptionFactory> factory =
+ (_, _) => new ("The factory should not be invoked.");
+
+ (span.MustHaveLengthIn(validRange, factory) == span).Should().BeTrue();
+ (readOnlySpan.MustHaveLengthIn(validRange, factory) == readOnlySpan).Should().BeTrue();
+ memory.MustHaveLengthIn(validRange, factory).Should().Be(memory);
+ readOnlyMemory.MustHaveLengthIn(validRange, factory).Should().Be(readOnlyMemory);
}
[Fact]
@@ -112,8 +159,22 @@ public static void MemoryExactLengthFailuresSupportMessagesExpressionsAndFactori
.WithParameterName(nameof(memory))
.WithMessage("*custom*");
Test.CustomMemoryException(memory, 1, (value, length, factory) => value.MustHaveLength(length, factory));
- Test.CustomMemoryException(readOnlyMemory, 1,
- (value, length, factory) => value.MustHaveLength(length, factory));
+ Test.CustomMemoryException(
+ readOnlyMemory,
+ 1,
+ (value, length, factory) => value.MustHaveLength(length, factory)
+ );
+ }
+
+ [Fact]
+ public static void MemoryExactLengthFactoriesDoNotThrowForValidLengths()
+ {
+ var memory = new[] { 1, 2 }.AsMemory();
+ ReadOnlyMemory readOnlyMemory = memory;
+ ReadOnlySpanExceptionFactory factory = (_, _) => new ("The factory should not be invoked.");
+
+ memory.MustHaveLength(2, factory).Should().Be(memory);
+ readOnlyMemory.MustHaveLength(2, factory).Should().Be(readOnlyMemory);
}
[Fact]
@@ -152,16 +213,40 @@ public static void EmptyAndWhitespaceFailuresUseExistingStringExceptions()
.WithMessage("*custom*");
}
+ [Fact]
+ public static void WhitespaceFactoriesDoNotThrowForEveryValidShape()
+ {
+ var characters = " a".ToCharArray();
+ var span = characters.AsSpan();
+ ReadOnlySpan readOnlySpan = characters;
+ var memory = characters.AsMemory();
+ ReadOnlyMemory readOnlyMemory = characters;
+ ReadOnlySpanExceptionFactory factory = _ => new ("The factory should not be invoked.");
+
+ (span.MustNotBeEmptyOrWhiteSpace(factory) == span).Should().BeTrue();
+ (readOnlySpan.MustNotBeEmptyOrWhiteSpace(factory) == readOnlySpan).Should().BeTrue();
+ memory.MustNotBeEmptyOrWhiteSpace(factory).Should().Be(memory);
+ readOnlyMemory.MustNotBeEmptyOrWhiteSpace(factory).Should().Be(readOnlyMemory);
+ }
+
[Fact]
public static void WhitespaceFactoriesReceiveEveryShape()
{
- Test.CustomSpanException(" ".ToCharArray().AsSpan(),
- (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory));
- Test.CustomSpanException((ReadOnlySpan) " ".ToCharArray(),
- (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory));
- Test.CustomMemoryException(" ".ToCharArray().AsMemory(),
- (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory));
- Test.CustomMemoryException((ReadOnlyMemory) " ".ToCharArray(),
- (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory));
+ Test.CustomSpanException(
+ " ".ToCharArray().AsSpan(),
+ (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory)
+ );
+ Test.CustomSpanException(
+ (ReadOnlySpan) " ".ToCharArray(),
+ (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory)
+ );
+ Test.CustomMemoryException(
+ " ".ToCharArray().AsMemory(),
+ (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory)
+ );
+ Test.CustomMemoryException(
+ (ReadOnlyMemory) " ".ToCharArray(),
+ (value, factory) => value.MustNotBeEmptyOrWhiteSpace(factory)
+ );
}
}
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainKeyTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainKeyTests.cs
index dc5fd195..bbd50d42 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainKeyTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainKeyTests.cs
@@ -19,7 +19,7 @@ public static void KeyNotPresent()
{
var dictionary = new Dictionary { ["Foo"] = 1, ["Bar"] = 2 };
- Action act = () => dictionary.MustContainKey("Baz", nameof(dictionary));
+ Action act = () => dictionary.MustContainKey("Baz");
var assertion = act.Should().Throw().Which;
assertion.Message.Should()
@@ -41,7 +41,7 @@ public static void InterfaceKeyNotPresent()
{
IReadOnlyDictionary dictionary = new Dictionary { ["Foo"] = 1 };
- Action act = () => dictionary.MustContainKey("Bar", nameof(dictionary));
+ Action act = () => dictionary.MustContainKey("Bar");
act.Should().Throw()
.And.Message.Should()
@@ -127,7 +127,15 @@ public static void CustomExceptionNotThrown()
{
var dictionary = new Dictionary { ["Foo"] = 1 };
- dictionary.MustContainKey("Foo", (_, _) => new Exception()).Should().BeSameAs(dictionary);
+ dictionary.MustContainKey("Foo", (_, _) => new ()).Should().BeSameAs(dictionary);
+ }
+
+ [Fact]
+ public static void InterfaceCustomExceptionNotThrown()
+ {
+ IReadOnlyDictionary dictionary = new Dictionary { ["Foo"] = 1 };
+
+ dictionary.MustContainKey("Foo", (_, _) => new ()).Should().BeSameAs(dictionary);
}
[Fact]
@@ -158,7 +166,7 @@ public static void DictionaryShapeIsPreservedInFluentChains()
{
var map = new Dictionary { ["endpoint"] = "https://example.com" };
- Dictionary result = map.MustNotBeNull().MustContainKey("endpoint");
+ var result = map.MustNotBeNull().MustContainKey("endpoint");
result.Should().BeSameAs(map);
}
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainTests.cs
index e450f768..9777d4d3 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustContainTests.cs
@@ -15,7 +15,7 @@ public static class MustContainTests
[InlineData(new[] { -5491, 6199 }, 42)]
public static void ItemNotPartOf(int[] collection, int item)
{
- Action act = () => collection.MustContain(item, nameof(collection));
+ Action act = () => collection.MustContain(item);
var assertion = act.Should().Throw().Which;
assertion.Message.Should().Contain($"{nameof(collection)} must contain {item}, but it actually does not.");
@@ -41,15 +41,44 @@ public static void CollectionNull()
[InlineData(new[] { long.MinValue, long.MaxValue }, 42L)]
[InlineData(null, 42L)]
public static void CustomException(long[] array, long item) =>
- Test.CustomException(array,
- item,
- (collection, i, exceptionFactory) => collection.MustContain(i, exceptionFactory));
+ Test.CustomException(
+ array,
+ item,
+ (collection, i, exceptionFactory) => collection.MustContain(i, exceptionFactory)
+ );
[Fact]
public static void CustomExceptionNotThrown()
{
var collection = new List { 1, 2, 3 };
- collection.MustContain(2, (_, _) => new Exception()).Should().BeSameAs(collection);
+ collection.MustContain(2, (_, _) => new ()).Should().BeSameAs(collection);
+ }
+
+ [Fact]
+ public static void LazyEnumerableItemPartOf()
+ {
+ var enumerable = new TrackingEnumerable([1, 2, 3], false);
+
+ enumerable.MustContain(2).Should().BeSameAs(enumerable);
+ }
+
+ [Fact]
+ public static void LazyEnumerableItemNotPartOf()
+ {
+ var enumerable = new TrackingEnumerable([1, 2, 3], false);
+
+ var act = () => enumerable.MustContain(42);
+
+ act.Should().Throw()
+ .WithParameterName(nameof(enumerable));
+ }
+
+ [Fact]
+ public static void CustomExceptionNotThrownLazyEnumerable()
+ {
+ var enumerable = new TrackingEnumerable([1, 2, 3], false);
+
+ enumerable.MustContain(3, (_, _) => new ()).Should().BeSameAs(enumerable);
}
[Fact]
@@ -57,13 +86,15 @@ public static void CustomMessage() =>
Test.CustomMessage(message => new List().MustContain("Foo", message: message));
[Fact]
- public static void CustomMessageCollectionNull() =>
- Test.CustomMessage(message => ((ObservableCollection) null).MustContain("Foo", message: message));
+ public static void CustomMessageCollectionNull() =>
+ Test.CustomMessage(
+ message => ((ObservableCollection) null).MustContain("Foo", message: message)
+ );
[Fact]
public static void CallerArgumentExpression()
{
- var array = new [] { "Foo", "Bar" };
+ var array = new[] { "Foo", "Bar" };
var act = () => array.MustContain("Baz");
@@ -77,7 +108,7 @@ public static void CallerArgumentExpression()
public static void ImmutableArrayItemNotPartOf(int[] source, int item)
{
var immutableArray = source.ToImmutableArray();
- Action act = () => immutableArray.MustContain(item, nameof(immutableArray));
+ Action act = () => immutableArray.MustContain(item);
var assertion = act.Should().Throw().Which;
assertion.Message.Should().Contain($"{nameof(immutableArray)} must contain {item}, but it actually does not.");
@@ -119,7 +150,7 @@ public static void ImmutableArrayCustomException(long[] source, long item)
public static void ImmutableArrayCustomExceptionNotThrown()
{
var immutableArray = ImmutableArray.Create(1, 2, 3);
- immutableArray.MustContain(2, (_, _) => new Exception()).Should().Equal(immutableArray);
+ immutableArray.MustContain(2, (_, _) => new ()).Should().Equal(immutableArray);
}
[Fact]
@@ -138,4 +169,4 @@ public static void ImmutableArrayCallerArgumentExpression()
act.Should().Throw()
.WithParameterName(nameof(immutableArray));
}
-}
\ No newline at end of file
+}
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs
index 4c1e15e6..c5c2c552 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveLengthInTests.cs
@@ -25,7 +25,7 @@ public static void LengthInRange(ImmutableArray array, Range range) =>
[MemberData(nameof(LengthNotInRangeData))]
public static void LengthNotInRange(ImmutableArray array, Range range)
{
- var act = () => array.MustHaveLengthIn(range, nameof(array));
+ var act = () => array.MustHaveLengthIn(range);
act.Should().Throw()
.And.Message.Should().Contain($"must have its length in between {range.CreateRangeDescriptionText("and")}")
@@ -49,6 +49,16 @@ public static void CustomException() =>
(array, r, exceptionFactory) => array.MustHaveLengthIn(r, exceptionFactory)
);
+ [Fact]
+ public static void CustomExceptionNotThrown()
+ {
+ var array = ImmutableArray.Create(1, 2, 3);
+
+ var result = array.MustHaveLengthIn(Range.InclusiveBetween(1, 3), (_, _) => new ());
+
+ result.Should().Equal(array);
+ }
+
[Fact]
public static void CustomMessage() =>
Test.CustomMessage(
@@ -84,7 +94,7 @@ public static void DefaultImmutableArrayNotInRange()
{
var defaultArray = default(ImmutableArray);
- var act = () => defaultArray.MustHaveLengthIn(Range.FromInclusive(1).ToInclusive(5), nameof(defaultArray));
+ var act = () => defaultArray.MustHaveLengthIn(Range.FromInclusive(1).ToInclusive(5));
act.Should().Throw()
.And.Message.Should().Contain("must have its length in between 1 (inclusive) and 5 (inclusive)")
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveSameCountAsTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveSameCountAsTests.cs
index 352ccdc9..058f085e 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveSameCountAsTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustHaveSameCountAsTests.cs
@@ -54,6 +54,7 @@ public static void NullReceiverUsesCapturedReceiverExpression()
{
int[] values = null;
+ // ReSharper disable once ExpressionIsAlwaysNull
Action act = () => values.MustHaveSameCountAs(Array.Empty());
act.Should().Throw().WithParameterName(nameof(values));
@@ -65,6 +66,7 @@ public static void NullComparisonCollectionUsesSecondaryArgumentNameWithoutObser
var values = new TrackingEnumerable([1]);
string[] other = null;
+ // ReSharper disable once ExpressionIsAlwaysNull
Action act = () => values.MustHaveSameCountAs(other);
act.Should().Throw().WithParameterName("otherCollection");
@@ -113,6 +115,19 @@ public static void CustomFactoryReceivesOriginalValuesForEveryFailure(bool recei
invocationCount.Should().Be(1);
}
+ [Fact]
+ public static void CustomFactoryIsNotInvokedWhenComparingACollectionWithItself()
+ {
+ var collection = new TrackingEnumerable([1, 2]);
+
+ collection.MustHaveSameCountAs(
+ collection,
+ (_, _) => throw new InvalidOperationException("The factory must not be invoked.")
+ )
+ .Should().BeSameAs(collection);
+ collection.EnumeratorCount.Should().Be(0);
+ }
+
[Fact]
public static void CustomFactoryIsNotInvokedForEqualCounts()
{
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainKeyTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainKeyTests.cs
index 3972f770..dba42e24 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainKeyTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainKeyTests.cs
@@ -19,7 +19,7 @@ public static void KeyPresent()
{
var dictionary = new Dictionary { ["Foo"] = 1, ["Bar"] = 2 };
- Action act = () => dictionary.MustNotContainKey("Foo", nameof(dictionary));
+ Action act = () => dictionary.MustNotContainKey("Foo");
act.Should().Throw()
.And.Message.Should()
@@ -39,7 +39,7 @@ public static void InterfaceKeyPresent()
{
IReadOnlyDictionary dictionary = new Dictionary { ["Foo"] = 1 };
- Action act = () => dictionary.MustNotContainKey("Foo", nameof(dictionary));
+ Action act = () => dictionary.MustNotContainKey("Foo");
act.Should().Throw()
.And.Message.Should()
@@ -125,7 +125,15 @@ public static void CustomExceptionNotThrown()
{
var dictionary = new Dictionary { ["Foo"] = 1 };
- dictionary.MustNotContainKey("Bar", (_, _) => new Exception()).Should().BeSameAs(dictionary);
+ dictionary.MustNotContainKey("Bar", (_, _) => new ()).Should().BeSameAs(dictionary);
+ }
+
+ [Fact]
+ public static void InterfaceCustomExceptionNotThrown()
+ {
+ IReadOnlyDictionary dictionary = new Dictionary { ["Foo"] = 1 };
+
+ dictionary.MustNotContainKey("Bar", (_, _) => new ()).Should().BeSameAs(dictionary);
}
[Fact]
@@ -156,7 +164,7 @@ public static void DictionaryShapeIsPreservedInFluentChains()
{
var map = new Dictionary { ["endpoint"] = "https://example.com" };
- Dictionary result = map.MustNotBeNull().MustNotContainKey("proxy");
+ var result = map.MustNotBeNull().MustNotContainKey("proxy");
result.Should().BeSameAs(map);
}
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullOrWhiteSpaceTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullOrWhiteSpaceTests.cs
index 5d0f9861..9ac66980 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullOrWhiteSpaceTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullOrWhiteSpaceTests.cs
@@ -159,6 +159,18 @@ public static void InvalidImmutableArrayThrowsAtItsPosition()
.WithMessage("*position 1*");
}
+ [Fact]
+ public static void InvalidReadOnlyIndexableReceiverThrowsAtItsPosition()
+ {
+ var values = new ReadOnlyIndexableOnlyList(["Alpha", " ", "Gamma"]);
+
+ Action act = () => values.MustNotContainNullOrWhiteSpace();
+
+ act.Should().Throw()
+ .WithParameterName(nameof(values))
+ .WithMessage("*position 1*");
+ }
+
[Fact]
public static void ImmutableArrayCustomFactoryReceivesOriginalShape() =>
Test.CustomException(
@@ -166,6 +178,18 @@ public static void ImmutableArrayCustomFactoryReceivesOriginalShape() =>
(values, factory) => values.MustNotContainNullOrWhiteSpace(factory)
);
+ [Fact]
+ public static void ValidImmutableArrayDoesNotInvokeCustomFactory()
+ {
+ var values = ImmutableArray.Create("Alpha", "Beta");
+
+ var result = values.MustNotContainNullOrWhiteSpace(
+ _ => new InvalidOperationException("The factory must not be invoked.")
+ );
+
+ result.Should().Equal(values);
+ }
+
[Fact]
public static void DefaultImmutableArrayDoesNotInvokeCustomFactory()
{
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullTests.cs
index 7d355b19..bd8e1891 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainNullTests.cs
@@ -179,6 +179,18 @@ public static void ImmutableArrayCustomFactoryReceivesOriginalShape() =>
(values, factory) => values.MustNotContainNull(factory)
);
+ [Fact]
+ public static void ValidImmutableArrayDoesNotInvokeCustomFactory()
+ {
+ var values = ImmutableArray.Create("Alpha", "Beta");
+
+ var result = values.MustNotContainNull(
+ _ => new InvalidOperationException("The factory must not be invoked.")
+ );
+
+ result.Should().Equal(values);
+ }
+
[Fact]
public static void DefaultImmutableArrayDoesNotInvokeCustomFactory()
{
diff --git a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainTests.cs b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainTests.cs
index 3f4b8172..fee70ac7 100644
--- a/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainTests.cs
+++ b/tests/Light.GuardClauses.Tests/CollectionAssertions/MustNotContainTests.cs
@@ -17,10 +17,12 @@ public static class MustNotContainTests
[InlineData(new[] { "Corge", "Grault", null }, null)]
public static void ItemExists(string[] collection, string item)
{
- Action act = () => collection.MustNotContain(item, nameof(collection));
+ Action act = () => collection.MustNotContain(item);
var assertions = act.Should().Throw().Which;
- assertions.Message.Should().Contain($"{nameof(collection)} must not contain {item.ToStringOrNull()}, but it actually does.");
+ assertions.Message.Should().Contain(
+ $"{nameof(collection)} must not contain {item.ToStringOrNull()}, but it actually does."
+ );
assertions.ParamName.Should().BeSameAs(nameof(collection));
}
@@ -34,37 +36,72 @@ public static void ItemExistsNot(int[] collection, int item) =>
[Fact]
public static void CollectionNull()
{
- Action act = () => ((ObservableCollection