Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,21 @@ Shared by all types and members.
| | Filter | Assert (single) | Assert (many) |
|---------------------------------|-------------------------|---------------------------|----------------------------|
| by name | `.WithName("x")` | `.HasName("x")` | `.HaveName("x")` |
| not by name | `.WithoutName("x")` | `.DoesNotHaveName("x")` | `.DoNotHaveName("x")` |
| by namespace *(types only)* | `.WithNamespace("x")` | `.HasNamespace("x")` | `.HaveNamespace("x")` |
| within namespace *(types only)* | `.WithinNamespace("x")` | `.IsWithinNamespace("x")` | `.AreWithinNamespace("x")` |

`WithoutName`/`DoesNotHaveName`/`DoNotHaveName` are the negations of the name filter and assertions:
`WithoutName` keeps the items whose name does *not* match, `DoesNotHaveName` verifies a single item is
*not* named the given value, and `DoNotHaveName` verifies that *none* of the items in a collection are.
They accept the same [string matching options](#string-matching-options) as their positive counterparts:

```csharp
// Verify that no type in the production assembly is named with a "Test" suffix
await Expect.That(In.AssemblyContaining<MyClass>().Types())
.DoNotHaveName("Test").AsSuffix();
```

The name/namespace *equality* filters and assertions (`WithName`, `WithNamespace`, and their
`Has`/`Have` counterparts) accept the
[string matching options](#string-matching-options) (`AsPrefix`, `AsSuffix`, `AsWildcard`, `AsRegex`,
Expand Down Expand Up @@ -429,6 +441,7 @@ on them directly:
| | Filter | Assert (single) | Assert (many) |
|-----------------------------|----------------------------------------|----------------------------------|-----------------------------------|
| by name | `.WithName("x")` | `.HasName("x")` | `.HaveName("x")` |
| not by name | `.WithoutName("x")` | `.DoesNotHaveName("x")` | `.DoNotHaveName("x")` |
| by target framework | `.WhichTarget("net8.0")` | `.Targets("net8.0")` | `.Target("net8.0")` |
| has attribute | `.With<TAttribute>()` | `.Has<TAttribute>()` | `.Have<TAttribute>()` |
| depends on assembly | `.WhichHaveADependencyOn("x")` | `.HasADependencyOn("x")` | `.HaveADependencyOn("x")` |
Expand Down
22 changes: 22 additions & 0 deletions Source/aweXpect.Reflection/Filters/AssemblyFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class AssemblyFilters
{
/// <summary>
/// Filter for assemblies without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Assemblies.StringEqualityResultType WithoutName(this Filtered.Assemblies @this,
string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Assemblies.StringEqualityResultType(@this.Which(Filter.Suffix<Assembly>(
async assembly => !await options.AreConsideredEqual(assembly.GetName().Name, unexpected),
() => $" without name {options.GetExpectation(unexpected, ExpectationGrammars.None)}")),
options);
}
}
21 changes: 21 additions & 0 deletions Source/aweXpect.Reflection/Filters/EventFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class EventFilters
{
/// <summary>
/// Filter for events without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Events.StringEqualityResultType WithoutName(this Filtered.Events @this, string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Events.StringEqualityResultType(@this.Which(Filter.Suffix<EventInfo>(
async eventInfo => !await options.AreConsideredEqual(eventInfo.Name, unexpected),
() => $"without name {options.GetExpectation(unexpected, ExpectationGrammars.None)} ")),
options);
}
}
21 changes: 21 additions & 0 deletions Source/aweXpect.Reflection/Filters/FieldFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class FieldFilters
{
/// <summary>
/// Filter for fields without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Fields.StringEqualityResultType WithoutName(this Filtered.Fields @this, string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Fields.StringEqualityResultType(@this.Which(Filter.Suffix<FieldInfo>(
async fieldInfo => !await options.AreConsideredEqual(fieldInfo.Name, unexpected),
() => $"without name {options.GetExpectation(unexpected, ExpectationGrammars.None)} ")),
options);
}
}
21 changes: 21 additions & 0 deletions Source/aweXpect.Reflection/Filters/MethodFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class MethodFilters
{
/// <summary>
/// Filter for methods without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Methods.StringEqualityResultType WithoutName(this Filtered.Methods @this, string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Methods.StringEqualityResultType(@this.Which(Filter.Suffix<MethodInfo>(
async methodInfo => !await options.AreConsideredEqual(methodInfo.Name, unexpected),
() => $"without name {options.GetExpectation(unexpected, ExpectationGrammars.None)} ")),
options);
}
}
22 changes: 22 additions & 0 deletions Source/aweXpect.Reflection/Filters/PropertyFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class PropertyFilters
{
/// <summary>
/// Filter for properties without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Properties.StringEqualityResultType WithoutName(this Filtered.Properties @this,
string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Properties.StringEqualityResultType(@this.Which(Filter.Suffix<PropertyInfo>(
async propertyInfo => !await options.AreConsideredEqual(propertyInfo.Name, unexpected),
() => $"without name {options.GetExpectation(unexpected, ExpectationGrammars.None)} ")),
options);
}
}
21 changes: 21 additions & 0 deletions Source/aweXpect.Reflection/Filters/TypeFilters.WithoutName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using aweXpect.Core;
using aweXpect.Options;
using aweXpect.Reflection.Collections;

namespace aweXpect.Reflection;

public static partial class TypeFilters
{
/// <summary>
/// Filter for types without the <paramref name="unexpected" /> name.
/// </summary>
public static Filtered.Types.StringEqualityResultType WithoutName(this Filtered.Types @this, string unexpected)
{
StringEqualityOptions options = new();
return new Filtered.Types.StringEqualityResultType(@this.Which(Filter.Suffix<Type>(
async type => !await options.AreConsideredEqual(type.Name, unexpected),
() => $"without name {options.GetExpectation(unexpected, ExpectationGrammars.None)} ")),
options);
}
}
92 changes: 92 additions & 0 deletions Source/aweXpect.Reflection/ThatAssemblies.DoNotHaveName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Options;
using aweXpect.Reflection.Helpers;
using aweXpect.Results;

// ReSharper disable PossibleMultipleEnumeration

namespace aweXpect.Reflection;

public static partial class ThatAssemblies
{
/// <summary>
/// Verifies that none of the items in the filtered collection of <see cref="Assembly" /> have
/// the <paramref name="unexpected" /> name.
/// </summary>
public static StringEqualityTypeResult<IEnumerable<Assembly?>, IThat<IEnumerable<Assembly?>>> DoNotHaveName(
this IThat<IEnumerable<Assembly?>> subject, string unexpected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<IEnumerable<Assembly?>, IThat<IEnumerable<Assembly?>>>(subject.Get()
.ExpectationBuilder.AddConstraint<IEnumerable<Assembly?>>((it, grammars)
=> new DoNotHaveNameConstraint(it, grammars, unexpected, options)),
subject,
options);
}

#if NET8_0_OR_GREATER
/// <summary>
/// Verifies that none of the items in the filtered collection of <see cref="Assembly" /> have
/// the <paramref name="unexpected" /> name.
/// </summary>
public static StringEqualityTypeResult<IAsyncEnumerable<Assembly?>, IThat<IAsyncEnumerable<Assembly?>>>
DoNotHaveName(
this IThat<IAsyncEnumerable<Assembly?>> subject, string unexpected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<IAsyncEnumerable<Assembly?>, IThat<IAsyncEnumerable<Assembly?>>>(subject
.Get()
.ExpectationBuilder.AddConstraint<IAsyncEnumerable<Assembly?>>((it, grammars)
=> new DoNotHaveNameConstraint(it, grammars, unexpected, options)),
subject,
options);
}
#endif

private sealed class DoNotHaveNameConstraint(
string it,
ExpectationGrammars grammars,
string unexpected,
StringEqualityOptions options)
: CollectionConstraintResult<Assembly?>(grammars),
IAsyncConstraint<IEnumerable<Assembly?>>
#if NET8_0_OR_GREATER
, IAsyncConstraint<IAsyncEnumerable<Assembly?>>
#endif
{
#if NET8_0_OR_GREATER
public async Task<ConstraintResult> IsMetBy(IAsyncEnumerable<Assembly?> actual,
CancellationToken cancellationToken)
=> await SetAsyncValue(actual,
async assembly => !await options.AreConsideredEqual(assembly?.GetName().Name, unexpected));
#endif

public async Task<ConstraintResult> IsMetBy(IEnumerable<Assembly?> actual, CancellationToken cancellationToken)
=> await SetValue(actual,
async assembly => !await options.AreConsideredEqual(assembly?.GetName().Name, unexpected));

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("all have name ").Append(options.GetExpectation(unexpected, Grammars.Negate()));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" contained not matching types ");
Formatter.Format(stringBuilder, NotMatching, FormattingOptions.Indented(indentation));
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("not all have name ").Append(options.GetExpectation(unexpected, Grammars.Negate()));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" only contained matching types ");
Formatter.Format(stringBuilder, Matching, FormattingOptions.Indented(indentation));
}
}
}
27 changes: 27 additions & 0 deletions Source/aweXpect.Reflection/ThatAssembly.DoesNotHaveName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Options;
using aweXpect.Reflection.Helpers;
using aweXpect.Results;

// ReSharper disable PossibleMultipleEnumeration

namespace aweXpect.Reflection;

public static partial class ThatAssembly
{
/// <summary>
/// Verifies that the <see cref="Assembly" /> does not have the <paramref name="unexpected" /> name.
/// </summary>
public static StringEqualityTypeResult<Assembly?, IThat<Assembly?>> DoesNotHaveName(
this IThat<Assembly?> subject, string unexpected)
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<Assembly?, IThat<Assembly?>>(
subject.Get().ExpectationBuilder.AddConstraint((it, grammars)
=> new HasNameConstraint(it, grammars, unexpected, options).Invert()),
subject,
options);
}
}
28 changes: 28 additions & 0 deletions Source/aweXpect.Reflection/ThatMember.DoesNotHaveName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Options;
using aweXpect.Reflection.Helpers;
using aweXpect.Results;

// ReSharper disable PossibleMultipleEnumeration

namespace aweXpect.Reflection;

public static partial class ThatMember
{
/// <summary>
/// Verifies that the <typeparamref name="TMember" /> does not have the <paramref name="unexpected" /> name.
/// </summary>
public static StringEqualityTypeResult<TMember, IThat<TMember>> DoesNotHaveName<TMember>(
this IThat<TMember> subject, string unexpected)
where TMember : MemberInfo?
{
StringEqualityOptions options = new();
return new StringEqualityTypeResult<TMember, IThat<TMember>>(
subject.Get().ExpectationBuilder.AddConstraint((it, grammars)
=> new HasNameConstraint<TMember>(it, grammars, unexpected, options).Invert()),
subject,
options);
}
}
Loading
Loading