1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System . IO ;
3+ using System . Text . RegularExpressions ;
4+
5+ namespace NLWebNet . Tests . Docker ;
6+
7+ [ TestClass ]
8+ public class DockerfileTests
9+ {
10+ [ TestMethod ]
11+ public void Dockerfile_AllReferencedProjectFilesExist ( )
12+ {
13+ // Arrange
14+ var rootPath = GetRepositoryRoot ( ) ;
15+ var dockerfilePath = Path . Combine ( rootPath , "deployment/docker/Dockerfile" ) ;
16+
17+ Assert . IsTrue ( File . Exists ( dockerfilePath ) , $ "Dockerfile not found at { dockerfilePath } ") ;
18+
19+ var dockerfileContent = File . ReadAllText ( dockerfilePath ) ;
20+
21+ // Extract COPY commands that reference .csproj files
22+ var copyPattern = @"COPY \[""([^""]+\.csproj)"", ""[^""]+/""\]" ;
23+ var matches = Regex . Matches ( dockerfileContent , copyPattern ) ;
24+
25+ // Act & Assert
26+ foreach ( Match match in matches )
27+ {
28+ var projectPath = match . Groups [ 1 ] . Value ;
29+ var fullPath = Path . Combine ( rootPath , projectPath ) ;
30+
31+ Assert . IsTrue ( File . Exists ( fullPath ) ,
32+ $ "Project file referenced in Dockerfile does not exist: { projectPath } (Full path: { fullPath } )") ;
33+ }
34+
35+ // Verify we found at least the expected project files
36+ Assert . IsTrue ( matches . Count >= 3 ,
37+ "Expected to find at least 3 project file references in Dockerfile (NLWebNet, Demo, Tests)" ) ;
38+ }
39+
40+ [ TestMethod ]
41+ public void Dockerfile_DoesNotReferenceAspireHostProject ( )
42+ {
43+ // Arrange
44+ var rootPath = GetRepositoryRoot ( ) ;
45+ var dockerfilePath = Path . Combine ( rootPath , "deployment/docker/Dockerfile" ) ;
46+
47+ Assert . IsTrue ( File . Exists ( dockerfilePath ) , $ "Dockerfile not found at { dockerfilePath } ") ;
48+
49+ var dockerfileContent = File . ReadAllText ( dockerfilePath ) ;
50+
51+ // Act & Assert
52+ Assert . IsFalse ( dockerfileContent . Contains ( "AspireHost" ) ,
53+ "Dockerfile should not contain references to AspireHost project" ) ;
54+ Assert . IsFalse ( dockerfileContent . Contains ( "NLWebNet.AspireHost.csproj" ) ,
55+ "Dockerfile should not contain references to NLWebNet.AspireHost.csproj" ) ;
56+ }
57+
58+ private static string GetRepositoryRoot ( )
59+ {
60+ var currentDirectory = Directory . GetCurrentDirectory ( ) ;
61+ var directory = new DirectoryInfo ( currentDirectory ) ;
62+
63+ while ( directory != null && ! File . Exists ( Path . Combine ( directory . FullName , "NLWebNet.sln" ) ) )
64+ {
65+ directory = directory . Parent ;
66+ }
67+
68+ Assert . IsNotNull ( directory , "Could not find repository root (NLWebNet.sln not found)" ) ;
69+ return directory . FullName ;
70+ }
71+ }
0 commit comments