Skip to content

Commit 6c13d07

Browse files
Merge pull request #393 from TNG/ci/given-objects-that-tests
Add Tests For Object Predicates
2 parents b87dee6 + d3ba159 commit 6c13d07

File tree

71 files changed

+18571
-5523
lines changed

Some content is hidden

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

71 files changed

+18571
-5523
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ list_license.ps1
6262
*.user
6363

6464
# Visual Studio cache/options directory
65-
.vs/
65+
.vs/
66+
67+
# Test Results and Coverage Reports
68+
TestResults/
69+
coveragereport/

ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMemberConditionsDefinition.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace ArchUnitNET.Fluent.Syntax.Elements.Members.MethodMembers
1010
{
1111
public static class MethodMemberConditionsDefinition
1212
{
13+
public static RelationCondition<MethodMember, MethodMember> BeMethodMembersThat()
14+
{
15+
return new RelationCondition<MethodMember, MethodMember>(
16+
ObjectConditionsDefinition<MethodMember>.Be,
17+
"be method members that",
18+
"are not method members that"
19+
);
20+
}
21+
1322
public static ICondition<MethodMember> BeConstructor()
1423
{
1524
return new SimpleCondition<MethodMember>(

ArchUnitNET/Fluent/Syntax/Elements/Members/MethodMembers/MethodMembersShould.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ public class MethodMembersShould
1111
public MethodMembersShould(IArchRuleCreator<MethodMember> ruleCreator)
1212
: base(ruleCreator) { }
1313

14+
public ShouldRelateToMethodMembersThat<
15+
MethodMembersShouldConjunction,
16+
MethodMember
17+
> BeMethodMembersThat()
18+
{
19+
_ruleCreator.BeginComplexCondition(
20+
ArchRuleDefinition.MethodMembers(),
21+
MethodMemberConditionsDefinition.BeMethodMembersThat()
22+
);
23+
return new ShouldRelateToMethodMembersThat<
24+
MethodMembersShouldConjunction,
25+
MethodMember
26+
>(_ruleCreator);
27+
}
28+
1429
public MethodMembersShouldConjunction BeConstructor()
1530
{
1631
_ruleCreator.AddCondition(MethodMemberConditionsDefinition.BeConstructor());

ArchUnitNET/Fluent/Syntax/Elements/ObjectConditionsDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ bool Condition(TRuleType obj, Architecture architecture)
29392939
return true;
29402940
}
29412941

2942-
return new ArchitectureCondition<TRuleType>(Condition, failDescription, description);
2942+
return new ArchitectureCondition<TRuleType>(Condition, description, failDescription);
29432943
}
29442944

29452945
public static ICondition<TRuleType> NotHaveAttributeWithNamedArguments(
@@ -3041,7 +3041,7 @@ bool Condition(TRuleType obj, Architecture architecture)
30413041
return true;
30423042
}
30433043

3044-
return new ArchitectureCondition<TRuleType>(Condition, failDescription, description);
3044+
return new ArchitectureCondition<TRuleType>(Condition, description, failDescription);
30453045
}
30463046

30473047
[Obsolete(

ArchUnitNET/Fluent/Syntax/Elements/ObjectPredicatesDefinition.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ bool Condition(T obj, Architecture architecture)
14391439
goto NextAttribute;
14401440
}
14411441
}
1442-
else if (!argumentList.Contains(arg))
1442+
else if (!attributeArgs.Contains(arg))
14431443
{
14441444
goto NextAttribute;
14451445
}
@@ -1527,7 +1527,7 @@ bool Predicate(T obj, Architecture architecture)
15271527
goto NextAttribute;
15281528
}
15291529
}
1530-
else if (!argumentList.Contains(arg))
1530+
else if (!attributeArgs.Contains(arg))
15311531
{
15321532
goto NextAttribute;
15331533
}
@@ -2344,7 +2344,9 @@ bool Predicate(T obj, Architecture architecture)
23442344
return false;
23452345
}
23462346
}
2347-
else if (attributeArguments.Contains(arg))
2347+
else if (
2348+
attributeArguments.Contains(arg) || typeAttributeArguments.Contains(arg)
2349+
)
23482350
{
23492351
return false;
23502352
}
@@ -2434,7 +2436,7 @@ IEnumerable<object> argumentValues
24342436
)
24352437
{
24362438
string description;
2437-
var argumentValueList = argumentValues?.ToList() ?? new List<object> { null };
2439+
var argumentValueList = argumentValues?.ToList() ?? new List<object> { };
24382440
if (argumentValueList.IsNullOrEmpty())
24392441
{
24402442
description = "do not have attribute \"" + attribute.FullName + "\"";
@@ -2503,7 +2505,7 @@ IEnumerable<object> argumentValues
25032505
)
25042506
{
25052507
string description;
2506-
var argumentValueList = argumentValues?.ToList() ?? new List<object> { null };
2508+
var argumentValueList = argumentValues?.ToList() ?? new List<object> { };
25072509
if (argumentValueList.IsNullOrEmpty())
25082510
{
25092511
description = "do not have attribute \"" + attribute.FullName + "\"";
@@ -2784,7 +2786,7 @@ bool Predicate(T obj, Architecture architecture)
27842786
goto NextAttribute;
27852787
}
27862788
}
2787-
else if (!argumentList.Contains(arg))
2789+
else if (!attributeArgs.Contains(arg))
27882790
{
27892791
goto NextAttribute;
27902792
}
@@ -2872,7 +2874,7 @@ bool Predicate(T obj, Architecture architecture)
28722874
goto NextAttribute;
28732875
}
28742876
}
2875-
else if (!argumentList.Contains(arg))
2877+
else if (!attributeArgs.Contains(arg))
28762878
{
28772879
goto NextAttribute;
28782880
}

ArchUnitNET/Fluent/Syntax/Elements/ShouldRelateToObjectsThat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ IEnumerable<object> argumentValues
11581158
)
11591159
{
11601160
_ruleCreator.ContinueComplexCondition(
1161-
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveAnyAttributesWithArguments(
1161+
ObjectPredicatesDefinition<TReferenceType>.DoNotHaveAttributeWithArguments(
11621162
attribute,
11631163
argumentValues
11641164
)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ bool Condition(TRuleType ruleType)
165165
return new SimpleCondition<TRuleType>(Condition, description, failDescription);
166166
}
167167

168+
public static RelationCondition<TRuleType, IType> BeTypesThat()
169+
{
170+
return new RelationCondition<TRuleType, IType>(
171+
ObjectConditionsDefinition<TRuleType>.Be,
172+
"be types that",
173+
"are not types that"
174+
);
175+
}
176+
168177
public static ICondition<TRuleType> BeAssignableTo(
169178
IType firstType,
170179
params IType[] moreTypes

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ public TRuleTypeShouldConjunction BeAssignableTo(
5757
return Create<TRuleTypeShouldConjunction, TRuleType>(_ruleCreator);
5858
}
5959

60+
public ShouldRelateToTypesThat<TRuleTypeShouldConjunction, IType, TRuleType> BeTypesThat()
61+
{
62+
_ruleCreator.BeginComplexCondition(
63+
ArchRuleDefinition.Types(true),
64+
TypeConditionsDefinition<TRuleType>.BeTypesThat()
65+
);
66+
return new ShouldRelateToTypesThat<TRuleTypeShouldConjunction, IType, TRuleType>(
67+
_ruleCreator
68+
);
69+
}
70+
6071
public TRuleTypeShouldConjunction BeAssignableTo(IType firstType, params IType[] moreTypes)
6172
{
6273
_ruleCreator.AddCondition(

ArchUnitNETTests/ArchUnitNETTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
</ItemGroup>
4646
<ItemGroup>
4747
<Folder Include="Dependencies\cpplib\" />
48+
<Folder Include="Fluent\Syntax\Elements\Snapshots\" />
4849
</ItemGroup>
4950
<ItemGroup>
5051
<Reference Include="CppDllTest">

ArchUnitNETTests/AssemblyTestHelper/AssemblyTestHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public void AddSnapshotHeader(string header)
2525
snapshot.AppendLine("===== " + header + " =====\n");
2626
}
2727

28+
public void AddSnapshotSubHeader(string subHeader)
29+
{
30+
snapshot.AppendLine("----- " + subHeader + " -----\n");
31+
}
32+
2833
private string FormatSnapshot(IArchRule rule, IEnumerable<EvaluationResult> results)
2934
{
3035
var formatted = new StringBuilder();

0 commit comments

Comments
 (0)