Skip to content

Commit b25c4f9

Browse files
authored
Merge pull request #451 from TNG/446-notimplementanyinterfaces-returns-fail-if-interfaces-is-empty
Correct behavior of ImplementAny fluent syntax for empty arguments
2 parents e50b6dd + 1033ca9 commit b25c4f9

File tree

5 files changed

+128
-327
lines changed

5 files changed

+128
-327
lines changed

ArchUnitNET/Fluent/Syntax/Elements/Types/TypeConditionsDefinition.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ Architecture architecture
571571
{
572572
if (
573573
interfaceList.Count > 0
574-
? ruleType.ImplementedInterfaces.Intersect(interfaceList).Any()
575-
: ruleType.ImplementedInterfaces.Any()
574+
&& ruleType.ImplementedInterfaces.Intersect(interfaceList).Any()
576575
)
577576
{
578577
yield return new ConditionResult(ruleType, true);
@@ -592,7 +591,7 @@ Architecture architecture
592591
}
593592

594593
var description = interfaces.FormatDescription(
595-
"implement any interface",
594+
"implement any of no interfaces (always false)",
596595
"implement",
597596
"implement any"
598597
);
@@ -1211,11 +1210,10 @@ Architecture architecture
12111210
var interfaceList = interfaces.GetObjects(architecture).ToList();
12121211
foreach (var ruleType in ruleTypes.ToList())
12131212
{
1214-
var matchingInterfaces =
1215-
interfaceList.Count > 0
1216-
? ruleType.ImplementedInterfaces.Intersect(interfaceList).ToList()
1217-
: ruleType.ImplementedInterfaces.ToList();
1218-
if (matchingInterfaces.Any())
1213+
var matchingInterfaces = ruleType.ImplementedInterfaces.Intersect(
1214+
interfaceList
1215+
);
1216+
if (interfaceList.Count > 0 && matchingInterfaces.Any())
12191217
{
12201218
yield return new ConditionResult(
12211219
ruleType,
@@ -1232,7 +1230,7 @@ Architecture architecture
12321230
}
12331231

12341232
var description = interfaces.FormatDescription(
1235-
"not implement any interface",
1233+
"not implement any of no interfaces (always true)",
12361234
"not implement",
12371235
"not implement any"
12381236
);

ArchUnitNET/Fluent/Syntax/Elements/Types/TypePredicatesDefinition.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,11 @@ IEnumerable<T> Condition(IEnumerable<T> ruleTypes, Architecture architecture)
348348
var interfaceList = interfaces.GetObjects(architecture).ToList();
349349
return ruleTypes.Where(type =>
350350
interfaceList.Count > 0
351-
? type.ImplementedInterfaces.Intersect(interfaceList).Any()
352-
: type.ImplementedInterfaces.Any()
351+
&& type.ImplementedInterfaces.Intersect(interfaceList).Any()
353352
);
354353
}
355354
var description = interfaces.FormatDescription(
356-
"implement any interface",
355+
"implement any of no interfaces (always false)",
357356
"implement",
358357
"implement any"
359358
);
@@ -695,13 +694,12 @@ IEnumerable<T> Condition(IEnumerable<T> ruleTypes, Architecture architecture)
695694
{
696695
var interfaceList = interfaces.GetObjects(architecture).ToList();
697696
return ruleTypes.Where(type =>
698-
interfaceList.Count > 0
699-
? !type.ImplementedInterfaces.Intersect(interfaceList).Any()
700-
: !type.ImplementedInterfaces.Any()
697+
interfaceList.Count <= 0
698+
|| !type.ImplementedInterfaces.Intersect(interfaceList).Any()
701699
);
702700
}
703701
var description = interfaces.FormatDescription(
704-
"do not implement any interface",
702+
"do not implement any of no interfaces (always true)",
705703
"do not implement",
706704
"do not implement any"
707705
);

ArchUnitNETTests/Fluent/Syntax/Elements/Snapshots/TypeSyntaxElementsTests.ImplementAnyInterfacesTest.verified.txt

Lines changed: 73 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -258,203 +258,157 @@ Message:
258258

259259

260260

261-
===== Empty Arguments (No Violations) =====
261+
===== Empty Arguments (Only Violations) =====
262262

263263
----- Conditions -----
264264

265-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should implement any interface
266-
Result: True
267-
Description: InterfaceAssembly.IChildInterface passed
268-
Message:
269-
All Evaluations passed
270-
271-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should implement any interface
272-
Result: True
273-
Description: InterfaceAssembly.IChildInterface passed
274-
Message:
275-
All Evaluations passed
276-
277-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should implement any interface
278-
Result: True
279-
Description: InterfaceAssembly.IChildInterface passed
280-
Message:
281-
All Evaluations passed
282-
283-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should implement any Interfaces that have name "NotTheNameOfAnyObject"
284-
Result: True
285-
Description: InterfaceAssembly.IChildInterface passed
286-
Message:
287-
All Evaluations passed
288-
289-
----- Predicates -----
290-
291-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be Interfaces that implement any interface
292-
Result: True
293-
Description: InterfaceAssembly.IChildInterface passed
294-
Message:
295-
All Evaluations passed
296-
297-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be Interfaces that implement any interface
298-
Result: True
299-
Description: InterfaceAssembly.IChildInterface passed
300-
Message:
301-
All Evaluations passed
302-
303-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be Interfaces that implement any interface
304-
Result: True
305-
Description: InterfaceAssembly.IChildInterface passed
306-
Message:
307-
All Evaluations passed
308-
309-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
310-
Result: True
311-
Description: InterfaceAssembly.IChildInterface passed
312-
Message:
313-
All Evaluations passed
314-
315-
----- Predicates as conditions -----
316-
317-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be types that implement any interface
318-
Result: True
319-
Description: InterfaceAssembly.IChildInterface passed
320-
Message:
321-
All Evaluations passed
322-
323-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be types that implement any interface
324-
Result: True
325-
Description: InterfaceAssembly.IChildInterface passed
326-
Message:
327-
All Evaluations passed
328-
329-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should be types that implement any Interfaces that have name "NotTheNameOfAnyObject"
330-
Result: True
331-
Description: InterfaceAssembly.IChildInterface passed
332-
Message:
333-
All Evaluations passed
334-
335-
----- Complex conditions -----
336-
337-
Query: Interfaces that are "InterfaceAssembly.IChildInterface" should implement any interfaces that are any of no objects (always empty)
338-
Result: True
339-
Description: InterfaceAssembly.IChildInterface passed
340-
Message:
341-
All Evaluations passed
342-
343-
===== Empty Arguments (Violations) =====
344-
345-
----- Conditions -----
346-
347-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface
265+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)
348266
Result: False
349267
Description: InterfaceAssembly.IBaseInterface does not implement any interface
268+
Result: False
269+
Description: InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
350270
Message:
351-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface" failed:
271+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)" failed:
352272
InterfaceAssembly.IBaseInterface does not implement any interface
273+
InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
353274

354275

355276

356-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface
277+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)
357278
Result: False
358279
Description: InterfaceAssembly.IBaseInterface does not implement any interface
280+
Result: False
281+
Description: InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
359282
Message:
360-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface" failed:
283+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)" failed:
361284
InterfaceAssembly.IBaseInterface does not implement any interface
285+
InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
362286

363287

364288

365-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface
289+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)
366290
Result: False
367291
Description: InterfaceAssembly.IBaseInterface does not implement any interface
292+
Result: False
293+
Description: InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
368294
Message:
369-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interface" failed:
295+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any of no interfaces (always false)" failed:
370296
InterfaceAssembly.IBaseInterface does not implement any interface
297+
InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
371298

372299

373300

374-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any Interfaces that have name "NotTheNameOfAnyObject"
301+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any Interfaces that have name "NotTheNameOfAnyObject"
375302
Result: False
376303
Description: InterfaceAssembly.IBaseInterface does not implement any interface
304+
Result: False
305+
Description: InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
377306
Message:
378-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
307+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
379308
InterfaceAssembly.IBaseInterface does not implement any interface
309+
InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
380310

381311

382312

383313
----- Predicates -----
384314

385-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface
315+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)
316+
Result: False
317+
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
386318
Result: False
387-
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
319+
Description: InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
388320
Message:
389-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface" failed:
390-
InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
321+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)" failed:
322+
InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
323+
InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
391324

392325

393326

394-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface
327+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)
328+
Result: False
329+
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
395330
Result: False
396-
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
331+
Description: InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
397332
Message:
398-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface" failed:
399-
InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
333+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)" failed:
334+
InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
335+
InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
400336

401337

402338

403-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface
339+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)
404340
Result: False
405-
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
341+
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
342+
Result: False
343+
Description: InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
406344
Message:
407-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any interface" failed:
408-
InterfaceAssembly.IBaseInterface is not Interfaces that implement any interface
345+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any of no interfaces (always false)" failed:
346+
InterfaceAssembly.IBaseInterface is not Interfaces that implement any of no interfaces (always false)
347+
InterfaceAssembly.IChildInterface is not Interfaces that implement any of no interfaces (always false)
409348

410349

411350

412-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
351+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
413352
Result: False
414353
Description: InterfaceAssembly.IBaseInterface is not Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
354+
Result: False
355+
Description: InterfaceAssembly.IChildInterface is not Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
415356
Message:
416-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
357+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
417358
InterfaceAssembly.IBaseInterface is not Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
359+
InterfaceAssembly.IChildInterface is not Interfaces that implement any Interfaces that have name "NotTheNameOfAnyObject"
418360

419361

420362

421363
----- Predicates as conditions -----
422364

423-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any interface
365+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any of no interfaces (always false)
366+
Result: False
367+
Description: InterfaceAssembly.IBaseInterface does exist
424368
Result: False
425-
Description: InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
369+
Description: InterfaceAssembly.IChildInterface does exist
426370
Message:
427-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any interface" failed:
428-
InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
371+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any of no interfaces (always false)" failed:
372+
InterfaceAssembly.IBaseInterface does exist
373+
InterfaceAssembly.IChildInterface does exist
429374

430375

431376

432-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any interface
377+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any of no interfaces (always false)
433378
Result: False
434-
Description: InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
379+
Description: InterfaceAssembly.IBaseInterface does exist
380+
Result: False
381+
Description: InterfaceAssembly.IChildInterface does exist
435382
Message:
436-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any interface" failed:
437-
InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
383+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any of no interfaces (always false)" failed:
384+
InterfaceAssembly.IBaseInterface does exist
385+
InterfaceAssembly.IChildInterface does exist
438386

439387

440388

441-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any Interfaces that have name "NotTheNameOfAnyObject"
389+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any Interfaces that have name "NotTheNameOfAnyObject"
390+
Result: False
391+
Description: InterfaceAssembly.IBaseInterface does exist
442392
Result: False
443-
Description: InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
393+
Description: InterfaceAssembly.IChildInterface does exist
444394
Message:
445-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should be types that implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
446-
InterfaceAssembly.IBaseInterface is not "InterfaceAssembly.IChildInterface" or "InterfaceAssembly.IOtherChildInterface" or "InterfaceAssembly.IInterfaceWithMultipleDependencies"
395+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should be types that implement any Interfaces that have name "NotTheNameOfAnyObject"" failed:
396+
InterfaceAssembly.IBaseInterface does exist
397+
InterfaceAssembly.IChildInterface does exist
447398

448399

449400

450401
----- Complex conditions -----
451402

452-
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interfaces that are any of no objects (always empty)
403+
Query: Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any interfaces that are any of no objects (always empty)
453404
Result: False
454405
Description: InterfaceAssembly.IBaseInterface does not implement any interface
406+
Result: False
407+
Description: InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
455408
Message:
456-
"Interfaces that are "InterfaceAssembly.IBaseInterface" should implement any interfaces that are any of no objects (always empty)" failed:
409+
"Interfaces that are "InterfaceAssembly.IBaseInterface" or "InterfaceAssembly.IChildInterface" should implement any interfaces that are any of no objects (always empty)" failed:
457410
InterfaceAssembly.IBaseInterface does not implement any interface
411+
InterfaceAssembly.IChildInterface only implements InterfaceAssembly.IBaseInterface
458412

459413

460414

0 commit comments

Comments
 (0)