-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify with one project and new namespace tests to enforce correct … (
#39) * Simplify with one project and new namespace tests to enforce correct usage * Readme update
- Loading branch information
Showing
117 changed files
with
384 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using CodeHub.Shared.Services; | ||
using CodeHub.Core.Shared.Services; | ||
|
||
namespace CodeHub.Api.Jobs; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
....Tests/Extensions/AzureExtensionsTests.cs → .../Azure/Extensions/AzureExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
.../Extensions/AzureDevOpsExtensionsTests.cs → .../Extensions/AzureDevOpsExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...Tests/Extensions/GitHubExtensionsTests.cs → ...itHub/Extensions/GitHubExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...Tests/Extensions/GitLabExtensionsTests.cs → ...itLab/Extensions/GitLabExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace CodeHub.Core.Tests; | ||
|
||
public sealed class NamespaceUsageTests | ||
{ | ||
private static readonly string[] AllowedNamespaces = | ||
{ | ||
"CodeHub.Core.Shared" | ||
}; | ||
|
||
private static string GetRootPath() | ||
{ | ||
var baseDir = AppDomain.CurrentDomain.BaseDirectory; | ||
var solutionDir = | ||
Directory.GetParent(baseDir)?.Parent?.Parent?.Parent?.Parent?.FullName ?? string.Empty; | ||
return Path.Combine(solutionDir, "CodeHub.Core"); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Azure")] | ||
[InlineData("AzureDevOps")] | ||
[InlineData("GitHub")] | ||
[InlineData("GitLab")] | ||
public void UsingStatements_ShouldOnlyAllowThirdPartySelfAndSharedUsings(string moduleName) | ||
{ | ||
var rootPath = GetRootPath(); | ||
var modulePath = Path.Combine(rootPath, moduleName); | ||
var files = Directory.GetFiles(modulePath, "*.cs", SearchOption.AllDirectories); | ||
|
||
foreach (var file in files) | ||
{ | ||
var content = File.ReadAllText(file); | ||
var usings = Regex.Matches(content, @"^\s*using\s+([\w\.]+);", RegexOptions.Multiline) | ||
.Select(m => m.Groups[1].Value) | ||
.ToList(); | ||
|
||
foreach (var usedNamespace in usings) | ||
{ | ||
if (!usedNamespace.StartsWith("CodeHub.Core")) continue; | ||
|
||
var isAllowed = usedNamespace.StartsWith($"CodeHub.Core.{moduleName}") || | ||
AllowedNamespaces.Any(n => usedNamespace.StartsWith(n)); | ||
Assert.True(isAllowed, $"Disallowed namespace '{usedNamespace}' found in file '{file}'"); | ||
} | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...lidation/ValidationBuilderTestSettings.cs → ...lidation/ValidationBuilderTestSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ests/Validation/ValidationBuilderTests.cs → ...ared/Validation/ValidationBuilderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...tform.Azure/Extensions/AzureExtensions.cs → ....Core/Azure/Extensions/AzureExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ub.Platform.Azure/Models/AzureResource.cs → ...odeHub.Core/Azure/Models/AzureResource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.