Skip to content

Commit 0d3c2f8

Browse files
Add ImplementAny Fluent Syntax
Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
1 parent 6c13d07 commit 0d3c2f8

23 files changed

+1987
-46
lines changed

.csharpierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
ArchUnitNETTests/Fluent/Syntax/Elements/TypeSyntaxElementsTests.cs
12
ArchUnitNETTests/Fluent/Syntax/Elements/ObjectsShouldTests.cs

ArchUnit.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnit", "ArchUn
4444
EndProject
4545
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArchUnitNET.TUnitTests", "ArchUnitNET.TUnitTests\ArchUnitNET.TUnitTests.csproj", "{C54143CE-3256-4313-B991-0706705EEA1D}"
4646
EndProject
47+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceAssembly", "TestAssemblies\InterfaceAssembly\InterfaceAssembly.csproj", "{076E223C-32D3-4672-8B00-925CDBC1383E}"
48+
EndProject
4749
Global
4850
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4951
Debug|Any CPU = Debug|Any CPU
@@ -130,6 +132,10 @@ Global
130132
{C54143CE-3256-4313-B991-0706705EEA1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
131133
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
132134
{C54143CE-3256-4313-B991-0706705EEA1D}.Release|Any CPU.Build.0 = Release|Any CPU
135+
{076E223C-32D3-4672-8B00-925CDBC1383E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
136+
{076E223C-32D3-4672-8B00-925CDBC1383E}.Debug|Any CPU.Build.0 = Debug|Any CPU
137+
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.ActiveCfg = Release|Any CPU
138+
{076E223C-32D3-4672-8B00-925CDBC1383E}.Release|Any CPU.Build.0 = Release|Any CPU
133139
EndGlobalSection
134140
GlobalSection(SolutionProperties) = preSolution
135141
HideSolutionNode = FALSE
@@ -141,5 +147,6 @@ Global
141147
{0243F2D4-AC89-4561-A936-D647B6BB821F} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
142148
{5A24529B-1794-4080-ADCC-77440BA0A0B3} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
143149
{E6CB8C69-25F5-4C94-8EA3-D56E444EB46B} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
150+
{076E223C-32D3-4672-8B00-925CDBC1383E} = {B1191F18-91CB-4387-B775-A5EB64D3AC30}
144151
EndGlobalSection
145152
EndGlobal

ArchUnitNET/Fluent/Conditions/RelationCondition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ string failDescription
2828

2929
public ICondition<TRuleType> GetCondition(IEnumerable<TRelatedType> objects)
3030
{
31-
return _relation(new ListObjectProvider<TRelatedType>(objects.ToList()));
31+
return _relation(new ObjectProvider<TRelatedType>(objects.ToList()));
3232
}
3333

3434
private bool Equals(RelationCondition<TRuleType, TRelatedType> other)

ArchUnitNET/Fluent/ListObjectProvider.cs renamed to ArchUnitNET/Fluent/ObjectProvider.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
namespace ArchUnitNET.Fluent
66
{
7-
public class ListObjectProvider<T> : ISizedObjectProvider<T>
7+
public class ObjectProvider<T> : ISizedObjectProvider<T>
88
where T : ICanBeAnalyzed
99
{
10-
private readonly IEnumerable<T> _objects;
10+
private readonly List<T> _objects;
1111

12-
public ListObjectProvider(List<T> objects)
12+
public ObjectProvider()
13+
: this(new List<T>()) { }
14+
15+
public ObjectProvider(IEnumerable<T> objects)
1316
{
14-
_objects = objects;
15-
Description = string.Join(" or ", objects.Select(obj => $"\"{obj.FullName}\""));
17+
_objects = objects.ToList();
18+
Description = string.Join(" or ", _objects.Select(obj => $"\"{obj.FullName}\""));
1619
}
1720

1821
public string Description { get; }
@@ -24,7 +27,7 @@ public IEnumerable<T> GetObjects(Architecture architecture)
2427
return _objects;
2528
}
2629

27-
private bool Equals(ListObjectProvider<T> other)
30+
private bool Equals(ObjectProvider<T> other)
2831
{
2932
return string.Equals(Description, other.Description);
3033
}
@@ -41,7 +44,7 @@ public override bool Equals(object obj)
4144
return true;
4245
}
4346

44-
return obj.GetType() == GetType() && Equals((ListObjectProvider<T>)obj);
47+
return obj.GetType() == GetType() && Equals((ObjectProvider<T>)obj);
4548
}
4649

4750
public override int GetHashCode()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using ArchUnitNET.Domain;
2+
3+
namespace ArchUnitNET.Fluent.Syntax
4+
{
5+
public class DescriptionHelpers
6+
{
7+
public static string SelectDescription<T>(string emptyDescription, string singleDescription, string multipleDescription, IObjectProvider<T> objectProvider)
8+
{
9+
if (!(objectProvider is ISizedObjectProvider<T> sizedObjectProvider))
10+
{
11+
return $"{multipleDescription} {objectProvider.Description}";
12+
}
13+
14+
switch (sizedObjectProvider.Count)
15+
{
16+
case 0:
17+
return $"{emptyDescription}";
18+
case 1:
19+
return $"{singleDescription} {objectProvider.Description}";
20+
}
21+
return $"{multipleDescription} {objectProvider.Description}";
22+
}
23+
}
24+
}

ArchUnitNET/Fluent/Syntax/Elements/ObjectsShould.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ params ICanBeAnalyzed[] moreObjects
6262
objectList.AddRange(moreObjects);
6363
_ruleCreator.AddCondition(
6464
ObjectConditionsDefinition<TRuleType>.Be(
65-
new ListObjectProvider<ICanBeAnalyzed>(objectList)
65+
new ObjectProvider<ICanBeAnalyzed>(objectList)
6666
)
6767
);
6868
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -72,7 +72,7 @@ public TRuleTypeShouldConjunction Be(IEnumerable<ICanBeAnalyzed> objects)
7272
{
7373
_ruleCreator.AddCondition(
7474
ObjectConditionsDefinition<TRuleType>.Be(
75-
new ListObjectProvider<ICanBeAnalyzed>(objects.ToList())
75+
new ObjectProvider<ICanBeAnalyzed>(objects.ToList())
7676
)
7777
);
7878
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -121,7 +121,7 @@ params MethodMember[] moreMethods
121121
methodList.AddRange(moreMethods);
122122
_ruleCreator.AddCondition(
123123
ObjectConditionsDefinition<TRuleType>.CallAny(
124-
new ListObjectProvider<MethodMember>(methodList)
124+
new ObjectProvider<MethodMember>(methodList)
125125
)
126126
);
127127
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -131,7 +131,7 @@ public TRuleTypeShouldConjunction CallAny(IEnumerable<MethodMember> methods)
131131
{
132132
_ruleCreator.AddCondition(
133133
ObjectConditionsDefinition<TRuleType>.CallAny(
134-
new ListObjectProvider<MethodMember>(methods.ToList())
134+
new ObjectProvider<MethodMember>(methods.ToList())
135135
)
136136
);
137137
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -177,7 +177,7 @@ public TRuleTypeShouldConjunction DependOnAny(IType firstType, params IType[] mo
177177
typeList.AddRange(moreTypes);
178178
_ruleCreator.AddCondition(
179179
ObjectConditionsDefinition<TRuleType>.DependOnAny(
180-
new ListObjectProvider<IType>(typeList)
180+
new ObjectProvider<IType>(typeList)
181181
)
182182
);
183183
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -189,7 +189,7 @@ public TRuleTypeShouldConjunction DependOnAny(Type firstType, params Type[] more
189189
typeList.AddRange(moreTypes);
190190
_ruleCreator.AddCondition(
191191
ObjectConditionsDefinition<TRuleType>.DependOnAny(
192-
new SystemTypeListObjectProvider<IType>(typeList)
192+
new SystemTypeObjectProvider<IType>(typeList)
193193
)
194194
);
195195
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -205,7 +205,7 @@ public TRuleTypeShouldConjunction DependOnAny(IEnumerable<IType> types)
205205
{
206206
_ruleCreator.AddCondition(
207207
ObjectConditionsDefinition<TRuleType>.DependOnAny(
208-
new ListObjectProvider<IType>(types.ToList())
208+
new ObjectProvider<IType>(types.ToList())
209209
)
210210
);
211211
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -215,7 +215,7 @@ public TRuleTypeShouldConjunction DependOnAny(IEnumerable<Type> types)
215215
{
216216
_ruleCreator.AddCondition(
217217
ObjectConditionsDefinition<TRuleType>.DependOnAny(
218-
new SystemTypeListObjectProvider<IType>(types.ToList())
218+
new SystemTypeObjectProvider<IType>(types.ToList())
219219
)
220220
);
221221
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -288,7 +288,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IType firstType, params IType[] m
288288
typeList.AddRange(moreTypes);
289289
_ruleCreator.AddCondition(
290290
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
291-
new ListObjectProvider<IType>(typeList)
291+
new ObjectProvider<IType>(typeList)
292292
)
293293
);
294294
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -300,7 +300,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(Type firstType, params Type[] mor
300300
typeList.AddRange(moreTypes);
301301
_ruleCreator.AddCondition(
302302
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
303-
new SystemTypeListObjectProvider<IType>(typeList)
303+
new SystemTypeObjectProvider<IType>(typeList)
304304
)
305305
);
306306
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -316,7 +316,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable<IType> types)
316316
{
317317
_ruleCreator.AddCondition(
318318
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
319-
new ListObjectProvider<IType>(types.ToList())
319+
new ObjectProvider<IType>(types.ToList())
320320
)
321321
);
322322
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -326,7 +326,7 @@ public TRuleTypeShouldConjunction OnlyDependOn(IEnumerable<Type> types)
326326
{
327327
_ruleCreator.AddCondition(
328328
ObjectConditionsDefinition<TRuleType>.OnlyDependOn(
329-
new SystemTypeListObjectProvider<IType>(types.ToList())
329+
new SystemTypeObjectProvider<IType>(types.ToList())
330330
)
331331
);
332332
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -375,7 +375,7 @@ params Attribute[] moreAttributes
375375
attributeList.AddRange(moreAttributes);
376376
_ruleCreator.AddCondition(
377377
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
378-
new ListObjectProvider<Attribute>(attributeList)
378+
new ObjectProvider<Attribute>(attributeList)
379379
)
380380
);
381381
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -390,7 +390,7 @@ params Type[] moreAttributes
390390
attributeList.AddRange(moreAttributes);
391391
_ruleCreator.AddCondition(
392392
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
393-
new SystemTypeListObjectProvider<Attribute>(attributeList)
393+
new SystemTypeObjectProvider<Attribute>(attributeList)
394394
)
395395
);
396396
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -408,7 +408,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable<Attribute> attri
408408
{
409409
_ruleCreator.AddCondition(
410410
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
411-
new ListObjectProvider<Attribute>(attributes.ToList())
411+
new ObjectProvider<Attribute>(attributes.ToList())
412412
)
413413
);
414414
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -418,7 +418,7 @@ public TRuleTypeShouldConjunction HaveAnyAttributes(IEnumerable<Type> attributes
418418
{
419419
_ruleCreator.AddCondition(
420420
ObjectConditionsDefinition<TRuleType>.HaveAnyAttributes(
421-
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
421+
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
422422
)
423423
);
424424
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -467,7 +467,7 @@ params Attribute[] moreAttributes
467467
attributeList.AddRange(moreAttributes);
468468
_ruleCreator.AddCondition(
469469
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
470-
new ListObjectProvider<Attribute>(attributeList)
470+
new ObjectProvider<Attribute>(attributeList)
471471
)
472472
);
473473
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -482,7 +482,7 @@ params Type[] moreAttributes
482482
attributeList.AddRange(moreAttributes);
483483
_ruleCreator.AddCondition(
484484
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
485-
new SystemTypeListObjectProvider<Attribute>(attributeList)
485+
new SystemTypeObjectProvider<Attribute>(attributeList)
486486
)
487487
);
488488
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -500,7 +500,7 @@ public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable<Attribute> attr
500500
{
501501
_ruleCreator.AddCondition(
502502
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
503-
new ListObjectProvider<Attribute>(attributes.ToList())
503+
new ObjectProvider<Attribute>(attributes.ToList())
504504
)
505505
);
506506
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -510,7 +510,7 @@ public TRuleTypeShouldConjunction OnlyHaveAttributes(IEnumerable<Type> attribute
510510
{
511511
_ruleCreator.AddCondition(
512512
ObjectConditionsDefinition<TRuleType>.OnlyHaveAttributes(
513-
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
513+
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
514514
)
515515
);
516516
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -979,7 +979,7 @@ params ICanBeAnalyzed[] moreObjects
979979
objectList.AddRange(moreObjects);
980980
_ruleCreator.AddCondition(
981981
ObjectConditionsDefinition<TRuleType>.NotBe(
982-
new ListObjectProvider<ICanBeAnalyzed>(objectList)
982+
new ObjectProvider<ICanBeAnalyzed>(objectList)
983983
)
984984
);
985985
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -989,7 +989,7 @@ public TRuleTypeShouldConjunction NotBe(IEnumerable<ICanBeAnalyzed> objects)
989989
{
990990
_ruleCreator.AddCondition(
991991
ObjectConditionsDefinition<TRuleType>.NotBe(
992-
new ListObjectProvider<ICanBeAnalyzed>(objects.ToList())
992+
new ObjectProvider<ICanBeAnalyzed>(objects.ToList())
993993
)
994994
);
995995
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1038,7 +1038,7 @@ params MethodMember[] moreMethods
10381038
methods.AddRange(moreMethods);
10391039
_ruleCreator.AddCondition(
10401040
ObjectConditionsDefinition<TRuleType>.NotCallAny(
1041-
new ListObjectProvider<MethodMember>(methods)
1041+
new ObjectProvider<MethodMember>(methods)
10421042
)
10431043
);
10441044
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1049,7 +1049,7 @@ public TRuleTypeShouldConjunction NotCallAny(IEnumerable<MethodMember> methods)
10491049
var methodList = methods.ToList();
10501050
_ruleCreator.AddCondition(
10511051
ObjectConditionsDefinition<TRuleType>.NotCallAny(
1052-
new ListObjectProvider<MethodMember>(methodList)
1052+
new ObjectProvider<MethodMember>(methodList)
10531053
)
10541054
);
10551055
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1098,7 +1098,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IType firstType, params IType[]
10981098
typeList.AddRange(moreTypes);
10991099
_ruleCreator.AddCondition(
11001100
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
1101-
new ListObjectProvider<IType>(typeList)
1101+
new ObjectProvider<IType>(typeList)
11021102
)
11031103
);
11041104
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1110,7 +1110,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(Type firstType, params Type[] m
11101110
typeList.AddRange(moreTypes);
11111111
_ruleCreator.AddCondition(
11121112
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
1113-
new SystemTypeListObjectProvider<IType>(typeList)
1113+
new SystemTypeObjectProvider<IType>(typeList)
11141114
)
11151115
);
11161116
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1126,7 +1126,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable<IType> types)
11261126
{
11271127
_ruleCreator.AddCondition(
11281128
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
1129-
new ListObjectProvider<IType>(types.ToList())
1129+
new ObjectProvider<IType>(types.ToList())
11301130
)
11311131
);
11321132
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1136,7 +1136,7 @@ public TRuleTypeShouldConjunction NotDependOnAny(IEnumerable<Type> types)
11361136
{
11371137
_ruleCreator.AddCondition(
11381138
ObjectConditionsDefinition<TRuleType>.NotDependOnAny(
1139-
new SystemTypeListObjectProvider<IType>(types.ToList())
1139+
new SystemTypeObjectProvider<IType>(types.ToList())
11401140
)
11411141
);
11421142
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1185,7 +1185,7 @@ params Attribute[] moreAttributes
11851185
attributeList.AddRange(moreAttributes);
11861186
_ruleCreator.AddCondition(
11871187
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
1188-
new ListObjectProvider<Attribute>(attributeList)
1188+
new ObjectProvider<Attribute>(attributeList)
11891189
)
11901190
);
11911191
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1200,7 +1200,7 @@ params Type[] moreAttributes
12001200
attributeList.AddRange(moreAttributes);
12011201
_ruleCreator.AddCondition(
12021202
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
1203-
new SystemTypeListObjectProvider<Attribute>(attributeList)
1203+
new SystemTypeObjectProvider<Attribute>(attributeList)
12041204
)
12051205
);
12061206
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1220,7 +1220,7 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable<Attribute> at
12201220
{
12211221
_ruleCreator.AddCondition(
12221222
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
1223-
new ListObjectProvider<Attribute>(attributes.ToList())
1223+
new ObjectProvider<Attribute>(attributes.ToList())
12241224
)
12251225
);
12261226
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
@@ -1230,7 +1230,7 @@ public TRuleTypeShouldConjunction NotHaveAnyAttributes(IEnumerable<Type> attribu
12301230
{
12311231
_ruleCreator.AddCondition(
12321232
ObjectConditionsDefinition<TRuleType>.NotHaveAnyAttributes(
1233-
new SystemTypeListObjectProvider<Attribute>(attributes.ToList())
1233+
new SystemTypeObjectProvider<Attribute>(attributes.ToList())
12341234
)
12351235
);
12361236
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);

0 commit comments

Comments
 (0)