Skip to content

Commit f0c1cac

Browse files
committed
add TestResult.LoadedAssemblies
1 parent ca4af1e commit f0c1cac

19 files changed

+190
-76
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ var types = result.FailingTypes;
156156
```
157157

158158
> **Tip**
159-
Loading types is time time-consuming, since `Type` class is immutable, it can be shared between tests.
159+
Loading types is time-consuming, since `Type` class is immutable, its instance can be shared between tests.
160160

161161
## Rules for dependency analysis
162162

documentation/api.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* [AreSealed](#PredicateAreSealed)
5555
* [AreStateless](#PredicateAreStateless)
5656
* [AreStatic](#PredicateAreStatic)
57+
* [AreStaticless](#PredicateAreStaticless)
5758
* [AreStructures](#PredicateAreStructures)
5859
* [AreUsedByAny](#PredicateAreUsedByAny)
5960
* [DoNotHaveCustomAttribute](#PredicateDoNotHaveCustomAttribute)
@@ -131,6 +132,7 @@
131132
* [BeSealed](#ConditionBeSealed)
132133
* [BeStateless](#ConditionBeStateless)
133134
* [BeStatic](#ConditionBeStatic)
135+
* [BeStaticless](#ConditionBeStaticless)
134136
* [BeStructures](#ConditionBeStructures)
135137
* [BeUsedByAny](#ConditionBeUsedByAny)
136138
* [HaveCustomAttribute](#ConditionHaveCustomAttribute)
@@ -209,6 +211,7 @@
209211

210212
* [FailingTypes](#TestResultFailingTypes)
211213
* [IsSuccessful](#TestResultIsSuccessful)
214+
* [LoadedAssemblies](#TestResultLoadedAssemblies)
212215
* [LoadedTypes](#TestResultLoadedTypes)
213216
* [SelectedTypesForTesting](#TestResultSelectedTypesForTesting)
214217

@@ -220,14 +223,18 @@
220223
* [ReflectionType](#ITypeReflectionType)
221224
* [SourceFilePath](#ITypeSourceFilePath)
222225

226+
## IAssembly
227+
228+
* [FullName](#IAssemblyFullName)
229+
223230
## Options
224231

225232
* [Comparer](#OptionsComparer)
226233

227234
## Types
228235
### Types.FromFile
229236
```csharp
230-
Types Types.FromFile(string fileName)
237+
Types Types.FromFile(string fileName, IEnumerable<string> searchDirectories = null)
231238
```
232239
Creates a list of all the types in a particular module file.
233240
### Types.FromPath
@@ -477,6 +484,11 @@ Selects types that are stateless, they do not have instance state
477484
PredicateList Predicate.AreStatic()
478485
```
479486
Selects types that are static.
487+
### Predicate.AreStaticless
488+
```csharp
489+
PredicateList Predicate.AreStaticless()
490+
```
491+
Selects types that are staticless, they do not have static state
480492
### Predicate.AreStructures
481493
```csharp
482494
PredicateList Predicate.AreStructures()
@@ -836,6 +848,11 @@ Selects types that are stateless, they do not have instance state
836848
ConditionList Condition.BeStatic()
837849
```
838850
Selects types that are static.
851+
### Condition.BeStaticless
852+
```csharp
853+
ConditionList Condition.BeStaticless()
854+
```
855+
Selects types that are staticless, they do not have static state
839856
### Condition.BeStructures
840857
```csharp
841858
ConditionList Condition.BeStructures()
@@ -1200,6 +1217,11 @@ Gets a list of the types that failed the test.
12001217
IsSuccessful
12011218
```
12021219
Gets a flag indicating the success or failure of the test.
1220+
### TestResult.LoadedAssemblies
1221+
```csharp
1222+
LoadedAssemblies
1223+
```
1224+
Gets a list of all the assemblies that were loded by <see cref="T:NetArchTest.Rules.Types"/>.
12031225
### TestResult.LoadedTypes
12041226
```csharp
12051227
LoadedTypes
@@ -1238,6 +1260,13 @@ SourceFilePath
12381260
```
12391261
Path to the source file where type is defined.
12401262

1263+
## IAssembly
1264+
### IAssembly.FullName
1265+
```csharp
1266+
FullName
1267+
```
1268+
FullName of the assembly
1269+
12411270
## Options
12421271
### Options.Comparer
12431272
```csharp

documentation/api.nt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ capture output
55
condition_type = data.Classes | Symbols.WhereNamespaceStartsWith "NetArchTest.Rules" | Symbols.WhereNameMatches "^Condition"
66
testresult_type = data.Classes | Symbols.WhereNamespaceStartsWith "NetArchTest.Rules" | Symbols.WhereNameMatches "^TestResult"
77
itype_type = data.Interfaces | Symbols.WhereNamespaceStartsWith "NetArchTest.Rules" | Symbols.WhereNameMatches "^IType"
8+
iassembly_type = data.Interfaces | Symbols.WhereNamespaceStartsWith "NetArchTest.Rules" | Symbols.WhereNameMatches "^IAssembly"
89
options_type = data.Classes | Symbols.WhereNamespaceStartsWith "NetArchTest.Rules" | Symbols.WhereNameMatches "^Options"
910

10-
all_types = types_type | Array.Concat predicate_type | Array.Concat condition_type | Array.Concat testresult_type | Array.Concat itype_type | Array.Concat options_type
11+
all_types = types_type | Array.Concat predicate_type | Array.Concat condition_type | Array.Concat testresult_type | Array.Concat itype_type | Array.Concat iassembly_type | Array.Concat options_type
1112
}}
1213

1314

documentation/readme.nt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var types = result.FailingTypes;
107107
```
108108

109109
> **Tip**
110-
Loading types is time time-consuming, since `Type` class is immutable, it can be shared between tests.
110+
Loading types is time-consuming, since `Type` class is immutable, its instance can be shared between tests.
111111

112112
## Rules for dependency analysis
113113

sources/NetArchTest/Assemblies/AssemblySpec.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using Mono.Cecil;
4+
using NetArchTest.Assemblies.PublicUse;
5+
using NetArchTest.Rules;
46

57
namespace NetArchTest.Assemblies
68
{
@@ -21,5 +23,11 @@ public IEnumerable<TypeSpec> GetTypes()
2123
{
2224
return typeDefinitions.Select(x => new TypeSpec(x));
2325
}
26+
27+
28+
public IAssembly CreateWrapper()
29+
{
30+
return new AssemblyContainer(assemblyDefinition);
31+
}
2432
}
2533
}

sources/NetArchTest/Assemblies/DataLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static IEnumerable<AssemblySpec> Load(IEnumerable<string> fileNames, IEn
6161
var assemblyDefinition = ReadAssemblyDefinition(fileName, readerParameters);
6262
if (assemblyDefinition == null) continue;
6363

64-
if (exclusionTree.GetAllMatchingNames(assemblyDefinition.FullName).Any() == true) continue;
64+
if (exclusionTree.GetAllMatchingNames(assemblyDefinition.Name.Name).Any() == true) continue;
6565

6666
var typeDefinitions = ReadTypes(assemblyDefinition);
6767

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Diagnostics;
2+
using Mono.Cecil;
3+
using NetArchTest.Rules;
4+
5+
namespace NetArchTest.Assemblies.PublicUse
6+
{
7+
[DebuggerDisplay("{FullName}")]
8+
internal sealed class AssemblyContainer : IAssembly
9+
{
10+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
11+
private readonly AssemblyDefinition _monoAssemblyDefinition;
12+
13+
14+
public string FullName => _monoAssemblyDefinition.FullName;
15+
16+
17+
public AssemblyContainer(AssemblyDefinition assemblyDefinition)
18+
{
19+
_monoAssemblyDefinition = assemblyDefinition;
20+
}
21+
}
22+
}

sources/NetArchTest/Assemblies/TypeContainer.cs renamed to sources/NetArchTest/Assemblies/PublicUse/TypeContainer.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Mono.Cecil;
44
using NetArchTest.Rules;
55

6-
namespace NetArchTest.Assemblies
6+
namespace NetArchTest.Assemblies.PublicUse
77
{
88
[DebuggerDisplay("{FullName}")]
99
internal sealed class TypeContainer : IType
@@ -16,33 +16,33 @@ internal sealed class TypeContainer : IType
1616
private readonly Lazy<string> _sourceFilePath;
1717

1818

19+
public Type ReflectionType => _reflactionType.Value;
20+
public string FullName => _monoTypeDefinition.FullName;
21+
public string Name => _monoTypeDefinition.Name;
22+
public string Explanation { get; }
23+
public string SourceFilePath => _sourceFilePath.Value;
24+
25+
1926
internal TypeContainer(TypeDefinition monoTypeDefinition, string explanation)
2027
{
2128
_monoTypeDefinition = monoTypeDefinition;
2229
_reflactionType = new Lazy<Type>(() =>
23-
{
30+
{
2431
try
2532
{
2633
return _monoTypeDefinition.ToType();
2734
}
28-
catch
29-
{
35+
catch
36+
{
3037
}
3138
return null;
3239
});
3340
_sourceFilePath = new Lazy<string>(() => _monoTypeDefinition.GetFilePath());
3441
Explanation = explanation;
35-
}
36-
37-
38-
public Type ReflectionType => _reflactionType.Value;
39-
public string FullName => _monoTypeDefinition.FullName;
40-
public string Name => _monoTypeDefinition.Name;
41-
public string Explanation { get; }
42-
public string SourceFilePath => _sourceFilePath.Value;
42+
}
4343

4444

45-
public static implicit operator System.Type(TypeContainer type)
45+
public static implicit operator Type(TypeContainer type)
4646
{
4747
return type.ReflectionType;
4848
}

sources/NetArchTest/Assemblies/TypeSpec.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using Mono.Cecil;
4+
using NetArchTest.Assemblies.PublicUse;
45

56
namespace NetArchTest.Assemblies
67
{

sources/NetArchTest/IAssembly.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace NetArchTest.Rules
6+
{
7+
/// <summary>
8+
/// Assembly wrapper.
9+
/// </summary>
10+
public interface IAssembly
11+
{
12+
/// <summary>
13+
/// FullName of the assembly
14+
/// </summary>
15+
string FullName { get; }
16+
}
17+
}

0 commit comments

Comments
 (0)