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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/AssemblyFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Assemblies Except(this Filtered.Assemblies @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<Assembly>(
assembly => !predicate(assembly),
assembly => !UserCode.Invoke(predicate, assembly, "the predicate"),
$" except {doNotPopulateThisValue.TrimCommonWhiteSpace()}"));
}
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/AssemblyFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Assemblies Which(this Filtered.Assemblies @this,
Func<Assembly, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $" matching {doNotPopulateThisValue.TrimCommonWhiteSpace()}"));
=> @this.Which(Filter.Suffix<Assembly>(assembly => UserCode.Invoke(predicate, assembly, "the predicate"),
$" matching {doNotPopulateThisValue.TrimCommonWhiteSpace()}"));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -18,7 +19,7 @@ public static Filtered.Assemblies WithVersion(this Filtered.Assemblies @this,
string doNotPopulateThisValue = "")
{
IChangeableFilter<Assembly> filter = Filter.Suffix<Assembly>(
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Constructors Except(this Filtered.Constructors @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<ConstructorInfo>(
constructor => !predicate(constructor),
constructor => !UserCode.Invoke(predicate, constructor, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Constructors Which(this Filtered.Constructors @this,
Func<ConstructorInfo, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<ConstructorInfo>(constructor => UserCode.Invoke(predicate, constructor, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/EventFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Events Except(this Filtered.Events @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<EventInfo>(
eventInfo => !predicate(eventInfo),
eventInfo => !UserCode.Invoke(predicate, eventInfo, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/EventFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Events Which(this Filtered.Events @this,
Func<EventInfo, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<EventInfo>(eventInfo => UserCode.Invoke(predicate, eventInfo, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/FieldFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Fields Except(this Filtered.Fields @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<FieldInfo>(
field => !predicate(field),
field => !UserCode.Invoke(predicate, field, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/FieldFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Fields Which(this Filtered.Fields @this,
Func<FieldInfo, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<FieldInfo>(field => UserCode.Invoke(predicate, field, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/MethodFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Methods Except(this Filtered.Methods @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<MethodInfo>(
method => !predicate(method),
method => !UserCode.Invoke(predicate, method, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/MethodFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Methods Which(this Filtered.Methods @this,
Func<MethodInfo, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<MethodInfo>(method => UserCode.Invoke(predicate, method, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/PropertyFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -19,6 +20,6 @@ public static Filtered.Properties Except(this Filtered.Properties @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<PropertyInfo>(
property => !predicate(property),
property => !UserCode.Invoke(predicate, property, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/PropertyFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -15,5 +16,6 @@ public static Filtered.Properties Which(this Filtered.Properties @this,
Func<PropertyInfo, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<PropertyInfo>(property => UserCode.Invoke(predicate, property, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Filters/TypeFilters.Except.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -18,7 +19,7 @@ public static Filtered.Types Except(this Filtered.Types @this,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix<Type>(
type => !predicate(type),
type => !UserCode.Invoke(predicate, type, "the predicate"),
$"except {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Source/aweXpect.Reflection/Filters/TypeFilters.Which.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using aweXpect.Core;
using aweXpect.Reflection.Collections;
using aweXpect.Reflection.Helpers;

Expand All @@ -14,5 +15,6 @@ public static Filtered.Types Which(this Filtered.Types @this,
Func<Type, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> @this.Which(Filter.Suffix(predicate, $"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
=> @this.Which(Filter.Suffix<Type>(type => UserCode.Invoke(predicate, type, "the predicate"),
$"matching {doNotPopulateThisValue.TrimCommonWhiteSpace()} "));
}
2 changes: 1 addition & 1 deletion Source/aweXpect.Reflection/Helpers/AssemblyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Helpers/ConstructorInfoHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using aweXpect.Core;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection.Helpers;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Helpers/EventInfoHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using aweXpect.Core;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection.Helpers;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Helpers/FieldInfoHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using aweXpect.Core;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection.Helpers;
Expand Down Expand Up @@ -92,7 +93,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Reflection/Helpers/MethodInfoHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Helpers/PropertyInfoHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection;
using aweXpect.Core;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection.Helpers;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute castedAttribute)
{
return predicate?.Invoke(castedAttribute) ?? true;
return predicate is null || UserCode.Invoke(predicate, castedAttribute, "the predicate");
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Reflection/Helpers/TypeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public static bool HasAttribute<TAttribute>(
.FirstOrDefault();
if (attribute is TAttribute attributeValue)
{
return predicate?.Invoke(attributeValue) ?? true;
return predicate is null || UserCode.Invoke(predicate, attributeValue, "the predicate");
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using aweXpect.Core;

namespace aweXpect.Reflection.Options;

Expand Down Expand Up @@ -55,7 +56,8 @@ public ValueTask<bool> Matches(Type argument, string? genericArgumentName = null
return new ValueTask<bool>(true);
}

return _predicates.AllAsync(predicate => predicate(argument, genericArgumentName));
return _predicates.AllAsync(predicate
=> UserCode.InvokeAsync(() => predicate(argument, genericArgumentName), "the predicate"));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Options;

namespace aweXpect.Reflection.Options;
Expand Down Expand Up @@ -74,7 +75,7 @@ private async ValueTask<bool>
}

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<bool> MatchesFilters(Type[] arguments, string[]? genericTypeNames)
Expand Down
3 changes: 2 additions & 1 deletion Source/aweXpect.Reflection/Options/ParameterFilterOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using aweXpect.Core;

namespace aweXpect.Reflection.Options;

Expand Down Expand Up @@ -98,7 +99,7 @@ public ValueTask<bool> Matches(ParameterInfo parameter)
return new ValueTask<bool>(true);
}

return _predicates.AllAsync(predicate => predicate(parameter));
return _predicates.AllAsync(predicate => UserCode.InvokeAsync(() => predicate(parameter), "the predicate"));
}

private static Func<ParameterInfo, ValueTask<bool>> ToAsyncPredicate(Func<ParameterInfo, bool> predicate)
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Reflection/ThatAssemblies.DependOn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading
Loading