diff --git a/src/NetArchTest.Rules/Conditions.cs b/src/NetArchTest.Rules/Conditions.cs
index 139ae73..3663fa7 100644
--- a/src/NetArchTest.Rules/Conditions.cs
+++ b/src/NetArchTest.Rules/Conditions.cs
@@ -284,6 +284,26 @@ public ConditionList BeNested()
return new ConditionList(_types, _should, _sequence);
}
+ ///
+ /// Selects types that are nested and public.
+ ///
+ /// An updated set of conditions that can be applied to a list of types.
+ public ConditionList BeNestedPublic()
+ {
+ _sequence.AddFunctionCall(FunctionDelegates.BeNestedPublic, true, true);
+ return new ConditionList(_types, _should, _sequence);
+ }
+
+ ///
+ /// Selects types that are nested and private.
+ ///
+ /// An updated set of conditions that can be applied to a list of types.
+ public ConditionList BeNestedPrivate()
+ {
+ _sequence.AddFunctionCall(FunctionDelegates.BeNestedPrivate, true, true);
+ return new ConditionList(_types, _should, _sequence);
+ }
+
///
/// Selects types that are not nested.
///
@@ -294,6 +314,26 @@ public ConditionList NotBeNested()
return new ConditionList(_types, _should, _sequence);
}
+ ///
+ /// Selects types that are not nested and public.
+ ///
+ /// An updated set of conditions that can be applied to a list of types.
+ public ConditionList NotBeNestedPublic()
+ {
+ _sequence.AddFunctionCall(FunctionDelegates.BeNestedPublic, true, false);
+ return new ConditionList(_types, _should, _sequence);
+ }
+
+ ///
+ /// Selects types that are not nested and private.
+ ///
+ /// An updated set of conditions that can be applied to a list of types.
+ public ConditionList NotBeNestedPrivate()
+ {
+ _sequence.AddFunctionCall(FunctionDelegates.BeNestedPrivate, true, false);
+ return new ConditionList(_types, _should, _sequence);
+ }
+
///
/// Selects types that are have public scope.
///
diff --git a/src/NetArchTest.Rules/NetArchTest.Rules.xml b/src/NetArchTest.Rules/NetArchTest.Rules.xml
index 0bb026f..6ed36f4 100644
--- a/src/NetArchTest.Rules/NetArchTest.Rules.xml
+++ b/src/NetArchTest.Rules/NetArchTest.Rules.xml
@@ -229,12 +229,36 @@
An updated set of conditions that can be applied to a list of types.
+
+
+ Selects types that are nested and public.
+
+ An updated set of conditions that can be applied to a list of types.
+
+
+
+ Selects types that are nested and private.
+
+ An updated set of conditions that can be applied to a list of types.
+
Selects types that are not nested.
An updated set of conditions that can be applied to a list of types.
+
+
+ Selects types that are not nested and public.
+
+ An updated set of conditions that can be applied to a list of types.
+
+
+
+ Selects types that are not nested and private.
+
+ An updated set of conditions that can be applied to a list of types.
+
Selects types that are have public scope.
diff --git a/test/NetArchTest.Rules.UnitTests/ConditionTests.cs b/test/NetArchTest.Rules.UnitTests/ConditionTests.cs
index dbdc1ba..da25b27 100644
--- a/test/NetArchTest.Rules.UnitTests/ConditionTests.cs
+++ b/test/NetArchTest.Rules.UnitTests/ConditionTests.cs
@@ -331,18 +331,49 @@ public void AreNotInterfaces_MatchesFound_ClassesSelected()
[Fact(DisplayName = "Types can be selected if they are nested.")]
public void AreNested_MatchesFound_ClassesSelected()
{
+ // Include both public and private nested classes
var result = Types
.InAssembly(Assembly.GetAssembly(typeof(ClassA1)))
.That()
.ResideInNamespace("NetArchTest.TestStructure.Nested")
.And()
- .HaveName(typeof(NestedPublicClass).Name)
+ .HaveNameEndingWith("Class")
.Should()
.BeNested().GetResult();
Assert.True(result.IsSuccessful);
}
+ [Fact(DisplayName = "Types can be selected if they are nested and public.")]
+ public void AreNestedPublic_MatchesFound_ClassesSelected()
+ {
+ var result = Types
+ .InAssembly(Assembly.GetAssembly(typeof(ClassA1)))
+ .That()
+ .ResideInNamespace("NetArchTest.TestStructure.Nested")
+ .And()
+ .HaveName(typeof(NestedPublicClass).Name)
+ .Should()
+ .BeNestedPublic().GetResult();
+
+ Assert.True(result.IsSuccessful);
+ }
+
+ [Fact(DisplayName = "Types can be selected if they are nested and private.")]
+ public void AreNestedPrivate_MatchesFound_ClassesSelected()
+ {
+ var result = Types
+ .InAssembly(Assembly.GetAssembly(typeof(ClassA1)))
+ .That()
+ .ResideInNamespace("NetArchTest.TestStructure.Nested")
+ .And()
+ .HaveName("NestedPrivateClass")
+ .Should()
+ .BeNestedPrivate().GetResult();
+
+ Assert.True(result.IsSuccessful);
+ }
+
[Fact(DisplayName = "Types can be selected if they are not nested.")]
public void AreNotNested_MatchesFound_ClassesSelected()
{
@@ -358,6 +389,36 @@ public void AreNotNested_MatchesFound_ClassesSelected()
Assert.True(result.IsSuccessful);
}
+ [Fact(DisplayName = "Types can be selected if they are not nested and public.")]
+ public void AreNotNestedPublic_MatchesFound_ClassesSelected()
+ {
+ var result = Types
+ .InAssembly(Assembly.GetAssembly(typeof(ClassA1)))
+ .That()
+ .ResideInNamespace("NetArchTest.TestStructure.Nested")
+ .And()
+ .HaveNameStartingWith("NestedPrivate")
+ .Should()
+ .NotBeNestedPublic().GetResult();
+
+ Assert.True(result.IsSuccessful);
+ }
+
+ [Fact(DisplayName = "Types can be selected if they are not nested.")]
+ public void AreNotNestedPrivate_MatchesFound_ClassesSelected()
+ {
+ var result = Types
+ .InAssembly(Assembly.GetAssembly(typeof(ClassA1)))
+ .That()
+ .ResideInNamespace("NetArchTest.TestStructure.Nested")
+ .And()
+ .HaveNameStartingWith("NestedPublic")
+ .Should()
+ .NotBeNestedPrivate().GetResult();
+
+ Assert.True(result.IsSuccessful);
+ }
+
[Fact(DisplayName = "Types can be selected for being declared as public.")]
public void ArePublic_MatchesFound_ClassSelected()
{