Skip to content

Commit a6a49ec

Browse files
committed
add TestResult.LoadedTypes and TestResult.SelectedTypesForTesting
1 parent 9e69647 commit a6a49ec

File tree

7 files changed

+54
-54
lines changed

7 files changed

+54
-54
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@ public class SampleApp_ModuleOmega_Tests
127127

128128
The fluent API should direct you in building up a rule, based on a combination of [predicates](documentation/api.md#predicate), [conditions](documentation/api.md#condition) and conjunctions.
129129

130-
The starting point for any rule is the static [`Types`](documentation/api.md#types) class, where you load a set of types from a path, assembly.
130+
The starting point for any rule is the static [`Types`](documentation/api.md#types) class, where you load a set of types from a assembly, domain or patth.
131131

132132
```csharp
133133
var types = Types.InAssembly(typeof(MyClass).Assembly);
134134
```
135-
Once you have selected the types you can filter them using one or more predicates. These can be chained together using `And()` or `Or()` conjunctions:
135+
Once you have loaded the types, you can filter them using one or more predicates. These can be chained together using `And()` or `Or()` conjunctions:
136136
```csharp
137137
types.That().ResideInNamespace("MyProject.Data");
138138
```
139-
Once the set of classes have been filtered you can apply a set of conditions using the `Should()` or `ShouldNot()` methods, e.g.
139+
Once the set of types have been filtered, you can apply a set of conditions using the `Should()` or `ShouldNot()` methods, e.g.
140140
```csharp
141141
types.That().ResideInNamespace("MyProject.Data").Should().BeSealed();
142142
```

documentation/readme.nt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ The library is available as a package on NuGet: [NetArchTest.eNhancedEdition](ht
7878

7979
The fluent API should direct you in building up a rule, based on a combination of [predicates](documentation/api.md#predicate), [conditions](documentation/api.md#condition) and conjunctions.
8080

81-
The starting point for any rule is the static [`Types`](documentation/api.md#types) class, where you load a set of types from a path, assembly.
81+
The starting point for any rule is the static [`Types`](documentation/api.md#types) class, where you load a set of types from a assembly, domain or patth.
8282

8383
```csharp
8484
var types = Types.InAssembly(typeof(MyClass).Assembly);
8585
```
86-
Once you have selected the types you can filter them using one or more predicates. These can be chained together using `And()` or `Or()` conjunctions:
86+
Once you have loaded the types, you can filter them using one or more predicates. These can be chained together using `And()` or `Or()` conjunctions:
8787
```csharp
8888
types.That().ResideInNamespace("MyProject.Data");
8989
```
90-
Once the set of classes have been filtered you can apply a set of conditions using the `Should()` or `ShouldNot()` methods, e.g.
90+
Once the set of types have been filtered, you can apply a set of conditions using the `Should()` or `ShouldNot()` methods, e.g.
9191
```csharp
9292
types.That().ResideInNamespace("MyProject.Data").Should().BeSealed();
9393
```

sources/NetArchTest/IType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public interface IType
3030
/// </summary>
3131
string Explanation { get; }
3232

33-
3433
/// <summary>
3534
/// Path to the source file where type is defined.
3635
/// </summary>

sources/NetArchTest/RuleEngine/FunctionSequence.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public void CreateGroup()
2929
}
3030

3131

32-
public IEnumerable<TypeSpec> ExecuteToGetFailingTypes(IEnumerable<TypeSpec> inputTypes, bool selected, Options options, IEnumerable<TypeSpec> allTypes)
32+
public IReadOnlyList<TypeSpec> ExecuteToGetFailingTypes(IReadOnlyList<TypeSpec> inputTypes, bool selected, Options options, IEnumerable<TypeSpec> allTypes)
3333
{
3434
return Execute(inputTypes, selected, true, options, allTypes);
3535
}
36-
public IEnumerable<TypeSpec> Execute(IEnumerable<TypeSpec> inputTypes, Options options, IEnumerable<TypeSpec> allTypes)
36+
public IReadOnlyList<TypeSpec> Execute(IReadOnlyList<TypeSpec> inputTypes, Options options, IEnumerable<TypeSpec> allTypes)
3737
{
3838
return Execute(inputTypes, true, false, options, allTypes);
3939
}
4040

41-
private IEnumerable<TypeSpec> Execute(IEnumerable<TypeSpec> inputTypes, bool selected, bool isFailPathRun, Options options, IEnumerable<TypeSpec> allTypes)
41+
private IReadOnlyList<TypeSpec> Execute(IReadOnlyList<TypeSpec> inputTypes, bool selected, bool isFailPathRun, Options options, IEnumerable<TypeSpec> allTypes)
4242
{
4343
if (isEmpty) return inputTypes;
4444

sources/NetArchTest/RuleEngine/RuleContext.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ namespace NetArchTest.RuleEngine
99
{
1010
internal class RuleContext
1111
{
12-
private readonly IReadOnlyList<TypeSpec> types;
12+
private readonly IReadOnlyList<TypeSpec> lodedTypes;
1313
public PredicateContext PredicateContext { get; } = new PredicateContext();
1414
public ConditionContext ConditionContext { get; } = new ConditionContext();
1515

1616

1717
public RuleContext(IEnumerable<TypeSpec> inpuTypes)
1818
{
19-
types = inpuTypes.ToArray();
19+
lodedTypes = inpuTypes.ToArray();
2020
}
2121

2222

2323
public IEnumerable<TypeSpec> Execute(Options options)
2424
{
25-
IEnumerable<TypeSpec> result = types;
26-
result = PredicateContext.Sequence.Execute(result, options, types);
27-
result = ConditionContext.Sequence.Execute(result, options, types);
25+
var result = lodedTypes;
26+
result = PredicateContext.Sequence.Execute(result, options, lodedTypes);
27+
result = ConditionContext.Sequence.Execute(result, options, lodedTypes);
2828
return result;
2929
}
3030

3131
public TestResult GetResult(Options options)
3232
{
3333
bool success;
3434

35-
var filteredTypes = PredicateContext.Sequence.Execute(types, options, types);
36-
var passingTypes = ConditionContext.Sequence.Execute(filteredTypes, options, types);
35+
var filteredTypes = PredicateContext.Sequence.Execute(lodedTypes, options, lodedTypes);
36+
var passingTypes = ConditionContext.Sequence.Execute(filteredTypes, options, lodedTypes);
3737

3838
if (ConditionContext.Should)
3939
{
@@ -48,12 +48,12 @@ public TestResult GetResult(Options options)
4848

4949
if (success)
5050
{
51-
return TestResult.Success();
51+
return new TestResult(lodedTypes, filteredTypes, Array.Empty<TypeSpec>(), true);
5252
}
5353

5454
// If we've failed, get a collection of failing types so these can be reported in a failing test.
55-
var failedTypes = ConditionContext.Sequence.ExecuteToGetFailingTypes(filteredTypes, selected: !ConditionContext.Should, options, types);
56-
return TestResult.Failure(failedTypes);
55+
var failedTypes = ConditionContext.Sequence.ExecuteToGetFailingTypes(filteredTypes, selected: !ConditionContext.Should, options, lodedTypes);
56+
return new TestResult(lodedTypes, filteredTypes, failedTypes, false);
5757
}
5858

5959

sources/NetArchTest/Slices/SliceConditionList.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using NetArchTest.Assemblies;
34
using NetArchTest.Rules;
45
using NetArchTest.Slices.Model;
56

@@ -42,12 +43,13 @@ public TestResult GetResult()
4243

4344
if (isSuccessful)
4445
{
45-
return TestResult.Success();
46+
// todo replace Array.Empty<TypeSpec>() with real data
47+
return new TestResult(Array.Empty<TypeSpec>(), Array.Empty<TypeSpec>(), Array.Empty<TypeSpec>(), true);
4648
}
4749
else
4850
{
4951
var failingTypes = filteredTypes.Where(x => x.IsPassing == !successIsWhen);
50-
return TestResult.Failure(failingTypes.Select(x => x.TypeSpec));
52+
return new TestResult(Array.Empty<TypeSpec>(), Array.Empty<TypeSpec>(), failingTypes.Select(x => x.TypeSpec), false);
5153
}
5254
}
5355
}

sources/NetArchTest/TestResult.cs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ namespace NetArchTest.Rules
99
/// <summary>
1010
/// Defines a result from a test carried out on a <see cref="ConditionList"/>.
1111
/// </summary>
12-
[DebuggerDisplay("FailingTypes = {FailingTypes.Count}")]
12+
[DebuggerDisplay("LoadedTypes = {LoadedTypes.Count}, SelectedTypesForTesting = {SelectedTypesForTesting.Count}, FailingTypes = {FailingTypes.Count}")]
1313
public sealed class TestResult
14-
{
15-
private TestResult()
14+
{
15+
//private readonly IEnumerable<TypeSpec> loadedTypes;
16+
//private readonly IEnumerable<TypeSpec> selectedTypes;
17+
//private readonly IEnumerable<TypeSpec> failingTypes;
18+
19+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
20+
private readonly Lazy<IReadOnlyList<IType>> lazyLoadedTypes;
21+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
22+
private readonly Lazy<IReadOnlyList<IType>> lazySelectedTypes;
23+
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
24+
private readonly Lazy<IReadOnlyList<IType>> lazyFailingTypes;
25+
26+
27+
internal TestResult(IEnumerable<TypeSpec> loadedTypes, IEnumerable<TypeSpec> selectedTypes, IEnumerable<TypeSpec> failingTypes, bool isSuccessful)
1628
{
29+
lazyLoadedTypes = new Lazy<IReadOnlyList<IType>>(() => loadedTypes.Select(x => x.CreateWrapper()).ToArray());
30+
lazySelectedTypes = new Lazy<IReadOnlyList<IType>>(() => selectedTypes.Select(x => x.CreateWrapper()).ToArray());
31+
lazyFailingTypes = new Lazy<IReadOnlyList<IType>>(() => failingTypes.Select(x => x.CreateWrapper()).ToArray());
32+
IsSuccessful = isSuccessful;
1733
}
1834

1935

@@ -23,38 +39,21 @@ private TestResult()
2339
public bool IsSuccessful { get; private set; }
2440

2541
/// <summary>
26-
/// Gets a list of the types that failed the test.
27-
/// </summary>
28-
/// <remarks>
29-
/// This method loads all the types and may throw dependency loading errors if the test project does not have a direct dependency on the type being loaded.
30-
/// </remarks>
31-
[DebuggerDisplay("[{FailingTypes.Count}]")]
32-
public IReadOnlyList<IType> FailingTypes { get; private set; } = Array.Empty<IType>();
33-
42+
/// Gets a list of all the types that were loded by <see cref="Types"/>.
43+
/// </summary>
44+
[DebuggerDisplay("[{LoadedTypes.Count}]")]
45+
public IReadOnlyList<IType> LoadedTypes => lazyLoadedTypes.Value;
3446

3547
/// <summary>
36-
/// Creates a new instance of <see cref="TestResult"/> indicating a successful test.
37-
/// </summary>
38-
/// <returns>Instance of <see cref="TestResult"/></returns>
39-
internal static TestResult Success()
40-
{
41-
return new TestResult
42-
{
43-
IsSuccessful = true
44-
};
45-
}
48+
/// Gets a list of the types that passed filtering by predicates and were used as input to conditions.
49+
/// </summary>
50+
[DebuggerDisplay("[{SelectedTypesForTesting.Count}]")]
51+
public IReadOnlyList<IType> SelectedTypesForTesting => lazySelectedTypes.Value;
4652

4753
/// <summary>
48-
/// Creates a new instance of <see cref="TestResult"/> indicating a failed test.
49-
/// </summary>
50-
/// <returns>Instance of <see cref="TestResult"/></returns>
51-
internal static TestResult Failure(IEnumerable<TypeSpec> failingTypes)
52-
{
53-
return new TestResult
54-
{
55-
IsSuccessful = false,
56-
FailingTypes = failingTypes.Select(x => x.CreateWrapper()).ToArray()
57-
};
58-
}
54+
/// Gets a list of the types that failed the test.
55+
/// </summary>
56+
[DebuggerDisplay("[{FailingTypes.Count}]")]
57+
public IReadOnlyList<IType> FailingTypes => lazyFailingTypes.Value;
5958
}
6059
}

0 commit comments

Comments
 (0)