Put layer and wall-clock bans in one test project so Content and Protocol fail the same way as People.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
using HSchool.Ai;
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Protocol;
|
||||
using HSchool.Schedule;
|
||||
using HSchool.Simulation;
|
||||
|
||||
namespace HSchool.Architecture.Tests;
|
||||
|
||||
public class LayerBoundaryTests
|
||||
{
|
||||
private static readonly string[] LibraryFolders =
|
||||
[
|
||||
"HSchool.Protocol",
|
||||
"HSchool.Content",
|
||||
"HSchool.People",
|
||||
"HSchool.Schedule",
|
||||
"HSchool.Ai",
|
||||
"HSchool.Simulation"
|
||||
];
|
||||
|
||||
private static readonly string[] OldTestProjects =
|
||||
[
|
||||
"HSchool.People.Tests",
|
||||
"HSchool.Ai.Tests",
|
||||
"HSchool.Schedule.Tests",
|
||||
"HSchool.Simulation.Tests"
|
||||
];
|
||||
|
||||
[Fact]
|
||||
public void Protocol_DoesNotReferenceArchAspNetSocketsContentOrSimulation()
|
||||
{
|
||||
var names = References(typeof(ProtocolCodec));
|
||||
AssertNoArchAspNetOrSockets(names);
|
||||
Assert.DoesNotContain("HSchool.Content", names, StringComparer.Ordinal);
|
||||
Assert.DoesNotContain("HSchool.People", names, StringComparer.Ordinal);
|
||||
Assert.DoesNotContain("HSchool.Schedule", names, StringComparer.Ordinal);
|
||||
Assert.DoesNotContain("HSchool.Ai", names, StringComparer.Ordinal);
|
||||
Assert.DoesNotContain("HSchool.Simulation", names, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Content_DoesNotReferenceArchAspNetSocketsProtocolOrSimulation()
|
||||
{
|
||||
var names = References(typeof(MapLayout));
|
||||
AssertNoArchAspNetOrSockets(names);
|
||||
Assert.DoesNotContain("HSchool.Protocol", names, StringComparer.Ordinal);
|
||||
Assert.DoesNotContain("HSchool.Simulation", names, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(RosterGenerator))]
|
||||
[InlineData(typeof(TimetablePlanner))]
|
||||
[InlineData(typeof(WalkGraph))]
|
||||
public void PeopleScheduleAi_DoNotReferenceArchAspNetOrSockets(Type marker)
|
||||
{
|
||||
AssertNoArchAspNetOrSockets(References(marker));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Simulation_DoesNotReferenceAspNetOrSockets()
|
||||
{
|
||||
var names = References(typeof(School));
|
||||
Assert.DoesNotContain(names, name => name.Contains("AspNet", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("Sockets", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SixLibrarySources_DoNotUseWallClock()
|
||||
{
|
||||
foreach (var folder in LibraryFolders)
|
||||
{
|
||||
var root = Path.Combine(RepoRoot(), "src", folder);
|
||||
Assert.True(Directory.Exists(root), root);
|
||||
foreach (var path in SourceFiles(root))
|
||||
{
|
||||
var text = File.ReadAllText(path);
|
||||
Assert.DoesNotContain("DateTime.Now", text, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("DateTime.UtcNow", text, StringComparison.Ordinal);
|
||||
// Unused `using System.Net.Http` never becomes a referenced assembly.
|
||||
Assert.DoesNotContain("System.Net.Http", text, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PeopleAiScheduleSimulationTests_NoLongerCarryLayerBans()
|
||||
{
|
||||
foreach (var project in OldTestProjects)
|
||||
{
|
||||
var root = Path.Combine(RepoRoot(), "tests", project);
|
||||
Assert.True(Directory.Exists(root), root);
|
||||
foreach (var path in SourceFiles(root))
|
||||
{
|
||||
var text = File.ReadAllText(path);
|
||||
Assert.DoesNotContain("Assembly_DoesNotReference", text, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("Sources_DoNotUseWallClock", text, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> SourceFiles(string root) =>
|
||||
Directory.EnumerateFiles(root, "*.cs", SearchOption.AllDirectories)
|
||||
.Where(path => path.Split(Path.DirectorySeparatorChar).All(part => part is not ("bin" or "obj")));
|
||||
|
||||
private static string[] References(Type marker) =>
|
||||
[.. marker.Assembly.GetReferencedAssemblies().Select(assembly => assembly.Name!)];
|
||||
|
||||
private static void AssertNoArchAspNetOrSockets(IEnumerable<string> names)
|
||||
{
|
||||
Assert.DoesNotContain(names, name => name.StartsWith("Arch", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("AspNet", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("Sockets", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static string RepoRoot()
|
||||
{
|
||||
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "h-school.sln")))
|
||||
{
|
||||
dir = dir.Parent;
|
||||
}
|
||||
|
||||
if (dir is null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not find h-school.sln from the test output directory.");
|
||||
}
|
||||
|
||||
return dir.FullName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user