diff --git a/Source/aweXpect.Reflection/Filters/AssemblyFilters.Except.cs b/Source/aweXpect.Reflection/Filters/AssemblyFilters.Except.cs index 5123c0d3..a56ca13d 100644 --- a/Source/aweXpect.Reflection/Filters/AssemblyFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/AssemblyFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Assemblies Except(this Filtered.Assemblies @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - assembly => !predicate(assembly), + assembly => !UserCode.Invoke(predicate, assembly, "the predicate"), $" except {doNotPopulateThisValue.TrimCommonWhiteSpace()}")); } diff --git a/Source/aweXpect.Reflection/Filters/AssemblyFilters.Which.cs b/Source/aweXpect.Reflection/Filters/AssemblyFilters.Which.cs index e5a8aa01..eeb17805 100644 --- a/Source/aweXpect.Reflection/Filters/AssemblyFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/AssemblyFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Assemblies Which(this Filtered.Assemblies @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $" matching {doNotPopulateThisValue.TrimCommonWhiteSpace()}")); + => @this.Which(Filter.Suffix(assembly => UserCode.Invoke(predicate, assembly, "the predicate"), + $" matching {doNotPopulateThisValue.TrimCommonWhiteSpace()}")); } diff --git a/Source/aweXpect.Reflection/Filters/AssemblyFilters.WithVersion.cs b/Source/aweXpect.Reflection/Filters/AssemblyFilters.WithVersion.cs index a5dd7723..f90dfff1 100644 --- a/Source/aweXpect.Reflection/Filters/AssemblyFilters.WithVersion.cs +++ b/Source/aweXpect.Reflection/Filters/AssemblyFilters.WithVersion.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -18,7 +19,7 @@ public static Filtered.Assemblies WithVersion(this Filtered.Assemblies @this, string doNotPopulateThisValue = "") { IChangeableFilter filter = Filter.Suffix( - assembly => assembly.GetName().Version is { } version && predicate(version), + assembly => assembly.GetName().Version is { } version && UserCode.Invoke(predicate, version, "the predicate"), $" with version matching {doNotPopulateThisValue.TrimCommonWhiteSpace()}"); return @this.Which(filter); } diff --git a/Source/aweXpect.Reflection/Filters/ConstructorFilters.Except.cs b/Source/aweXpect.Reflection/Filters/ConstructorFilters.Except.cs index ba7f4dc1..5ad00be2 100644 --- a/Source/aweXpect.Reflection/Filters/ConstructorFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/ConstructorFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Constructors Except(this Filtered.Constructors @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - constructor => !predicate(constructor), + constructor => !UserCode.Invoke(predicate, constructor, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/ConstructorFilters.Which.cs b/Source/aweXpect.Reflection/Filters/ConstructorFilters.Which.cs index 66a882f5..2599303d 100644 --- a/Source/aweXpect.Reflection/Filters/ConstructorFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/ConstructorFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Constructors Which(this Filtered.Constructors @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(constructor => UserCode.Invoke(predicate, constructor, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/EventFilters.Except.cs b/Source/aweXpect.Reflection/Filters/EventFilters.Except.cs index f602620d..a541646a 100644 --- a/Source/aweXpect.Reflection/Filters/EventFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/EventFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Events Except(this Filtered.Events @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - eventInfo => !predicate(eventInfo), + eventInfo => !UserCode.Invoke(predicate, eventInfo, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/EventFilters.Which.cs b/Source/aweXpect.Reflection/Filters/EventFilters.Which.cs index cf62f293..a52164ad 100644 --- a/Source/aweXpect.Reflection/Filters/EventFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/EventFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Events Which(this Filtered.Events @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(eventInfo => UserCode.Invoke(predicate, eventInfo, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/FieldFilters.Except.cs b/Source/aweXpect.Reflection/Filters/FieldFilters.Except.cs index 34d0263c..b8c7624c 100644 --- a/Source/aweXpect.Reflection/Filters/FieldFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/FieldFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Fields Except(this Filtered.Fields @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - field => !predicate(field), + field => !UserCode.Invoke(predicate, field, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/FieldFilters.Which.cs b/Source/aweXpect.Reflection/Filters/FieldFilters.Which.cs index 8e83b4c7..7b87b8c5 100644 --- a/Source/aweXpect.Reflection/Filters/FieldFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/FieldFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Fields Which(this Filtered.Fields @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(field => UserCode.Invoke(predicate, field, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/MethodFilters.Except.cs b/Source/aweXpect.Reflection/Filters/MethodFilters.Except.cs index 25a69403..89ae3566 100644 --- a/Source/aweXpect.Reflection/Filters/MethodFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/MethodFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Methods Except(this Filtered.Methods @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - method => !predicate(method), + method => !UserCode.Invoke(predicate, method, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/MethodFilters.Which.cs b/Source/aweXpect.Reflection/Filters/MethodFilters.Which.cs index b06e743c..d4d1a3a4 100644 --- a/Source/aweXpect.Reflection/Filters/MethodFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/MethodFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Methods Which(this Filtered.Methods @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(method => UserCode.Invoke(predicate, method, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/PropertyFilters.Except.cs b/Source/aweXpect.Reflection/Filters/PropertyFilters.Except.cs index 542ad96e..3ec861e6 100644 --- a/Source/aweXpect.Reflection/Filters/PropertyFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/PropertyFilters.Except.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -19,6 +20,6 @@ public static Filtered.Properties Except(this Filtered.Properties @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - property => !predicate(property), + property => !UserCode.Invoke(predicate, property, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/PropertyFilters.Which.cs b/Source/aweXpect.Reflection/Filters/PropertyFilters.Which.cs index 2ef3119a..487d91b8 100644 --- a/Source/aweXpect.Reflection/Filters/PropertyFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/PropertyFilters.Which.cs @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -15,5 +16,6 @@ public static Filtered.Properties Which(this Filtered.Properties @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(property => UserCode.Invoke(predicate, property, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Filters/TypeFilters.Except.cs b/Source/aweXpect.Reflection/Filters/TypeFilters.Except.cs index 6fa56fad..ac8d0bd0 100644 --- a/Source/aweXpect.Reflection/Filters/TypeFilters.Except.cs +++ b/Source/aweXpect.Reflection/Filters/TypeFilters.Except.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -18,7 +19,7 @@ public static Filtered.Types Except(this Filtered.Types @this, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") => @this.Which(Filter.Suffix( - type => !predicate(type), + type => !UserCode.Invoke(predicate, type, "the predicate"), $"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); /// diff --git a/Source/aweXpect.Reflection/Filters/TypeFilters.Which.cs b/Source/aweXpect.Reflection/Filters/TypeFilters.Which.cs index 60db16b7..1c790a71 100644 --- a/Source/aweXpect.Reflection/Filters/TypeFilters.Which.cs +++ b/Source/aweXpect.Reflection/Filters/TypeFilters.Which.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using aweXpect.Core; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Helpers; @@ -14,5 +15,6 @@ public static Filtered.Types Which(this Filtered.Types @this, Func predicate, [CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") - => @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); + => @this.Which(Filter.Suffix(type => UserCode.Invoke(predicate, type, "the predicate"), + $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} ")); } diff --git a/Source/aweXpect.Reflection/Helpers/AssemblyHelpers.cs b/Source/aweXpect.Reflection/Helpers/AssemblyHelpers.cs index 80e1f0b7..c35918f4 100644 --- a/Source/aweXpect.Reflection/Helpers/AssemblyHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/AssemblyHelpers.cs @@ -40,7 +40,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/ConstructorInfoHelpers.cs b/Source/aweXpect.Reflection/Helpers/ConstructorInfoHelpers.cs index bb680aed..6731847b 100644 --- a/Source/aweXpect.Reflection/Helpers/ConstructorInfoHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/ConstructorInfoHelpers.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using aweXpect.Core; using aweXpect.Reflection.Collections; namespace aweXpect.Reflection.Helpers; @@ -88,7 +89,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/EventInfoHelpers.cs b/Source/aweXpect.Reflection/Helpers/EventInfoHelpers.cs index c99302e7..0e0ed4b8 100644 --- a/Source/aweXpect.Reflection/Helpers/EventInfoHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/EventInfoHelpers.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using aweXpect.Core; using aweXpect.Reflection.Collections; namespace aweXpect.Reflection.Helpers; @@ -49,7 +50,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/FieldInfoHelpers.cs b/Source/aweXpect.Reflection/Helpers/FieldInfoHelpers.cs index 6c9c2199..78070d64 100644 --- a/Source/aweXpect.Reflection/Helpers/FieldInfoHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/FieldInfoHelpers.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using aweXpect.Core; using aweXpect.Reflection.Collections; namespace aweXpect.Reflection.Helpers; @@ -92,7 +93,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/MethodInfoHelpers.cs b/Source/aweXpect.Reflection/Helpers/MethodInfoHelpers.cs index 05195553..1a6e6094 100644 --- a/Source/aweXpect.Reflection/Helpers/MethodInfoHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/MethodInfoHelpers.cs @@ -95,7 +95,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/PropertyInfoHelpers.cs b/Source/aweXpect.Reflection/Helpers/PropertyInfoHelpers.cs index 24ee51b9..01ab9a35 100644 --- a/Source/aweXpect.Reflection/Helpers/PropertyInfoHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/PropertyInfoHelpers.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Reflection; +using aweXpect.Core; using aweXpect.Reflection.Collections; namespace aweXpect.Reflection.Helpers; @@ -57,7 +58,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute castedAttribute) { - return predicate?.Invoke(castedAttribute) ?? true; + return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Helpers/TypeHelpers.cs b/Source/aweXpect.Reflection/Helpers/TypeHelpers.cs index bbd79dde..605b1d9c 100644 --- a/Source/aweXpect.Reflection/Helpers/TypeHelpers.cs +++ b/Source/aweXpect.Reflection/Helpers/TypeHelpers.cs @@ -469,7 +469,7 @@ public static bool HasAttribute( .FirstOrDefault(); if (attribute is TAttribute attributeValue) { - return predicate?.Invoke(attributeValue) ?? true; + return predicate is null || UserCode.Invoke(predicate, attributeValue, "the predicate"); } return false; diff --git a/Source/aweXpect.Reflection/Options/GenericArgumentFilterOptions.cs b/Source/aweXpect.Reflection/Options/GenericArgumentFilterOptions.cs index 8ccf2aee..2c539a84 100644 --- a/Source/aweXpect.Reflection/Options/GenericArgumentFilterOptions.cs +++ b/Source/aweXpect.Reflection/Options/GenericArgumentFilterOptions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using aweXpect.Core; namespace aweXpect.Reflection.Options; @@ -55,7 +56,8 @@ public ValueTask Matches(Type argument, string? genericArgumentName = null return new ValueTask(true); } - return _predicates.AllAsync(predicate => predicate(argument, genericArgumentName)); + return _predicates.AllAsync(predicate + => UserCode.InvokeAsync(() => predicate(argument, genericArgumentName), "the predicate")); } /// diff --git a/Source/aweXpect.Reflection/Options/GenericArgumentsFilterOptions.cs b/Source/aweXpect.Reflection/Options/GenericArgumentsFilterOptions.cs index 07d2672e..1b9da516 100644 --- a/Source/aweXpect.Reflection/Options/GenericArgumentsFilterOptions.cs +++ b/Source/aweXpect.Reflection/Options/GenericArgumentsFilterOptions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using aweXpect.Core; using aweXpect.Options; namespace aweXpect.Reflection.Options; @@ -74,7 +75,7 @@ private async ValueTask } private bool MatchesPredicates(Type[] arguments) - => _predicates.All(predicate => predicate(arguments)); + => _predicates.All(predicate => UserCode.Invoke(predicate, arguments, "the predicate")); #if NET8_0_OR_GREATER private async ValueTask MatchesFilters(Type[] arguments, string[]? genericTypeNames) diff --git a/Source/aweXpect.Reflection/Options/ParameterFilterOptions.cs b/Source/aweXpect.Reflection/Options/ParameterFilterOptions.cs index d36e6807..81338e64 100644 --- a/Source/aweXpect.Reflection/Options/ParameterFilterOptions.cs +++ b/Source/aweXpect.Reflection/Options/ParameterFilterOptions.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using aweXpect.Core; namespace aweXpect.Reflection.Options; @@ -98,7 +99,7 @@ public ValueTask Matches(ParameterInfo parameter) return new ValueTask(true); } - return _predicates.AllAsync(predicate => predicate(parameter)); + return _predicates.AllAsync(predicate => UserCode.InvokeAsync(() => predicate(parameter), "the predicate")); } private static Func> ToAsyncPredicate(Func predicate) diff --git a/Source/aweXpect.Reflection/ThatAssemblies.DependOn.cs b/Source/aweXpect.Reflection/ThatAssemblies.DependOn.cs index 1e189b6a..695c7a5a 100644 --- a/Source/aweXpect.Reflection/ThatAssemblies.DependOn.cs +++ b/Source/aweXpect.Reflection/ThatAssemblies.DependOn.cs @@ -89,7 +89,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string? protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) => stringBuilder.Append("not all have dependency on assembly ") - .Append(options.GetExpectation(expected, Grammars.Negate())); + .Append(options.GetExpectation(expected, Grammars)); protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) => stringBuilder.Append(It).Append(" only contained assemblies with the unexpected dependency"); diff --git a/Source/aweXpect.Reflection/ThatAssembly.HasName.cs b/Source/aweXpect.Reflection/ThatAssembly.HasName.cs index 1c52a8f5..4fc9b9fc 100644 --- a/Source/aweXpect.Reflection/ThatAssembly.HasName.cs +++ b/Source/aweXpect.Reflection/ThatAssembly.HasName.cs @@ -47,7 +47,7 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str => stringBuilder.Append("has name ").Append(options.GetExpectation(expected, Grammars)); protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - => stringBuilder.Append(options.GetExtendedFailure(It, Grammars, Actual?.GetName().Name, expected)); + => stringBuilder.Append(options.GetExtendedMemberFailure(It, "name", Grammars, Actual?.GetName().Name, expected)); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) => AppendNormalExpectation(stringBuilder, indentation); diff --git a/Source/aweXpect.Reflection/ThatAssembly.Targets.cs b/Source/aweXpect.Reflection/ThatAssembly.Targets.cs index 3cfef698..dc1d9631 100644 --- a/Source/aweXpect.Reflection/ThatAssembly.Targets.cs +++ b/Source/aweXpect.Reflection/ThatAssembly.Targets.cs @@ -51,7 +51,7 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str => stringBuilder.Append("targets ").Append(options.GetExpectation(expected, Grammars)); protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - => stringBuilder.Append(options.GetExtendedFailure(It, Grammars, Actual?.GetTargetFramework(), expected)); + => stringBuilder.Append(options.GetExtendedMemberFailure(It, "target framework", Grammars, Actual?.GetTargetFramework(), expected)); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) => AppendNormalExpectation(stringBuilder, indentation); diff --git a/Source/aweXpect.Reflection/ThatMember.HasName.cs b/Source/aweXpect.Reflection/ThatMember.HasName.cs index 6198b500..431d1490 100644 --- a/Source/aweXpect.Reflection/ThatMember.HasName.cs +++ b/Source/aweXpect.Reflection/ThatMember.HasName.cs @@ -50,7 +50,7 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str => stringBuilder.Append("has name ").Append(options.GetExpectation(expected, Grammars)); protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - => stringBuilder.Append(options.GetExtendedFailure(It, Grammars, Actual?.Name, expected)); + => stringBuilder.Append(options.GetExtendedMemberFailure(It, "name", Grammars, Actual?.Name, expected)); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) => AppendNormalExpectation(stringBuilder, indentation); diff --git a/Source/aweXpect.Reflection/ThatType.HasNamespace.cs b/Source/aweXpect.Reflection/ThatType.HasNamespace.cs index 0b6e118a..9f51a086 100644 --- a/Source/aweXpect.Reflection/ThatType.HasNamespace.cs +++ b/Source/aweXpect.Reflection/ThatType.HasNamespace.cs @@ -47,10 +47,10 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str => stringBuilder.Append("has namespace ").Append(options.GetExpectation(expected, Grammars)); protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - => stringBuilder.Append(options.GetExtendedFailure(It, Grammars, Actual?.Namespace, expected)); + => stringBuilder.Append(options.GetExtendedMemberFailure(It, "namespace", Grammars, Actual?.Namespace, expected)); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) - => stringBuilder.Append("does not have namespace ").Append(options.GetExpectation(expected, Grammars)); + => AppendNormalExpectation(stringBuilder, indentation); protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) => AppendNormalResult(stringBuilder, indentation); diff --git a/Source/aweXpect.Reflection/ThatType.Implements.cs b/Source/aweXpect.Reflection/ThatType.Implements.cs index 2a69736b..f424e67a 100644 --- a/Source/aweXpect.Reflection/ThatType.Implements.cs +++ b/Source/aweXpect.Reflection/ThatType.Implements.cs @@ -124,9 +124,9 @@ public ConstraintResult IsMetBy(Type? actual) public override void AppendContexts(ResultContextCollector contexts) { - if (Actual is not null) + if (Actual is { } actual) { - contexts.Add(new ResultContext.Fixed("Actual", Actual.ToString())); + contexts.Add(new ResultContext.SyncCallback("Actual", () => Formatter.Format(actual))); } } @@ -137,18 +137,9 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str } protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - { - if (forceDirect && Actual?.Implements(interfaceType) == true) - { - stringBuilder.Append(It).Append(" implemented "); - Formatter.Format(stringBuilder, interfaceType); - stringBuilder.Append(" only indirectly"); - return; - } - - stringBuilder.Append(It).Append(" did not implement "); - Formatter.Format(stringBuilder, interfaceType); - } + => stringBuilder.Append(It).Append(forceDirect && Actual?.Implements(interfaceType) == true + ? " did only indirectly" + : " did not"); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) { @@ -157,9 +148,6 @@ protected override void AppendNegatedExpectation(StringBuilder stringBuilder, st } protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(forceDirect ? " did directly implement " : " did implement "); - Formatter.Format(stringBuilder, interfaceType); - } + => stringBuilder.Append(It).Append(" did"); } } diff --git a/Source/aweXpect.Reflection/ThatType.InheritsFrom.cs b/Source/aweXpect.Reflection/ThatType.InheritsFrom.cs index 2775472c..3f3a98af 100644 --- a/Source/aweXpect.Reflection/ThatType.InheritsFrom.cs +++ b/Source/aweXpect.Reflection/ThatType.InheritsFrom.cs @@ -122,9 +122,9 @@ public ConstraintResult IsMetBy(Type? actual) public override void AppendContexts(ResultContextCollector contexts) { - if (Actual is not null) + if (Actual is { } actual) { - contexts.Add(new ResultContext.Fixed("Actual", Actual.ToString())); + contexts.Add(new ResultContext.SyncCallback("Actual", () => Formatter.Format(actual))); } } @@ -136,18 +136,9 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str } protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - { - if (forceDirect && Actual?.InheritsFromClass(baseType) == true) - { - stringBuilder.Append(It).Append(" inherited from "); - Formatter.Format(stringBuilder, baseType); - stringBuilder.Append(" only indirectly"); - return; - } - - stringBuilder.Append(It).Append(" did not inherit from "); - Formatter.Format(stringBuilder, baseType); - } + => stringBuilder.Append(It).Append(forceDirect && Actual?.InheritsFromClass(baseType) == true + ? " did only indirectly" + : " did not"); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) { @@ -157,11 +148,7 @@ protected override void AppendNegatedExpectation(StringBuilder stringBuilder, st } protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(" did inherit "); - AppendDirectlyFrom(stringBuilder, forceDirect); - Formatter.Format(stringBuilder, baseType); - } + => stringBuilder.Append(It).Append(" did"); private static void AppendDirectlyFrom(StringBuilder stringBuilder, bool forceDirect) { diff --git a/Source/aweXpect.Reflection/ThatType.IsAssignableTo.cs b/Source/aweXpect.Reflection/ThatType.IsAssignableTo.cs index ad1b4ca3..6402e569 100644 --- a/Source/aweXpect.Reflection/ThatType.IsAssignableTo.cs +++ b/Source/aweXpect.Reflection/ThatType.IsAssignableTo.cs @@ -181,9 +181,9 @@ public ConstraintResult IsMetBy(Type? actual) public override void AppendContexts(ResultContextCollector contexts) { - if (Actual is not null) + if (Actual is { } actual) { - contexts.Add(new ResultContext.Fixed("Actual", Actual.ToString())); + contexts.Add(new ResultContext.SyncCallback("Actual", () => Formatter.Format(actual))); } } @@ -194,10 +194,7 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str } protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(" was not assignable to "); - Formatter.Format(stringBuilder, type); - } + => stringBuilder.Append(It).Append(" was not"); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) { @@ -206,10 +203,7 @@ protected override void AppendNegatedExpectation(StringBuilder stringBuilder, st } protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(" was assignable to "); - Formatter.Format(stringBuilder, type); - } + => stringBuilder.Append(It).Append(" was"); } private sealed class IsAssignableFromConstraint( @@ -228,9 +222,9 @@ public ConstraintResult IsMetBy(Type? actual) public override void AppendContexts(ResultContextCollector contexts) { - if (Actual is not null) + if (Actual is { } actual) { - contexts.Add(new ResultContext.Fixed("Actual", Actual.ToString())); + contexts.Add(new ResultContext.SyncCallback("Actual", () => Formatter.Format(actual))); } } @@ -241,10 +235,7 @@ protected override void AppendNormalExpectation(StringBuilder stringBuilder, str } protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(" was not assignable from "); - Formatter.Format(stringBuilder, type); - } + => stringBuilder.Append(It).Append(" was not"); protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null) { @@ -253,9 +244,6 @@ protected override void AppendNegatedExpectation(StringBuilder stringBuilder, st } protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null) - { - stringBuilder.Append(It).Append(" was assignable from "); - Formatter.Format(stringBuilder, type); - } + => stringBuilder.Append(It).Append(" was"); } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Except.Tests.cs index b1edc8b6..63ccb84d 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(assemblies.GetDescription()) .IsEqualTo( "in all loaded assemblies except assembly => assembly.GetName().Name == \"aweXpect.Reflection.Tests\""); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Assemblies assemblies = In.AssemblyContaining() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(assemblies).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that in assembly containing type AssemblyFilters except _ => throw new InvalidOperationException("boom") + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Which.Tests.cs index 989832c7..a37b15f9 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -19,6 +20,27 @@ await That(typeAssemblies.GetDescription()) .IsEqualTo( "in all loaded assemblies matching it => it.FullName!.Contains(\"aweXpect.Reflection.Tests\")"); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Assemblies assemblies = In.AssemblyContaining() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(assemblies).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that in assembly containing type AssemblyFilters matching _ => throw new InvalidOperationException("boom") + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.With.AttributeTests.cs index 93c0541b..6387a38c 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -64,6 +65,27 @@ await That(assemblies.GetDescription()) .IsEqualTo( "in all loaded assemblies with direct AssemblyTitleAttribute matching attribute => attribute.Title == \"aweXpect.Reflection.Tests\""); } + + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Assemblies assemblies = In.AssemblyContaining() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(assemblies).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that in assembly containing type AssemblyFilters with AssemblyTitleAttribute matching _ => throw new InvalidOperationException("boom") + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } public sealed class OrWithAttributeTests diff --git a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.WithVersion.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.WithVersion.Tests.cs index ef6251a0..7e49c240 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.WithVersion.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/AssemblyFilters.WithVersion.Tests.cs @@ -1,6 +1,7 @@ using System.Reflection; using aweXpect.Reflection.Collections; using aweXpect.Reflection.Tests.TestHelpers.Types; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -29,6 +30,48 @@ public async Task ShouldNotMatchWhenPredicateIsNeverTrue() await That(assemblies).IsEmpty(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Assemblies assemblies = In.AssemblyContaining() + .WithVersion(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(assemblies).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that in assembly containing type AssemblyFilters with version matching _ => throw new InvalidOperationException("boom") + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + + [Fact] + public async Task WhenPredicateThrows_ShouldFailWhenNegated() + { + Filtered.Assemblies assemblies = In.AssemblyContaining() + .WithVersion(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(assemblies).DoesNotComplyWith(they => they.IsEmpty()); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that in assembly containing type AssemblyFilters with version matching _ => throw new InvalidOperationException("boom") + is not empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("a predicate that throws answers neither the expectation nor its negation"); + } } public sealed class ComponentTests diff --git a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Except.Tests.cs index 438eb48a..12785c90 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(constructors.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Constructors constructors = In.AssemblyContaining().Constructors() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(constructors).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that constructors except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + private class ClassWithConstructors { public ClassWithConstructors() diff --git a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Which.Tests.cs index 9111ce19..ef828ba9 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -21,6 +22,27 @@ await That(constructors.GetDescription()) "constructors matching it => it.DeclaringType == typeof(SomeClassToVerifyTheConstructorNameOfIt) in assembly") .AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Constructors constructors = In.AssemblyContaining().Constructors() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(constructors).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that constructors matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.With.AttributeTests.cs index 45da5853..346aa8ea 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/ConstructorFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -38,6 +39,27 @@ await That(constructors.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Constructors constructors = In.AssemblyContaining().Constructors() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(constructors).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that constructors with ConstructorFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Except.Tests.cs index 0c0c03db..85efdf08 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -18,6 +19,27 @@ public async Task ShouldFilterOutEventsThatSatisfyThePredicate() await That(events.GetDescription()) .IsEqualTo("events except e => e.Name == \"ConcreteEvent\" in").AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Events events = In.AssemblyContaining().Events() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(events).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that events except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Which.Tests.cs index 41230ab1..084045ad 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(events.GetDescription()) "events matching it => it.Name.Equals(\"SomeEventToVerifyTheNameOfIt\") in assembly") .AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Events events = In.AssemblyContaining().Events() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(events).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that events matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.With.AttributeTests.cs index eb2da933..0a194d37 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/EventFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -64,6 +65,27 @@ await That(events.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Events events = In.AssemblyContaining().Events() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(events).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that events with EventFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Except.Tests.cs index 7f67a00a..0b80b953 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -19,6 +20,27 @@ await That(fields.GetDescription()) .IsEqualTo("fields except field => field.Name == \"ExcludedField\" in").AsPrefix(); } + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Fields fields = In.AssemblyContaining().Fields() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(fields).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that fields except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value private class ClassWithFields { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Which.Tests.cs index 7d80fdc5..519c7045 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(fields.GetDescription()) "fields matching it => it.Name.Equals(\"SomeFieldToVerifyTheNameOfIt\") in assembly") .AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Fields fields = In.AssemblyContaining().Fields() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(fields).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that fields matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.With.AttributeTests.cs index f82b2db5..e957d4a4 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/FieldFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -38,6 +39,27 @@ await That(fields.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Fields fields = In.AssemblyContaining().Fields() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(fields).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that fields with FieldFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Except.Tests.cs index d1a6b721..8693307e 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -18,6 +19,27 @@ public async Task ShouldFilterOutMethodsThatSatisfyThePredicate() await That(methods.GetDescription()) .IsEqualTo("methods except method => method.Name == \"ConcreteMethod\" in").AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Methods methods = In.AssemblyContaining().Methods() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(methods).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that methods except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Which.Tests.cs index 778d507d..ab930116 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(methods.GetDescription()) "methods matching it => it.Name.Equals(\"SomeMethodToVerifyTheNameOfIt\") in assembly") .AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Methods methods = In.AssemblyContaining().Methods() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(methods).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that methods matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.With.AttributeTests.cs index ec560121..0c1613d7 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/MethodFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -65,6 +66,27 @@ await That(methods.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Methods methods = In.AssemblyContaining().Methods() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(methods).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that methods with MethodFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Except.Tests.cs index 30135184..656378b1 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -18,6 +19,27 @@ public async Task ShouldFilterOutPropertiesThatSatisfyThePredicate() await That(properties.GetDescription()) .IsEqualTo("properties except property => property.Name == \"ConcreteProperty\" in").AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Properties properties = In.AssemblyContaining().Properties() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(properties).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that properties except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Which.Tests.cs index 3fec662d..5d0f902b 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -20,6 +21,27 @@ await That(properties.GetDescription()) "properties matching it => it.Name.Equals(\"SomePropertyToVerifyTheNameOfIt\") in assembly") .AsPrefix(); } + + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Properties properties = In.AssemblyContaining().Properties() + .Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(properties).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that properties matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } } } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.With.AttributeTests.cs index 4dbe846d..534eea51 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/PropertyFilters.With.AttributeTests.cs @@ -1,5 +1,6 @@ using System.Reflection; using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -66,6 +67,27 @@ await That(properties.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Properties properties = In.AssemblyContaining().Properties() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(properties).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that properties with PropertyFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Except.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Except.Tests.cs index be4be732..3f80cbab 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Except.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Except.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -31,6 +32,48 @@ await That(types.GetDescription()) .IsEqualTo("types except type => type.Name == \"TypeToExclude\" in assembly").AsPrefix(); } + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Types types = In.AssemblyContaining().Types() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(types).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that types except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + + [Fact] + public async Task WhenPredicateThrows_ShouldFailWhenNegated() + { + Filtered.Types types = In.AssemblyContaining().Types() + .Except(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(types).DoesNotComplyWith(they => they.IsEmpty()); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that types except _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is not empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("a predicate that throws answers neither the expectation nor its negation"); + } + private class TypeToExclude; } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Which.Tests.cs b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Which.Tests.cs index f631b6b4..59ac2e53 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Which.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.Which.Tests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -21,6 +22,48 @@ await That(types.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WhenPredicateThrows_ShouldFail() + { + Filtered.Types types = In.AssemblyContaining() + .Types().Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(types).AreNotAbstract(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that types matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + are all not abstract, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + + [Fact] + public async Task WhenPredicateThrows_ShouldFailWhenNegated() + { + Filtered.Types types = In.AssemblyContaining() + .Types().Which(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(types).DoesNotComplyWith(they => they.AreNotAbstract()); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that types matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + also contain an abstract type, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("a predicate that throws answers neither the expectation nor its negation"); + } + private class SomeClassToVerifyViaAPredicate; } } diff --git a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.With.AttributeTests.cs b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.With.AttributeTests.cs index 7fc40aee..25700733 100644 --- a/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.With.AttributeTests.cs +++ b/Tests/aweXpect.Reflection.Tests/Filters/TypeFilters.With.AttributeTests.cs @@ -1,4 +1,5 @@ using aweXpect.Reflection.Collections; +using Xunit.Sdk; namespace aweXpect.Reflection.Tests.Filters; @@ -58,6 +59,27 @@ await That(types.GetDescription()) .AsPrefix(); } + [Fact] + public async Task WithPredicate_WhenPredicateThrows_ShouldFail() + { + Filtered.Types types = In.AssemblyContaining().Types() + .With(_ => throw new InvalidOperationException("boom")); + + async Task Act() + { + await That(types).IsEmpty(); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that types with TypeFilters.With.FooAttribute matching _ => throw new InvalidOperationException("boom") in assembly containing type AssemblyFilters + is empty, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + public static TheoryData GetFooValues() => new() { diff --git a/Tests/aweXpect.Reflection.Tests/ThatAssemblies.DependOn.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatAssemblies.DependOn.Tests.cs index e9a39dfb..eb683cfc 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatAssemblies.DependOn.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatAssemblies.DependOn.Tests.cs @@ -101,7 +101,7 @@ async Task Act() await That(Act).Throws() .WithMessage(""" Expected that in assembly containing type PublicAbstractClass - not all have dependency on assembly not equal to "aweXpect.Core", + not all have dependency on assembly equal to "aweXpect.Core", but it only contained assemblies with the unexpected dependency Collection: @@ -109,7 +109,8 @@ but it only contained assemblies with the unexpected dependency aweXpect.Reflection.Tests, Version=*, Culture=neutral, PublicKeyToken=null ] """) - .AsWildcard(); + .AsWildcard() + .Because("\"not all\" already negates the expectation, so the dependency must not be negated again"); } } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatAssembly.DoesNotHaveName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatAssembly.DoesNotHaveName.Tests.cs index 9a8289ba..4da5f85f 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatAssembly.DoesNotHaveName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatAssembly.DoesNotHaveName.Tests.cs @@ -37,7 +37,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "aweXpect.Reflection.Tests", - but it was "aweXpect.Reflection.Tests" + but it had name "aweXpect.Reflection.Tests" """); } @@ -55,7 +55,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not ending with ".Tests", - but it was "aweXpect.Reflection.Tests" + but it had name "aweXpect.Reflection.Tests" """); } @@ -91,7 +91,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "AWExPECT.rEFLECTION.tESTS" ignoring case, - but it was "aweXpect.Reflection.Tests" + but it had name "aweXpect.Reflection.Tests" """); } @@ -125,7 +125,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "NonExistentAssembly", - but it was "aweXpect.Reflection.Tests", which differs at index 0: + but it had name "aweXpect.Reflection.Tests", which differs at index 0: ↓ (actual) "aweXpect.Reflection.Tests" "NonExistentAssembly" diff --git a/Tests/aweXpect.Reflection.Tests/ThatAssembly.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatAssembly.HasName.Tests.cs index bfb26f55..4e04bf4c 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatAssembly.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatAssembly.HasName.Tests.cs @@ -24,7 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Reflection", - but it was "aweXpect.Reflection.Tests", which differs at index 0: + but it had name "aweXpect.Reflection.Tests", which differs at index 0: ↓ (actual) "aweXpect.Reflection.Tests" "Reflection" @@ -119,7 +119,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "aweXpect.Reflection.Tests", - but it was "aweXpect.Reflection.Tests" + but it had name "aweXpect.Reflection.Tests" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatAssembly.Targets.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatAssembly.Targets.Tests.cs index 55df2c4b..9ad4dda9 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatAssembly.Targets.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatAssembly.Targets.Tests.cs @@ -29,11 +29,11 @@ async Task Act() } await That(Act).Throws() - .WithMessage(""" - Expected that subject - targets equal to "net99.0", - but it * - """).AsWildcard(); + .WithMessage($""" + Expected that subject + targets equal to "net99.0", + but it had target framework "{CurrentTarget}", which differs * + """).AsWildcard(); } [Fact] @@ -110,8 +110,8 @@ await That(Act).Throws() .WithMessage($""" Expected that subject targets not equal to "{CurrentTarget}", - but it * - """).AsWildcard(); + but it had target framework "{CurrentTarget}" + """); } } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatEvent.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatEvent.HasName.Tests.cs index f6ae2614..3e366c67 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatEvent.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatEvent.HasName.Tests.cs @@ -84,7 +84,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Event", - but it was "PublicEvent", which differs at index 0: + but it had name "PublicEvent", which differs at index 0: ↓ (actual) "PublicEvent" "Event" @@ -124,7 +124,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicEvent", - but it was "PublicEvent" + but it had name "PublicEvent" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatField.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatField.HasName.Tests.cs index 4f283dc7..442fa544 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatField.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatField.HasName.Tests.cs @@ -24,7 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Field", - but it was "PublicField", which differs at index 0: + but it had name "PublicField", which differs at index 0: ↓ (actual) "PublicField" "Field" @@ -124,7 +124,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicField", - but it was "PublicField" + but it had name "PublicField" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatMethod.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatMethod.HasName.Tests.cs index 04f9950a..f5efc6d3 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatMethod.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatMethod.HasName.Tests.cs @@ -24,7 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Method", - but it was "PublicMethod", which differs at index 0: + but it had name "PublicMethod", which differs at index 0: ↓ (actual) "PublicMethod" "Method" @@ -124,7 +124,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicMethod", - but it was "PublicMethod" + but it had name "PublicMethod" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatMethod.HasParameter.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatMethod.HasParameter.Tests.cs index eb457d60..7fea7481 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatMethod.HasParameter.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatMethod.HasParameter.Tests.cs @@ -1,5 +1,8 @@ using System.IO; using System.Reflection; +using aweXpect.Core; +using aweXpect.Reflection.Options; +using aweXpect.Reflection.Results; using aweXpect.Reflection.Tests.TestHelpers; using Xunit.Sdk; @@ -469,6 +472,30 @@ async Task Act() await That(Act).DoesNotThrow(); } + [Fact] + public async Task WhenParameterPredicateThrows_ShouldFail() + { + MethodInfo methodInfo = typeof(TestClass).GetMethod(nameof(TestClass.MethodWithIntAndString))!; + Func predicate = _ => throw new InvalidOperationException("boom"); + + async Task Act() + { + ParameterCollectionResult result = That(methodInfo).HasParameter(); + ((IOptionsProvider)result).Options + .AddPredicate(predicate, () => ""); + await result; + } + + await That(Act).Throws() + .WithMessage(""" + Expected that methodInfo + has parameter of type int, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + [Fact] public async Task WithDefaultValue_WhenParameterHasDefault_ShouldSucceed() { @@ -771,6 +798,29 @@ but it did """); } + [Fact] + public async Task WhenParameterPredicateThrows_ShouldFail() + { + MethodInfo methodInfo = typeof(TestClass).GetMethod(nameof(TestClass.MethodWithIntAndString))!; + Func predicate = _ => throw new InvalidOperationException("boom"); + + async Task Act() + { + await That(methodInfo).DoesNotComplyWith(it + => ((IOptionsProvider)it.HasParameter()).Options + .AddPredicate(predicate, () => "")); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that methodInfo + does not have parameter of type int, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("a predicate that throws answers neither the expectation nor its negation"); + } + #pragma warning disable CA1822 // ReSharper disable UnusedParameter.Local // ReSharper disable UnusedMember.Local diff --git a/Tests/aweXpect.Reflection.Tests/ThatProperty.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatProperty.HasName.Tests.cs index b76855ff..a47e8724 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatProperty.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatProperty.HasName.Tests.cs @@ -24,7 +24,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Property", - but it was "PublicProperty", which differs at index 1: + but it had name "PublicProperty", which differs at index 1: ↓ (actual) "PublicProperty" "Property" @@ -124,7 +124,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicProperty", - but it was "PublicProperty" + but it had name "PublicProperty" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotHaveName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotHaveName.Tests.cs index 2dd249b7..1c768839 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotHaveName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotHaveName.Tests.cs @@ -49,7 +49,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicAbstractClass", - but it was "PublicAbstractClass" + but it had name "PublicAbstractClass" """); } @@ -67,7 +67,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not ending with "AbstractClass", - but it was "PublicAbstractClass" + but it had name "PublicAbstractClass" """); } @@ -103,7 +103,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "pUBLICaBSTRACTcLASS" ignoring case, - but it was "PublicAbstractClass" + but it had name "PublicAbstractClass" """); } } @@ -124,7 +124,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "NonExistentClass", - but it was "PublicAbstractClass", which differs at index 0: + but it had name "PublicAbstractClass", which differs at index 0: ↓ (actual) "PublicAbstractClass" "NonExistentClass" diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotImplement.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotImplement.Tests.cs index 44d1ffe6..323c2e04 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotImplement.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotImplement.Tests.cs @@ -50,10 +50,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not directly implement ThatType.ITestInterface, - but it did directly implement ThatType.ITestInterface + but it did Actual: - aweXpect.Reflection.Tests.ThatType+ClassWithInterface + ThatType.ClassWithInterface """); } @@ -84,10 +84,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not implement ThatType.ITestInterface, - but it did implement ThatType.ITestInterface + but it did Actual: - aweXpect.Reflection.Tests.ThatType+ClassWithInterface + ThatType.ClassWithInterface """); } } @@ -139,10 +139,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not implement ThatType.ITestInterface, - but it did implement ThatType.ITestInterface + but it did Actual: - aweXpect.Reflection.Tests.ThatType+ClassWithInterface + ThatType.ClassWithInterface """); } } @@ -163,10 +163,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject implements ThatType.ITestInterface, - but it did not implement ThatType.ITestInterface + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotInheritFrom.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotInheritFrom.Tests.cs index d4e27ae4..dac9da0c 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotInheritFrom.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.DoesNotInheritFrom.Tests.cs @@ -50,10 +50,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } @@ -71,10 +71,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit directly from ThatType.BaseClass, - but it did inherit directly from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } @@ -92,10 +92,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+GrandChildClass + ThatType.GrandChildClass """); } @@ -160,10 +160,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } @@ -182,10 +182,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+GrandChildClass + ThatType.GrandChildClass """); } } @@ -221,10 +221,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits from ThatType.BaseClass, - but it did not inherit from ThatType.BaseClass + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.HasName.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.HasName.Tests.cs index 39e14ae8..1ba7e917 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.HasName.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.HasName.Tests.cs @@ -23,7 +23,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name equal to "Abstract", - but it was "PublicAbstractClass", which differs at index 0: + but it had name "PublicAbstractClass", which differs at index 0: ↓ (actual) "PublicAbstractClass" "Abstract" @@ -118,7 +118,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has name not equal to "PublicAbstractClass", - but it was "PublicAbstractClass" + but it had name "PublicAbstractClass" """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.HasNamespace.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.HasNamespace.Tests.cs index a8c901a5..21fa73d6 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.HasNamespace.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.HasNamespace.Tests.cs @@ -23,7 +23,7 @@ await That(Act).Throws() .WithMessage(""" Expected that subject has namespace equal to "Reflection.Tests.TestHelpers", - but it was "aweXpect.Reflection.Tests.Test…", which differs at index 0: + but it had namespace "aweXpect.Reflection.Tests.Test…", which differs at index 0: ↓ (actual) "aweXpect.Reflection.Tests.TestHelpers.Types" "Reflection.Tests.TestHelpers" @@ -103,7 +103,12 @@ await That(subject).DoesNotComplyWith(it } await That(Act).Throws() - .WithMessage("*does not have namespace*aweXpect.Reflection.Tests.TestHelpers.Types*").AsWildcard(); + .WithMessage(""" + Expected that subject + has namespace not equal to "aweXpect.Reflection.Tests.Test…", + but it had namespace "aweXpect.Reflection.Tests.TestHelpers.Types" + """) + .Because("the negated match type already says \"not\", so the verb must not be negated again"); } } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.Implements.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.Implements.Tests.cs index d289d0ad..2a33dd05 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.Implements.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.Implements.Tests.cs @@ -22,10 +22,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject directly implements ThatType.ITestInterface, - but it implemented ThatType.ITestInterface only indirectly + but it did only indirectly Actual: - aweXpect.Reflection.Tests.ThatType+ClassWithDerivedInterface + ThatType.ClassWithDerivedInterface """); } @@ -90,10 +90,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject implements ThatType.ITestInterface, - but it did not implement ThatType.ITestInterface + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -111,10 +111,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject directly implements ThatType.ITestInterface, - but it did not implement ThatType.ITestInterface + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -158,10 +158,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject directly implements ThatType.ITestInterface, - but it implemented ThatType.ITestInterface only indirectly + but it did only indirectly Actual: - aweXpect.Reflection.Tests.ThatType+DerivedFromClassWithInterface + ThatType.DerivedFromClassWithInterface """); } @@ -240,10 +240,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject implements ThatType.ITestInterface, - but it did not implement ThatType.ITestInterface + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -291,10 +291,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not implement ThatType.ITestInterface, - but it did implement ThatType.ITestInterface + but it did Actual: - aweXpect.Reflection.Tests.ThatType+ClassWithInterface + ThatType.ClassWithInterface """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.InheritsFrom.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.InheritsFrom.Tests.cs index 799f6002..e20000d7 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.InheritsFrom.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.InheritsFrom.Tests.cs @@ -37,10 +37,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits from ThatType.BaseClass, - but it did not inherit from ThatType.BaseClass + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -58,10 +58,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits directly from ThatType.BaseClass, - but it did not inherit from ThatType.BaseClass + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -118,10 +118,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits directly from ThatType.BaseClass, - but it inherited from ThatType.BaseClass only indirectly + but it did only indirectly Actual: - aweXpect.Reflection.Tests.ThatType+GrandChildClass + ThatType.GrandChildClass """); } @@ -139,10 +139,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits from ThatType.BaseClass, - but it did not inherit from ThatType.BaseClass + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+BaseClass + ThatType.BaseClass """); } } @@ -195,10 +195,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits from ThatType.BaseClass, - but it did not inherit from ThatType.BaseClass + but it did not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -245,10 +245,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject inherits directly from ThatType.BaseClass, - but it inherited from ThatType.BaseClass only indirectly + but it did only indirectly Actual: - aweXpect.Reflection.Tests.ThatType+GrandChildClass + ThatType.GrandChildClass """); } } @@ -297,10 +297,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } @@ -318,10 +318,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject does not inherit from ThatType.BaseClass, - but it did inherit from ThatType.BaseClass + but it did Actual: - aweXpect.Reflection.Tests.ThatType+GrandChildClass + ThatType.GrandChildClass """); } } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableFrom.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableFrom.Tests.cs index 0dea0a87..fb85d410 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableFrom.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableFrom.Tests.cs @@ -65,10 +65,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is assignable from ThatType.UnrelatedClass, - but it was not assignable from ThatType.UnrelatedClass + but it was not Actual: - aweXpect.Reflection.Tests.ThatType+BaseClass + ThatType.BaseClass """); } @@ -120,10 +120,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is not assignable from ThatType.DerivedClass, - but it was assignable from ThatType.DerivedClass + but it was Actual: - aweXpect.Reflection.Tests.ThatType+BaseClass + ThatType.BaseClass """); } @@ -176,10 +176,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is not assignable from ThatType.DerivedClass, - but it was assignable from ThatType.DerivedClass + but it was Actual: - aweXpect.Reflection.Tests.ThatType+BaseClass + ThatType.BaseClass """); } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableTo.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableTo.Tests.cs index 976df894..a57b55b9 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableTo.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.IsAssignableTo.Tests.cs @@ -93,10 +93,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is assignable to ThatType.BaseClass, - but it was not assignable to ThatType.BaseClass + but it was not Actual: - aweXpect.Reflection.Tests.ThatType+UnrelatedClass + ThatType.UnrelatedClass """); } @@ -148,10 +148,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is not assignable to ThatType.BaseClass, - but it was assignable to ThatType.BaseClass + but it was Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } @@ -204,10 +204,10 @@ await That(Act).Throws() .WithMessage(""" Expected that subject is not assignable to ThatType.BaseClass, - but it was assignable to ThatType.BaseClass + but it was Actual: - aweXpect.Reflection.Tests.ThatType+DerivedClass + ThatType.DerivedClass """); } diff --git a/Tests/aweXpect.Reflection.Tests/ThatType.IsGeneric.Tests.cs b/Tests/aweXpect.Reflection.Tests/ThatType.IsGeneric.Tests.cs index c35fc7f8..0acbf377 100644 --- a/Tests/aweXpect.Reflection.Tests/ThatType.IsGeneric.Tests.cs +++ b/Tests/aweXpect.Reflection.Tests/ThatType.IsGeneric.Tests.cs @@ -1,4 +1,8 @@ -using aweXpect.Reflection.Tests.TestHelpers.Types; +using aweXpect.Core; +using aweXpect.Options; +using aweXpect.Reflection.Options; +using aweXpect.Reflection.Results; +using aweXpect.Reflection.Tests.TestHelpers.Types; using Xunit.Sdk; namespace aweXpect.Reflection.Tests; @@ -9,6 +13,53 @@ public sealed partial class IsGeneric { public sealed class Tests { + [Fact] + public async Task WhenArgumentFilterThrows_ShouldFail() + { + Type subject = typeof(PublicGenericClass); + Func predicate = (_, _) => throw new InvalidOperationException("boom"); + + async Task Act() + { + GenericArgumentCollectionResult result = That(subject).IsGeneric(); + ((IOptionsProvider)result).Options.AddFilter( + new GenericArgumentFilterOptions(predicate, () => "matching predicate"), new CollectionIndexOptions()); + await result; + } + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is generic with argument matching predicate, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + + [Fact] + public async Task WhenArgumentsPredicateThrows_ShouldFail() + { + Type subject = typeof(PublicGenericClass); + + async Task Act() + { + GenericArgumentCollectionResult result = That(subject).IsGeneric(); + ((IOptionsProvider)result).Options.AddPredicate( + _ => throw new InvalidOperationException("boom"), () => "with arguments matching predicate"); + await result; + } + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is generic with arguments matching predicate, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("an exception of the predicate must fail the expectation instead of aborting the evaluation"); + } + [Fact] public async Task WhenTypeIsGeneric_ShouldSucceed() { @@ -61,6 +112,28 @@ but it was public sealed class NegatedTests { + [Fact] + public async Task WhenArgumentsPredicateThrows_ShouldFail() + { + Type subject = typeof(PublicGenericClass); + + async Task Act() + { + await That(subject).DoesNotComplyWith(it + => ((IOptionsProvider)it.IsGeneric()).Options.AddPredicate( + _ => throw new InvalidOperationException("boom"), () => "with arguments matching predicate")); + } + + await That(Act).Throws() + .WithMessage(""" + Expected that subject + is not generic, + but the predicate did throw an InvalidOperationException: + boom + """) + .Because("a predicate that throws answers neither the expectation nor its negation"); + } + [Fact] public async Task WhenTypeIsGeneric_ShouldFail() {