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: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ evaluated collection that you can navigate and filter further.
| `In.AllLoadedAssemblies()` | all currently loaded assemblies (system assemblies [excluded](#assembly-exclusions)) |
| `In.Assemblies(a1, a2, …)` / `In.Assemblies(collection)` | the given assemblies |
| `In.AssemblyContaining<T>()` / `In.AssemblyContaining(typeof(T))` | the assembly that declares `T` |
| `In.EntryAssembly()` | the entry assembly |
| `In.ExecutingAssembly()` | the executing assembly |
| `In.Type<T>()` / `In.Type(typeof(T))` | a single type |
| `In.Types<T1, T2>()` / `In.Types<T1, T2, T3>()` / `In.Types(t1, t2, …)` | the given types |
| `In.Constructors(…)` / `In.Events(…)` / `In.Fields(…)` / `In.Methods(…)` / `In.Properties(…)` | the given members |
Expand All @@ -111,7 +109,6 @@ point for architecture rules:
| `Types.InAllLoadedAssemblies()` | all types in all currently loaded assemblies |
| `Types.InAssemblies(a1, a2, …)` | all types in the given assemblies |
| `Types.InAssemblyContaining<T>()` / `…(typeof(T))` | all types in the assembly that declares `T` |
| `Types.InEntryAssembly()` / `Types.InExecutingAssembly()` | all types in the entry / executing assembly |

`Types.InNamespace(…)` searches all loaded assemblies by default; chain one of the same `In*` methods directly
after it to clarify the assembly source (it can only be specified once, before any further filters):
Expand Down
23 changes: 6 additions & 17 deletions Source/aweXpect.Reflection/Collections/Filtered.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,41 +507,30 @@ internal InNamespaceResult(string @namespace)
/// current <see cref="System.AppDomain.CurrentDomain" /> (the default).
/// </summary>
public Types InAllLoadedAssemblies()
=> In.AllLoadedAssemblies().Types().WithinNamespace(_namespace);
=> From(In.AllLoadedAssemblies());

/// <summary>
/// Clarifies that the types within the namespace are searched in the given <paramref name="assemblies" />.
/// </summary>
public Types InAssemblies(params IEnumerable<Assembly?> assemblies)
=> new Assemblies(assemblies, $"in the assemblies {Formatter.Format(assemblies)}").Types()
.WithinNamespace(_namespace);
=> From(In.Assemblies(assemblies));

/// <summary>
/// Clarifies that the types within the namespace are searched in the assembly that contains
/// the <typeparamref name="TType" />.
/// </summary>
public Types InAssemblyContaining<TType>()
=> In.AssemblyContaining<TType>().Types().WithinNamespace(_namespace);
=> From(In.AssemblyContaining<TType>());

/// <summary>
/// Clarifies that the types within the namespace are searched in the assembly that contains
/// the <paramref name="type" />.
/// </summary>
public Types InAssemblyContaining(Type type)
=> In.AssemblyContaining(type).Types().WithinNamespace(_namespace);
=> From(In.AssemblyContaining(type));

/// <summary>
/// Clarifies that the types within the namespace are searched in the <see cref="Assembly.GetEntryAssembly()" />.
/// </summary>
public Types InEntryAssembly()
=> In.EntryAssembly().Types().WithinNamespace(_namespace);

/// <summary>
/// Clarifies that the types within the namespace are searched in the
/// <see cref="Assembly.GetExecutingAssembly()" />.
/// </summary>
public Types InExecutingAssembly()
=> In.ExecutingAssembly().Types().WithinNamespace(_namespace);
private Types From(Assemblies assemblies)
=> assemblies.Types().WithinNamespace(_namespace);
}

/// <summary>
Expand Down
17 changes: 4 additions & 13 deletions Source/aweXpect.Reflection/In.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
namespace aweXpect.Reflection;

/// <summary>
/// Static entry point for assemblies.
/// Static entry point for selecting assemblies, types and members from concrete reflection objects.
/// </summary>
/// <remarks>
/// To select types <em>by criteria</em> (e.g. by namespace), use <see cref="aweXpect.Reflection.Types" /> instead.
/// </remarks>
public static class In
{
/// <summary>
Expand Down Expand Up @@ -50,18 +53,6 @@ public static Filtered.Assemblies AssemblyContaining<TType>()
public static Filtered.Assemblies AssemblyContaining(Type type)
=> new(type.Assembly, $"in assembly containing type {Formatter.Format(type)}");

/// <summary>
/// Defines expectations on the <see cref="Assembly.GetEntryAssembly()" />.
/// </summary>
public static Filtered.Assemblies EntryAssembly()
=> new(Assembly.GetEntryAssembly(), "in entry assembly");

/// <summary>
/// Defines expectations on the <see cref="Assembly.GetExecutingAssembly()" />.
/// </summary>
public static Filtered.Assemblies ExecutingAssembly()
=> new(Assembly.GetExecutingAssembly(), "in executing assembly");

/// <summary>
/// Defines expectations on the type <typeparamref name="TType" />.
/// </summary>
Expand Down
20 changes: 7 additions & 13 deletions Source/aweXpect.Reflection/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace aweXpect.Reflection;
/// <summary>
/// Static entry point for selecting types by criteria.
/// </summary>
/// <remarks>
/// The <c>In*</c> methods mirror the assembly sources on <see cref="In" /> (each is the corresponding
/// <c>In.*(…).Types()</c>) and are mirrored again as source clarifiers on
/// <see cref="Filtered.Types.InNamespaceResult" />. When adding a new assembly source, keep all three
/// surfaces in sync.
/// </remarks>
public static class Types
{
/// <summary>
Expand Down Expand Up @@ -40,18 +46,6 @@ public static Filtered.Types InAssemblyContaining<TType>()
public static Filtered.Types InAssemblyContaining(Type type)
=> In.AssemblyContaining(type).Types();

/// <summary>
/// Defines expectations on all types in the <see cref="Assembly.GetEntryAssembly()" />.
/// </summary>
public static Filtered.Types InEntryAssembly()
=> In.EntryAssembly().Types();

/// <summary>
/// Defines expectations on all types in the <see cref="Assembly.GetExecutingAssembly()" />.
/// </summary>
public static Filtered.Types InExecutingAssembly()
=> In.ExecutingAssembly().Types();

/// <summary>
/// Defines expectations on all types within the <paramref name="namespace" /> (including sub-namespaces).
/// </summary>
Expand All @@ -66,4 +60,4 @@ public static Filtered.Types InExecutingAssembly()
/// </remarks>
public static Filtered.Types.InNamespaceResult InNamespace(string @namespace)
=> new(@namespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable<System.Reflection.ConstructorInfo> constructors) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable<System.Reflection.EventInfo> events) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable<System.Reflection.FieldInfo> fields) { }
public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo> methods) { }
public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable<System.Reflection.PropertyInfo> properties) { }
Expand Down Expand Up @@ -2036,8 +2034,6 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types.InNamespaceResult InNamespace(string @namespace) { }
}
}
Expand Down Expand Up @@ -2213,8 +2209,6 @@ namespace aweXpect.Reflection.Collections
public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
}
public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable<System.Reflection.ConstructorInfo> constructors) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable<System.Reflection.EventInfo> events) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable<System.Reflection.FieldInfo> fields) { }
public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo> methods) { }
public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable<System.Reflection.PropertyInfo> properties) { }
Expand Down Expand Up @@ -2036,8 +2034,6 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types.InNamespaceResult InNamespace(string @namespace) { }
}
}
Expand Down Expand Up @@ -2213,8 +2209,6 @@ namespace aweXpect.Reflection.Collections
public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
}
public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies AssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable<System.Reflection.ConstructorInfo> constructors) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable<System.Reflection.EventInfo> events) { }
public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable<System.Reflection.FieldInfo> fields) { }
public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo> methods) { }
public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable<System.Reflection.PropertyInfo> properties) { }
Expand Down Expand Up @@ -1672,8 +1670,6 @@ namespace aweXpect.Reflection
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public static aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
public static aweXpect.Reflection.Collections.Filtered.Types.InNamespaceResult InNamespace(string @namespace) { }
}
}
Expand Down Expand Up @@ -1849,8 +1845,6 @@ namespace aweXpect.Reflection.Collections
public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable<System.Reflection.Assembly?> assemblies) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { }
public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining<TType>() { }
public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { }
public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { }
}
public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types
{
Expand Down
28 changes: 0 additions & 28 deletions Tests/aweXpect.Reflection.Tests/InTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,6 @@ public async Task Constructors_WithEnumerable_ShouldContainProvidedConstructors(
await That(sut.GetDescription()).IsEqualTo("in the constructors ").AsPrefix();
}

[Fact]
public async Task EntryAssembly_ShouldContainExpectedAssembly()
{
Assembly? expectedAssembly = Assembly.GetEntryAssembly();

Filtered.Assemblies sut = In.EntryAssembly();

#if NET8_0_OR_GREATER
await That(sut).HasSingle().Which
.IsEqualTo(expectedAssembly);
#else
await That(sut).IsEmpty();
#endif
await That(sut.GetDescription()).IsEqualTo("in entry assembly");
}

[Fact]
public async Task Events_WithEnumerable_ShouldContainProvidedEvents()
{
Expand All @@ -111,18 +95,6 @@ public async Task Events_WithEnumerable_ShouldContainProvidedEvents()
await That(sut.GetDescription()).IsEqualTo("in the events ").AsPrefix();
}

[Fact]
public async Task ExecutingAssembly_ShouldContainExpectedAssembly()
{
Assembly expectedAssembly = typeof(In).Assembly;

Filtered.Assemblies sut = In.ExecutingAssembly();

await That(sut).HasSingle().Which
.IsEqualTo(expectedAssembly);
await That(sut.GetDescription()).IsEqualTo("in executing assembly");
}

[Fact]
public async Task Fields_ShouldExcludeCompilerGeneratedBackingFields()
{
Expand Down
38 changes: 0 additions & 38 deletions Tests/aweXpect.Reflection.Tests/TypesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ public async Task InAssemblyContaining_WithType_ShouldContainTypesFromAssemblyOf
await That(sut.GetDescription()).IsEqualTo("types in assembly containing type In");
}

[Fact]
public async Task InEntryAssembly_ShouldUseEntryAssemblyAsSource()
{
Filtered.Types sut = Types.InEntryAssembly();

await That(sut).DoesNotContain(typeof(TypesTests));
await That(sut.GetDescription()).IsEqualTo("types in entry assembly");
}

[Fact]
public async Task InExecutingAssembly_ShouldContainTypesFromExecutingAssembly()
{
Filtered.Types sut = Types.InExecutingAssembly();

await That(sut).Contains(typeof(In));
await That(sut.GetDescription()).IsEqualTo("types in executing assembly");
}

[Fact]
public async Task InNamespace_ShouldContainTypesWithinNamespaceIncludingSubNamespaces()
{
Expand Down Expand Up @@ -196,26 +178,6 @@ await That(sut.GetDescription())
.IsEqualTo($"types within namespace \"{NamespaceScope}\" in assembly containing type In");
}

[Fact]
public async Task InNamespace_InEntryAssembly_ShouldUseEntryAssemblyAsSource()
{
Filtered.Types sut = Types.InNamespace(NamespaceScope).InEntryAssembly();

await That(sut).IsEmpty();
await That(sut.GetDescription())
.IsEqualTo($"types within namespace \"{NamespaceScope}\" in entry assembly");
}

[Fact]
public async Task InNamespace_InExecutingAssembly_ShouldUseExecutingAssemblyAsSource()
{
Filtered.Types sut = Types.InNamespace(NamespaceScope).InExecutingAssembly();

await That(sut).IsEmpty();
await That(sut.GetDescription())
.IsEqualTo($"types within namespace \"{NamespaceScope}\" in executing assembly");
}

[Fact]
public async Task InNamespace_AfterClarification_OriginalShouldStillUseAllLoadedAssemblies()
{
Expand Down
Loading