Skip to content

Commit

Permalink
Added conditions for NestedPublic and NestedPrivate.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorris committed Aug 24, 2019
1 parent 11c8f4a commit 7cd3ee4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/NetArchTest.Rules/Conditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ public ConditionList BeNested()
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are nested and public.
/// </summary>
/// <returns>An updated set of conditions that can be applied to a list of types.</returns>
public ConditionList BeNestedPublic()
{
_sequence.AddFunctionCall(FunctionDelegates.BeNestedPublic, true, true);
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are nested and private.
/// </summary>
/// <returns>An updated set of conditions that can be applied to a list of types.</returns>
public ConditionList BeNestedPrivate()
{
_sequence.AddFunctionCall(FunctionDelegates.BeNestedPrivate, true, true);
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are not nested.
/// </summary>
Expand All @@ -294,6 +314,26 @@ public ConditionList NotBeNested()
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are not nested and public.
/// </summary>
/// <returns>An updated set of conditions that can be applied to a list of types.</returns>
public ConditionList NotBeNestedPublic()
{
_sequence.AddFunctionCall(FunctionDelegates.BeNestedPublic, true, false);
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are not nested and private.
/// </summary>
/// <returns>An updated set of conditions that can be applied to a list of types.</returns>
public ConditionList NotBeNestedPrivate()
{
_sequence.AddFunctionCall(FunctionDelegates.BeNestedPrivate, true, false);
return new ConditionList(_types, _should, _sequence);
}

/// <summary>
/// Selects types that are have public scope.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions src/NetArchTest.Rules/NetArchTest.Rules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 62 additions & 1 deletion test/NetArchTest.Rules.UnitTests/ConditionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down

0 comments on commit 7cd3ee4

Please sign in to comment.