Skip to content

Commit 045717a

Browse files
committed
add tests for record type
1 parent d2b14ed commit 045717a

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/NetArchTest.Rules/Functions/FunctionDelegates.Traits.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ internal static IEnumerable<TypeSpec> BeInterface(IEnumerable<TypeSpec> input, b
7171
return input.Where(c => !c.Definition.IsInterface);
7272
}
7373
}
74+
// todo
75+
internal static IEnumerable<TypeSpec> BeRecord(IEnumerable<TypeSpec> input, bool condition)
76+
{
77+
if (condition)
78+
{
79+
return Enumerable.Empty<TypeSpec>();
80+
}
81+
else
82+
{
83+
return Enumerable.Empty<TypeSpec>();
84+
}
85+
}
7486

7587
// Modifiers
7688

src/NetArchTest.Rules/Predicate.Traits.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,27 @@ public PredicateList AreNotEnums()
102102
{
103103
AddFunctionCall(x => FunctionDelegates.BeEnum(x, false));
104104
return CreatePredicateList();
105-
}
105+
}
106+
107+
/// <summary>
108+
/// Selects types that are records.
109+
/// </summary>
110+
/// <returns>An updated set of predicates that can be applied to a list of types.</returns>
111+
internal PredicateList AreRecords()
112+
{
113+
AddFunctionCall(x => FunctionDelegates.BeRecord(x, true));
114+
return CreatePredicateList();
115+
}
116+
117+
/// <summary>
118+
/// Selects types that are not records.
119+
/// </summary>
120+
/// <returns>An updated set of predicates that can be applied to a list of types.</returns>
121+
internal PredicateList AreNotRecords()
122+
{
123+
AddFunctionCall(x => FunctionDelegates.BeRecord(x, false));
124+
return CreatePredicateList();
125+
}
106126

107127
/// <summary>
108128
/// Selects types that have generic parameters.

test/NetArchTest.Rules.UnitTests/PredicateTests_Types.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void AreNotClasses()
4040
}
4141

4242
[Fact(DisplayName = "AreStructures")]
43-
public void AreStructuresd()
43+
public void AreStructures()
4444
{
4545
var result = GetTypesThat().AreStructures().GetReflectionTypes();
4646

@@ -136,5 +136,27 @@ public void AreNotStatic()
136136
Assert.Contains<Type>(typeof(ExampleClass), result);
137137
Assert.Contains<Type>(typeof(IExampleInterface), result);
138138
}
139+
140+
// todo
141+
[Fact(DisplayName = "AreRecords", Skip = "not implemented yet")]
142+
public void AreRecords()
143+
{
144+
var result = GetTypesThat().AreRecords().GetReflectionTypes();
145+
146+
Assert.Equal(2, result.Count());
147+
Assert.Contains<Type>(typeof(ExampleRecordClass), result);
148+
Assert.Contains<Type>(typeof(ExampleRecordStruct), result);
149+
}
150+
151+
// todo
152+
[Fact(DisplayName = "AreNotRecords", Skip = "not implemented yet")]
153+
public void AreNotRecords()
154+
{
155+
var result = GetTypesThat().AreNotRecords().GetReflectionTypes();
156+
157+
Assert.Equal(6, result.Count());
158+
Assert.Contains<Type>(typeof(ExampleClass), result);
159+
Assert.Contains<Type>(typeof(ExampleStruct), result);
160+
}
139161
}
140162
}

0 commit comments

Comments
 (0)