Skip to content

Commit

Permalink
add tests for record type
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Nov 20, 2023
1 parent d2b14ed commit 045717a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/NetArchTest.Rules/Functions/FunctionDelegates.Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ internal static IEnumerable<TypeSpec> BeInterface(IEnumerable<TypeSpec> input, b
return input.Where(c => !c.Definition.IsInterface);
}
}
// todo
internal static IEnumerable<TypeSpec> BeRecord(IEnumerable<TypeSpec> input, bool condition)
{
if (condition)
{
return Enumerable.Empty<TypeSpec>();
}
else
{
return Enumerable.Empty<TypeSpec>();
}
}

// Modifiers

Expand Down
22 changes: 21 additions & 1 deletion src/NetArchTest.Rules/Predicate.Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,27 @@ public PredicateList AreNotEnums()
{
AddFunctionCall(x => FunctionDelegates.BeEnum(x, false));
return CreatePredicateList();
}
}

/// <summary>
/// Selects types that are records.
/// </summary>
/// <returns>An updated set of predicates that can be applied to a list of types.</returns>
internal PredicateList AreRecords()
{
AddFunctionCall(x => FunctionDelegates.BeRecord(x, true));
return CreatePredicateList();
}

/// <summary>
/// Selects types that are not records.
/// </summary>
/// <returns>An updated set of predicates that can be applied to a list of types.</returns>
internal PredicateList AreNotRecords()
{
AddFunctionCall(x => FunctionDelegates.BeRecord(x, false));
return CreatePredicateList();
}

/// <summary>
/// Selects types that have generic parameters.
Expand Down
24 changes: 23 additions & 1 deletion test/NetArchTest.Rules.UnitTests/PredicateTests_Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void AreNotClasses()
}

[Fact(DisplayName = "AreStructures")]
public void AreStructuresd()
public void AreStructures()
{
var result = GetTypesThat().AreStructures().GetReflectionTypes();

Expand Down Expand Up @@ -136,5 +136,27 @@ public void AreNotStatic()
Assert.Contains<Type>(typeof(ExampleClass), result);
Assert.Contains<Type>(typeof(IExampleInterface), result);
}

// todo
[Fact(DisplayName = "AreRecords", Skip = "not implemented yet")]
public void AreRecords()
{
var result = GetTypesThat().AreRecords().GetReflectionTypes();

Assert.Equal(2, result.Count());
Assert.Contains<Type>(typeof(ExampleRecordClass), result);
Assert.Contains<Type>(typeof(ExampleRecordStruct), result);
}

// todo
[Fact(DisplayName = "AreNotRecords", Skip = "not implemented yet")]
public void AreNotRecords()
{
var result = GetTypesThat().AreNotRecords().GetReflectionTypes();

Assert.Equal(6, result.Count());
Assert.Contains<Type>(typeof(ExampleClass), result);
Assert.Contains<Type>(typeof(ExampleStruct), result);
}
}
}

0 comments on commit 045717a

Please sign in to comment.