Skip to content

Commit 3c04b49

Browse files
Refactor Fluent Syntax to have a single implementation of each method
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
1 parent aad79ad commit 3c04b49

80 files changed

Lines changed: 1154 additions & 4086 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs renamed to ArchUnitNET/Fluent/Syntax/Elements/AddObjectCondition.cs

Lines changed: 117 additions & 101 deletions
Large diffs are not rendered by default.

ArchUnitNET/Fluent/Syntax/Elements/GivenObjectsThat.cs renamed to ArchUnitNET/Fluent/Syntax/Elements/AddObjectPredicate.cs

Lines changed: 81 additions & 85 deletions
Large diffs are not rendered by default.

ArchUnitNET/Fluent/Syntax/Elements/IObjectConditions.cs renamed to ArchUnitNET/Fluent/Syntax/Elements/IAddObjectCondition.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections.Generic;
33
using ArchUnitNET.Domain;
44
using ArchUnitNET.Fluent.Conditions;
5+
using ArchUnitNET.Fluent.Syntax.Elements.Types;
6+
using ArchUnitNET.Fluent.Syntax.Elements.Types.Attributes;
57
using Attribute = ArchUnitNET.Domain.Attribute;
68

79
namespace ArchUnitNET.Fluent.Syntax.Elements
810
{
9-
public interface IObjectConditions<out TReturnType, out TRuleType>
11+
public interface IAddObjectCondition<TReturnType, TRuleType>
1012
where TRuleType : ICanBeAnalyzed
1113
{
1214
// csharpier-ignore-start
@@ -27,6 +29,7 @@ public interface IObjectConditions<out TReturnType, out TRuleType>
2729
TReturnType DependOnAny(IObjectProvider<IType> types);
2830
TReturnType DependOnAny(IEnumerable<IType> types);
2931
TReturnType DependOnAny(IEnumerable<Type> types);
32+
ShouldRelateToTypesThat<TReturnType, TRuleType> DependOnAnyTypesThat();
3033

3134
TReturnType FollowCustomCondition(ICondition<TRuleType> condition);
3235
TReturnType FollowCustomCondition(Func<TRuleType, ConditionResult> condition, string description);
@@ -38,20 +41,23 @@ public interface IObjectConditions<out TReturnType, out TRuleType>
3841
TReturnType OnlyDependOn(IObjectProvider<IType> types);
3942
TReturnType OnlyDependOn(IEnumerable<IType> types);
4043
TReturnType OnlyDependOn(IEnumerable<Type> types);
44+
ShouldRelateToTypesThat<TReturnType, TRuleType> OnlyDependOnTypesThat();
4145

4246
TReturnType HaveAnyAttributes();
4347
TReturnType HaveAnyAttributes(params Attribute[] attributes);
4448
TReturnType HaveAnyAttributes(params Type[] attributes);
4549
TReturnType HaveAnyAttributes(IObjectProvider<Attribute> attributes);
4650
TReturnType HaveAnyAttributes(IEnumerable<Attribute> attributes);
4751
TReturnType HaveAnyAttributes(IEnumerable<Type> attributes);
52+
ShouldRelateToAttributesThat<TReturnType, TRuleType> HaveAnyAttributesThat();
4853

4954
TReturnType OnlyHaveAttributes();
5055
TReturnType OnlyHaveAttributes(params Attribute[] attributes);
5156
TReturnType OnlyHaveAttributes(params Type[] attributes);
5257
TReturnType OnlyHaveAttributes(IObjectProvider<Attribute> attributes);
5358
TReturnType OnlyHaveAttributes(IEnumerable<Attribute> attributes);
5459
TReturnType OnlyHaveAttributes(IEnumerable<Type> attributes);
60+
ShouldRelateToAttributesThat<TReturnType, TRuleType> OnlyHaveAttributesThat();
5561

5662
TReturnType HaveAnyAttributesWithArguments(IEnumerable<object> argumentValues);
5763

@@ -109,13 +115,15 @@ public interface IObjectConditions<out TReturnType, out TRuleType>
109115
TReturnType NotDependOnAny(IObjectProvider<IType> types);
110116
TReturnType NotDependOnAny(IEnumerable<IType> types);
111117
TReturnType NotDependOnAny(IEnumerable<Type> types);
118+
ShouldRelateToTypesThat<TReturnType, TRuleType> NotDependOnAnyTypesThat();
112119

113120
TReturnType NotHaveAnyAttributes();
114121
TReturnType NotHaveAnyAttributes(params Attribute[] attributes);
115122
TReturnType NotHaveAnyAttributes(params Type[] attributes);
116123
TReturnType NotHaveAnyAttributes(IObjectProvider<Attribute> attributes);
117124
TReturnType NotHaveAnyAttributes(IEnumerable<Attribute> attributes);
118125
TReturnType NotHaveAnyAttributes(IEnumerable<Type> attributes);
126+
ShouldRelateToAttributesThat<TReturnType, TRuleType> NotHaveAnyAttributesThat();
119127

120128
TReturnType NotHaveAnyAttributesWithArguments(IEnumerable<object> argumentValues);
121129

ArchUnitNET/Fluent/Syntax/Elements/IObjectPredicates.cs renamed to ArchUnitNET/Fluent/Syntax/Elements/IAddObjectPredicate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace ArchUnitNET.Fluent.Syntax.Elements
88
{
9-
public interface IObjectPredicates<out TReturnType, TRuleType>
9+
public interface IAddObjectPredicate<out TReturnType, TRuleType>
1010
where TRuleType : ICanBeAnalyzed
1111
{
1212
// csharpier-ignore-start

ArchUnitNET/Fluent/Syntax/Elements/IComplexObjectConditions.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using ArchUnitNET.Domain;
4+
using ArchUnitNET.Fluent.Syntax.Elements.Types;
5+
6+
namespace ArchUnitNET.Fluent.Syntax.Elements.Members
7+
{
8+
public abstract class AddMemberCondition<TNextElement, TRuleType>
9+
: AddObjectCondition<TNextElement, TRuleType>,
10+
IAddMemberCondition<TNextElement, TRuleType>
11+
where TRuleType : IMember
12+
{
13+
internal AddMemberCondition(IArchRuleCreator<TRuleType> ruleCreator)
14+
: base(ruleCreator) { }
15+
16+
// csharpier-ignore-start
17+
public TNextElement BeDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeDeclaredIn(firstType, moreTypes));
18+
public TNextElement BeDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeDeclaredIn(firstType, moreTypes));
19+
public TNextElement BeDeclaredIn(IObjectProvider<IType> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeDeclaredIn(types));
20+
public TNextElement BeDeclaredIn(IEnumerable<IType> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeDeclaredIn(types));
21+
public TNextElement BeDeclaredIn(IEnumerable<Type> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeDeclaredIn(types));
22+
23+
public TNextElement BeStatic() => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeStatic());
24+
public TNextElement BeReadOnly() => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeReadOnly());
25+
public TNextElement BeImmutable() => CreateNextElement(MemberConditionsDefinition<TRuleType>.BeImmutable());
26+
27+
//Relation Conditions
28+
29+
public ShouldRelateToTypesThat<TNextElement, TRuleType> BeDeclaredInTypesThat() => BeginComplexTypeCondition(MemberConditionsDefinition<TRuleType>.BeDeclaredInTypesThat());
30+
31+
//Negations
32+
33+
public TNextElement NotBeDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeDeclaredIn(firstType, moreTypes));
34+
public TNextElement NotBeDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeDeclaredIn(firstType, moreTypes));
35+
public TNextElement NotBeDeclaredIn(IObjectProvider<IType> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeDeclaredIn(types));
36+
public TNextElement NotBeDeclaredIn(IEnumerable<IType> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeDeclaredIn(types));
37+
public TNextElement NotBeDeclaredIn(IEnumerable<Type> types) => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeDeclaredIn(types));
38+
39+
public TNextElement NotBeStatic() => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeStatic());
40+
public TNextElement NotBeReadOnly() => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeReadOnly());
41+
public TNextElement NotBeImmutable() => CreateNextElement(MemberConditionsDefinition<TRuleType>.NotBeImmutable());
42+
43+
//Relation Condition Negations
44+
45+
public ShouldRelateToTypesThat<TNextElement, TRuleType> NotBeDeclaredInTypesThat() => BeginComplexTypeCondition(MemberConditionsDefinition<TRuleType>.NotBeDeclaredInTypesThat());
46+
// csharpier-ignore-end
47+
}
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using ArchUnitNET.Domain;
4+
5+
namespace ArchUnitNET.Fluent.Syntax.Elements.Members
6+
{
7+
public abstract class AddMemberPredicate<TNextElement, TRelatedType, TRuleType>
8+
: AddObjectPredicate<TNextElement, TRelatedType, TRuleType>,
9+
IAddMemberPredicate<TNextElement, TRuleType>
10+
where TRuleType : IMember
11+
where TRelatedType : ICanBeAnalyzed
12+
{
13+
internal AddMemberPredicate(IArchRuleCreator<TRelatedType> ruleCreator)
14+
: base(ruleCreator) { }
15+
16+
// csharpier-ignore-start
17+
public TNextElement AreDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreDeclaredIn(firstType, moreTypes));
18+
public TNextElement AreDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreDeclaredIn(firstType, moreTypes));
19+
public TNextElement AreDeclaredIn(IObjectProvider<IType> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreDeclaredIn(types));
20+
public TNextElement AreDeclaredIn(IEnumerable<IType> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreDeclaredIn(types));
21+
public TNextElement AreDeclaredIn(IEnumerable<Type> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreDeclaredIn(types));
22+
23+
public TNextElement AreStatic() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreStatic());
24+
public TNextElement AreReadOnly() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreReadOnly());
25+
public TNextElement AreImmutable() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreImmutable());
26+
27+
//Negations
28+
29+
public TNextElement AreNotDeclaredIn(IType firstType, params IType[] moreTypes) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(firstType, moreTypes));
30+
public TNextElement AreNotDeclaredIn(Type firstType, params Type[] moreTypes) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(firstType, moreTypes));
31+
public TNextElement AreNotDeclaredIn(IObjectProvider<IType> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(types));
32+
public TNextElement AreNotDeclaredIn(IEnumerable<IType> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(types));
33+
public TNextElement AreNotDeclaredIn(IEnumerable<Type> types) => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotDeclaredIn(types));
34+
35+
public TNextElement AreNotStatic() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotStatic());
36+
public TNextElement AreNotReadOnly() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotReadOnly());
37+
public TNextElement AreNotImmutable() => CreateNextElement(MemberPredicatesDefinition<TRuleType>.AreNotImmutable());
38+
39+
// csharpier-ignore-end
40+
}
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ArchUnitNET.Domain;
2+
3+
namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers
4+
{
5+
public abstract class AddFieldMemberCondition<TNextElement>
6+
: AddMemberCondition<TNextElement, FieldMember>,
7+
IAddFieldMemberCondition<TNextElement, FieldMember>
8+
{
9+
internal AddFieldMemberCondition(IArchRuleCreator<FieldMember> ruleCreator)
10+
: base(ruleCreator) { }
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ArchUnitNET.Domain;
2+
3+
namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers
4+
{
5+
public abstract class AddFieldMemberPredicate<TNextElement, TRelatedType>
6+
: AddMemberPredicate<TNextElement, TRelatedType, FieldMember>,
7+
IAddFieldMemberPredicate<TNextElement, FieldMember>
8+
where TRelatedType : ICanBeAnalyzed
9+
{
10+
internal AddFieldMemberPredicate(IArchRuleCreator<TRelatedType> ruleCreator)
11+
: base(ruleCreator) { }
12+
}
13+
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
using ArchUnitNET.Domain;
2+
using ArchUnitNET.Fluent.Conditions;
23

34
namespace ArchUnitNET.Fluent.Syntax.Elements.Members.FieldMembers
45
{
5-
public class FieldMembersShould
6-
: MembersShould<FieldMembersShouldConjunction, FieldMember>,
7-
IComplexFieldMemberConditions
6+
public sealed class FieldMembersShould : AddFieldMemberCondition<FieldMembersShould>
87
{
98
public FieldMembersShould(IArchRuleCreator<FieldMember> ruleCreator)
109
: base(ruleCreator) { }
10+
11+
protected override FieldMembersShould CreateNextElement(
12+
IOrderedCondition<FieldMember> condition
13+
)
14+
{
15+
_ruleCreator.AddCondition(condition);
16+
return new FieldMembersShould(_ruleCreator);
17+
}
1118
}
1219
}

0 commit comments

Comments
 (0)