diff --git a/Source/aweXpect/Results/HasItemWithConditionResult.cs b/Source/aweXpect/Results/HasItemWithConditionResult.cs
index ae3d0e43c..3dc3de7bf 100644
--- a/Source/aweXpect/Results/HasItemWithConditionResult.cs
+++ b/Source/aweXpect/Results/HasItemWithConditionResult.cs
@@ -13,19 +13,17 @@ namespace aweXpect.Results;
///
///
public class HasItemWithConditionResult
- : HasItemResult,
- IOptionsProvider>
+ : IOptionsProvider>
{
private readonly CollectionIndexOptions _collectionIndexOptions;
private readonly ExpectationBuilder _expectationBuilder;
private readonly PredicateOptions _options;
- private readonly IThat _subject;
+ private readonly IThat _subject;
internal HasItemWithConditionResult(ExpectationBuilder expectationBuilder,
- IThat subject,
+ IThat subject,
CollectionIndexOptions collectionIndexOptions,
PredicateOptions options)
- : base(expectationBuilder, subject, collectionIndexOptions)
{
_expectationBuilder = expectationBuilder;
_subject = subject;
@@ -39,62 +37,60 @@ internal HasItemWithConditionResult(ExpectationBuilder expectationBuilder,
///
/// …that satisfies the .
///
- public HasItemWithConditionResult Matching(Func predicate,
+ public HasItemResult Matching(Func predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
{
predicate.ThrowIfNull();
_options.SetPredicate(predicate,
$"matching {doNotPopulateThisValue}");
- return this;
+ return new HasItemResult(_expectationBuilder, _subject, _collectionIndexOptions);
}
///
/// …of type .
///
- public HasItemWithConditionResult Matching()
+ public HasItemResult Matching()
{
_options.SetPredicate(item => item is T,
$"of type {Formatter.Format(typeof(T))}");
- return Cast();
+ return new HasItemResult(_expectationBuilder, _subject, _collectionIndexOptions);
}
///
/// …of type that satisfies the .
///
- public HasItemWithConditionResult Matching(Func predicate,
+ public HasItemResult Matching(Func predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
{
predicate.ThrowIfNull();
_options.SetPredicate(item => item is T typed && predicate(typed),
$"of type {Formatter.Format(typeof(T))} matching {doNotPopulateThisValue}");
- return Cast();
+ return new HasItemResult(_expectationBuilder, _subject, _collectionIndexOptions);
}
///
/// …of type .
///
- public HasItemWithConditionResult MatchingExactly()
+ public HasItemResult MatchingExactly()
{
_options.SetPredicate(item => item is T && item.GetType() == typeof(T),
$"exactly of type {Formatter.Format(typeof(T))}");
- return Cast();
+
+ return new HasItemResult(_expectationBuilder, _subject, _collectionIndexOptions);
}
///
/// …of type that satisfies the .
///
- public HasItemWithConditionResult MatchingExactly(Func predicate,
+ public HasItemResult MatchingExactly(Func predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
{
predicate.ThrowIfNull();
_options.SetPredicate(item => item is T typed && item.GetType() == typeof(T) && predicate(typed),
$"exactly of type {Formatter.Format(typeof(T))} matching {doNotPopulateThisValue}");
- return Cast();
+ return new HasItemResult(_expectationBuilder, _subject, _collectionIndexOptions);
}
-
- private HasItemWithConditionResult Cast()
- => new(_expectationBuilder, _subject, _collectionIndexOptions, new PredicateOptions());
}
diff --git a/Source/aweXpect/That/Collections/ThatEnumerable.HasItem.cs b/Source/aweXpect/That/Collections/ThatEnumerable.HasItem.cs
index 8aac889a4..849b0e5d3 100644
--- a/Source/aweXpect/That/Collections/ThatEnumerable.HasItem.cs
+++ b/Source/aweXpect/That/Collections/ThatEnumerable.HasItem.cs
@@ -22,13 +22,13 @@ public static partial class ThatEnumerable
///
/// Verifies that the collection has an item…
///
- public static HasItemWithConditionResult, TItem> HasItem(
+ public static HasItemWithConditionResult?, TItem> HasItem(
this IThat?> source)
{
CollectionIndexOptions indexOptions = new();
PredicateOptions options = new();
ExpectationBuilder expectationBuilder = source.Get().ExpectationBuilder;
- return new HasItemWithConditionResult, TItem>(
+ return new HasItemWithConditionResult?, TItem>(
expectationBuilder.AddConstraint((it, grammars)
=> new HasItemConstraint(expectationBuilder, it, grammars,
x => options.Matches(x),
@@ -100,13 +100,13 @@ public static HasItemWithConditionResult, TItem> HasItem
/// Verifies that the collection has an item…
///
- public static HasItemWithConditionResult HasItem(
+ public static HasItemWithConditionResult HasItem(
this IThat source)
{
CollectionIndexOptions indexOptions = new();
PredicateOptions