-
Notifications
You must be signed in to change notification settings - Fork 70
feat: Add HaveAnyParameters and NotHaveAnyParameters #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add HaveAnyParameters and NotHaveAnyParameters #403
Conversation
0b2bb6a to
e64d5f7
Compare
|
Hi @Redestros, I think this is too specific to be included as a separate fluent syntax method, because it basically combines a predicate and two conditions. I think a syntax like the following would be a better way to allow for this: The only function that would be missing for this is |
|
Hi @alexanderlinne , ✅ Added HaveAnyParameters() condition for MethodMembers Usage Example var classes = Classes()
.That().ResideInNamespace("MyApp.Domain.Entities")
.And().AreNotAbstract();
MethodMembers()
.That()
.AreDeclaredIn(classes)
.And()
.AreConstructors()
.Should()
.BePrivate()
.AndShould()
.NotHaveAnyParameters(); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
==========================================
+ Coverage 77.39% 77.46% +0.06%
==========================================
Files 257 257
Lines 19034 19056 +22
Branches 1592 1592
==========================================
+ Hits 14731 14761 +30
+ Misses 3848 3840 -8
Partials 455 455 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1b1890f to
fd7746f
Compare
…eterlessConstructor conditions Add support for checking if classes have private parameterless constructors, which is essential for enforcing Domain-Driven Design patterns and ORM requirements. Signed-off-by: Ahmed Mohamed El Ahmar <ahmedmohamedelahmar@gmail.com>
…embers - Add HaveAnyParameters() condition to check if methods have parameters - Add NotHaveAnyParameters() condition to check if methods have no parameters - Add corresponding methods to IMethodMemberConditions interface - Add comprehensive test coverage for both conditions - Test both regular methods and constructors - Verify failure descriptions in violation cases - Use correct IL method names (.ctor) for constructor tests - Remove redundant test cases that provided no additional value The new conditions enable architectural rules to enforce parameter requirements on methods and constructors, complementing existing method member conditions. Signed-off-by: Ahmed Mohamed El Ahmar <ahmedmohamedelahmar@gmail.com>
fd7746f to
4cd515f
Compare
Description
This PR adds support for checking if classes have private parameterless constructors in ArchUnitNET. This feature is particularly valuable for enforcing Domain-Driven Design patterns where entities should have private parameterless constructors for ORM frameworks while maintaining public constructors with parameters for domain logic.
Motivation
In Domain-Driven Design and Entity Framework scenarios, it's common to require:
This pattern ensures that:
Implementation
Core Changes
HavePrivateParameterlessConstructor()condition usingSimpleCondition<Class>NotHavePrivateParameterlessConstructor()condition for inverse validationIClassConditionsinterface andClassConditionsDefinitionIsAbstractproperty (cls.IsAbstract == true)Test Coverage
Usage Examples
Basic Usage