Skip to content

Commit 5d08ed9

Browse files
committed
update readme
1 parent ef62a15 commit 5d08ed9

2 files changed

Lines changed: 25 additions & 60 deletions

File tree

README.md

Lines changed: 24 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# NetArchTest.eNhancedEdition
22

3-
A fluent API for .Net Standard that can enforce architectural rules in unit tests.
3+
A fluent API for .Net Standard that can enforce architectural rules in unit tests and create a *self-testing architecture*. Inspired by the [ArchUnit](https://www.archunit.org/) library for Java.
44

5-
Inspired by the [ArchUnit](https://www.archunit.org/) library for Java.
5+
NetArchTest.eNhancedEdition is based on [NetArchTest v1.3.2](https://github.com/BenMorris/NetArchTest). If you are not familiar with NetArchTest, you should start by reading [introduction on Ben's blog](https://www.ben-morris.com/writing-archunit-style-tests-for-net-and-c-for-self-testing-architectures).
66

77
## Rationale
88

9-
This project allows you create tests that enforce conventions for class design, naming and dependency in .Net code bases. These can be used with any unit test framework and incorporated into a build pipeline. It uses a fluid API that allows you to string together readable rules that can be used in test assertions.
109

11-
There are plenty of static analysis tools that can evaluate application structure, but they are aimed more at enforcing generic best practice rather than application-specific conventions. The better tools in this space can be press-ganged into creating custom rules for a specific architecture, but the intention here is to incorporate rules into a test suite and create a *self-testing architecture*.
1210

13-
The project is inspired by [ArchUnit](https://www.archunit.org/), a java-based library that attempts to address the difficulties of preserving architectural design patterns in code bases over the long term. Many patterns can only be enforced by convention, which tends to rely on a rigorous and consistent process of code review. This discipline often breaks down as projects grow, use cases become more complex and developers come and go.
11+
## Getting started
12+
13+
The library is available as a package on NuGet: [NetArchTest.eNhancedEdition](https://www.nuget.org/packages/NetArchTest.eNhancedEdition/).
1414

1515
## Examples
1616

@@ -20,33 +20,23 @@ var result = Types.InCurrentDomain()
2020
.That()
2121
.ResideInNamespace("NetArchTest.SampleLibrary.Presentation")
2222
.ShouldNot()
23-
.HaveDependencyOn("NetArchTest.SampleLibrary.Data")
24-
.GetResult()
25-
.IsSuccessful;
26-
27-
// Classes in the "data" namespace should implement IRepository
28-
result = Types.InCurrentDomain()
29-
.That().HaveDependencyOn("System.Data")
30-
.And().ResideInNamespace(("ArchTest"))
31-
.Should().ResideInNamespace(("NetArchTest.SampleLibrary.Data"))
23+
.HaveDependencyOnAny("NetArchTest.SampleLibrary.Data")
3224
.GetResult()
3325
.IsSuccessful;
3426

3527
// All the service classes should be sealed
36-
result = Types.InCurrentDomain()
37-
.That().ImplementInterface(typeof(IWidgetService))
38-
.Should().BeSealed()
28+
var result = Types.InCurrentDomain()
29+
.That()
30+
.ImplementInterface(typeof(IWidgetService))
31+
.Should()
32+
.BeSealed()
3933
.GetResult()
4034
.IsSuccessful;
4135
```
4236

43-
## Getting started
44-
45-
The main rules library is available as a package on NuGet: [NetArchTest.Rules](https://www.nuget.org/packages/NetArchTest.Rules/).
4637

47-
It is a .Net Standard 2.0 library that is compatible with .Net Framework 4.6.1 or better and .Net Core 2.0 or better.
4838

49-
### Writing rules
39+
## Writing rules
5040

5141
The fluent API should direct you in building up a rule based on a combination of predicates, conditions and conjunctions.
5242

@@ -68,49 +58,24 @@ Finally, you obtain a result from the rule by using an executor, i.e. use `GetTy
6858
var isValid = types.That().ResideInNamespace(“MyProject.Data”).Should().BeSealed().GetResult().IsSuccessful;
6959
```
7060

71-
### Custom rules
61+
62+
## Dependencies
63+
64+
## Slices
65+
66+
## Custom rules
7267

7368
You can extend the library by writing custom rules that implement the `ICustomRule` interface. These can be applied as both predicates and conditions using a `MeetsCustomRule()` method, e.g.
7469

7570
```csharp
7671
var myRule = new CustomRule();
7772

7873
// Write your own custom rules that can be used as both predicates and conditions
79-
result = Types.InCurrentDomain()
80-
.That().AreClasses()
74+
var result = Types.InCurrentDomain()
75+
.That()
76+
.AreClasses()
8177
.Should()
8278
.MeetCustomRule(myRule)
83-
.GetResult().IsSuccessful;
84-
```
85-
86-
### Grouping rules into Policies
87-
88-
Rules can be grouped into policies using the fluent interface exposed by the `Policy` class, e.g.
89-
90-
```csharp
91-
var architecturePolicy = Policy.Define("Example Policy", "This is an example policy")
92-
.For(Types.InCurrentDomain)
93-
.Add(t =>
94-
t.That()
95-
.ResideInNamespace("NetArchTest.SampleLibrary.Presentation")
96-
.ShouldNot()
97-
.HaveDependencyOn("NetArchTest.SampleLibrary.Data"),
98-
"Enforcing layered architecture", "Controllers should not directly reference repositories"
99-
)
100-
...
101-
.Add(t =>
102-
t.That()
103-
.AreInterfaces()
104-
.Should()
105-
.HaveNameStartingWith("I"),
106-
"Generic implementation rules", "Interface names should start with an 'I'"
107-
);
108-
109-
```
110-
The rules are loaded lazily and executed when the `Evaluate()` method is called. This method returns a `PolicyResults` instance that can be passed to a reporting mechanism.
111-
112-
The [ExamplePolicies](https://github.com/BenMorris/NetArchTest/blob/master/samples/NetArchTest.SampleRules/ExamplePolicies.cs) class in the samples demonstrates how to do this.
113-
114-
## Further reading
115-
116-
A more extensive blog post describing the implementation detail is available in [my blog](https://www.ben-morris.com/writing-archunit-style-tests-for-net-and-c-for-self-testing-architectures).
79+
.GetResult()
80+
.IsSuccessful;
81+
```

src/NetArchTest.Rules/PredicateList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal IEnumerable<TypeSpec> GetTypeSpecifications()
6060
}
6161
internal IEnumerable<Type> GetNetTypes()
6262
{
63-
return GetTypes().Select(x => x.Type);
63+
return GetTypeSpecifications().Select(x => x.Definition.ToType());
6464
}
6565

6666
/// <summary>

0 commit comments

Comments
 (0)