diff --git a/README.md b/README.md index 4d4d14b1..ff189c21 100644 --- a/README.md +++ b/README.md @@ -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()` / `In.AssemblyContaining(typeof(T))` | the assembly that declares `T` | -| `In.EntryAssembly()` | the entry assembly | -| `In.ExecutingAssembly()` | the executing assembly | | `In.Type()` / `In.Type(typeof(T))` | a single type | | `In.Types()` / `In.Types()` / `In.Types(t1, t2, …)` | the given types | | `In.Constructors(…)` / `In.Events(…)` / `In.Fields(…)` / `In.Methods(…)` / `In.Properties(…)` | the given members | @@ -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()` / `…(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): diff --git a/Source/aweXpect.Reflection/Collections/Filtered.Types.cs b/Source/aweXpect.Reflection/Collections/Filtered.Types.cs index 0b3c5a89..4d01b646 100644 --- a/Source/aweXpect.Reflection/Collections/Filtered.Types.cs +++ b/Source/aweXpect.Reflection/Collections/Filtered.Types.cs @@ -507,41 +507,30 @@ internal InNamespaceResult(string @namespace) /// current (the default). /// public Types InAllLoadedAssemblies() - => In.AllLoadedAssemblies().Types().WithinNamespace(_namespace); + => From(In.AllLoadedAssemblies()); /// /// Clarifies that the types within the namespace are searched in the given . /// public Types InAssemblies(params IEnumerable assemblies) - => new Assemblies(assemblies, $"in the assemblies {Formatter.Format(assemblies)}").Types() - .WithinNamespace(_namespace); + => From(In.Assemblies(assemblies)); /// /// Clarifies that the types within the namespace are searched in the assembly that contains /// the . /// public Types InAssemblyContaining() - => In.AssemblyContaining().Types().WithinNamespace(_namespace); + => From(In.AssemblyContaining()); /// /// Clarifies that the types within the namespace are searched in the assembly that contains /// the . /// public Types InAssemblyContaining(Type type) - => In.AssemblyContaining(type).Types().WithinNamespace(_namespace); + => From(In.AssemblyContaining(type)); - /// - /// Clarifies that the types within the namespace are searched in the . - /// - public Types InEntryAssembly() - => In.EntryAssembly().Types().WithinNamespace(_namespace); - - /// - /// Clarifies that the types within the namespace are searched in the - /// . - /// - public Types InExecutingAssembly() - => In.ExecutingAssembly().Types().WithinNamespace(_namespace); + private Types From(Assemblies assemblies) + => assemblies.Types().WithinNamespace(_namespace); } /// diff --git a/Source/aweXpect.Reflection/In.cs b/Source/aweXpect.Reflection/In.cs index a4914912..ba30365c 100644 --- a/Source/aweXpect.Reflection/In.cs +++ b/Source/aweXpect.Reflection/In.cs @@ -11,8 +11,11 @@ namespace aweXpect.Reflection; /// -/// Static entry point for assemblies. +/// Static entry point for selecting assemblies, types and members from concrete reflection objects. /// +/// +/// To select types by criteria (e.g. by namespace), use instead. +/// public static class In { /// @@ -50,18 +53,6 @@ public static Filtered.Assemblies AssemblyContaining() public static Filtered.Assemblies AssemblyContaining(Type type) => new(type.Assembly, $"in assembly containing type {Formatter.Format(type)}"); - /// - /// Defines expectations on the . - /// - public static Filtered.Assemblies EntryAssembly() - => new(Assembly.GetEntryAssembly(), "in entry assembly"); - - /// - /// Defines expectations on the . - /// - public static Filtered.Assemblies ExecutingAssembly() - => new(Assembly.GetExecutingAssembly(), "in executing assembly"); - /// /// Defines expectations on the type . /// diff --git a/Source/aweXpect.Reflection/Types.cs b/Source/aweXpect.Reflection/Types.cs index c4631d41..9b277302 100644 --- a/Source/aweXpect.Reflection/Types.cs +++ b/Source/aweXpect.Reflection/Types.cs @@ -8,6 +8,12 @@ namespace aweXpect.Reflection; /// /// Static entry point for selecting types by criteria. /// +/// +/// The In* methods mirror the assembly sources on (each is the corresponding +/// In.*(…).Types()) and are mirrored again as source clarifiers on +/// . When adding a new assembly source, keep all three +/// surfaces in sync. +/// public static class Types { /// @@ -40,18 +46,6 @@ public static Filtered.Types InAssemblyContaining() public static Filtered.Types InAssemblyContaining(Type type) => In.AssemblyContaining(type).Types(); - /// - /// Defines expectations on all types in the . - /// - public static Filtered.Types InEntryAssembly() - => In.EntryAssembly().Types(); - - /// - /// Defines expectations on all types in the . - /// - public static Filtered.Types InExecutingAssembly() - => In.ExecutingAssembly().Types(); - /// /// Defines expectations on all types within the (including sub-namespaces). /// @@ -66,4 +60,4 @@ public static Filtered.Types InExecutingAssembly() /// public static Filtered.Types.InNamespaceResult InNamespace(string @namespace) => new(@namespace); -} \ No newline at end of file +} diff --git a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net10.0.txt b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net10.0.txt index 99151c76..0fb6bc8d 100644 --- a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net10.0.txt +++ b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net10.0.txt @@ -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() { } public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable constructors) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable events) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable fields) { } public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable methods) { } public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable properties) { } @@ -2036,8 +2034,6 @@ namespace aweXpect.Reflection public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - 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) { } } } @@ -2213,8 +2209,6 @@ namespace aweXpect.Reflection.Collections public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { } - public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { } } public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types { diff --git a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net8.0.txt b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net8.0.txt index 28c2442d..245bf366 100644 --- a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net8.0.txt +++ b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_net8.0.txt @@ -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() { } public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable constructors) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable events) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable fields) { } public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable methods) { } public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable properties) { } @@ -2036,8 +2034,6 @@ namespace aweXpect.Reflection public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - 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) { } } } @@ -2213,8 +2209,6 @@ namespace aweXpect.Reflection.Collections public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { } - public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { } } public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types { diff --git a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_netstandard2.0.txt b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_netstandard2.0.txt index 0126d718..617fb73a 100644 --- a/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_netstandard2.0.txt +++ b/Tests/aweXpect.Reflection.Api.Tests/Expected/aweXpect.Reflection_netstandard2.0.txt @@ -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() { } public static aweXpect.Reflection.Collections.Filtered.Constructors Constructors(System.Collections.Generic.IEnumerable constructors) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies EntryAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Events Events(System.Collections.Generic.IEnumerable events) { } - public static aweXpect.Reflection.Collections.Filtered.Assemblies ExecutingAssembly() { } public static aweXpect.Reflection.Collections.Filtered.Fields Fields(System.Collections.Generic.IEnumerable fields) { } public static aweXpect.Reflection.Collections.Filtered.Methods Methods(System.Collections.Generic.IEnumerable methods) { } public static aweXpect.Reflection.Collections.Filtered.Properties Properties(System.Collections.Generic.IEnumerable properties) { } @@ -1672,8 +1670,6 @@ namespace aweXpect.Reflection public static aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public static aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - 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) { } } } @@ -1849,8 +1845,6 @@ namespace aweXpect.Reflection.Collections public aweXpect.Reflection.Collections.Filtered.Types InAssemblies(System.Collections.Generic.IEnumerable assemblies) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining(System.Type type) { } public aweXpect.Reflection.Collections.Filtered.Types InAssemblyContaining() { } - public aweXpect.Reflection.Collections.Filtered.Types InEntryAssembly() { } - public aweXpect.Reflection.Collections.Filtered.Types InExecutingAssembly() { } } public sealed class NamespaceDependencyFilterResult : aweXpect.Reflection.Collections.Filtered.Types { diff --git a/Tests/aweXpect.Reflection.Tests/InTests.cs b/Tests/aweXpect.Reflection.Tests/InTests.cs index 07f7e463..e3977ff0 100644 --- a/Tests/aweXpect.Reflection.Tests/InTests.cs +++ b/Tests/aweXpect.Reflection.Tests/InTests.cs @@ -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() { @@ -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() { diff --git a/Tests/aweXpect.Reflection.Tests/TypesTests.cs b/Tests/aweXpect.Reflection.Tests/TypesTests.cs index 67305687..ac436db3 100644 --- a/Tests/aweXpect.Reflection.Tests/TypesTests.cs +++ b/Tests/aweXpect.Reflection.Tests/TypesTests.cs @@ -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() { @@ -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() {