22using ControlR . DesktopClient . Common . ServiceInterfaces ;
33using ControlR . DesktopClient . Services ;
44using ControlR . Libraries . Shared . Dtos . IpcDtos ;
5- using Microsoft . Extensions . Hosting ;
5+ using ControlR . Tests . TestingUtilities ;
6+ using Microsoft . Extensions . Logging ;
67using Microsoft . Extensions . Options ;
78using Moq ;
89
910namespace ControlR . DesktopClient . Tests . Startup ;
1011
1112public class RemoteControlHostDependencyTests
1213{
13- [ Fact ]
14- internal void CreateRemoteControlHostBuilder_InDevelopment_ValidatesDependencyGraph ( )
14+ [ LinuxOnlyTheory ]
15+ [ InlineData ( DesktopEnvironmentType . X11 , "Development" ) ]
16+ [ InlineData ( DesktopEnvironmentType . Wayland , "Development" ) ]
17+ [ InlineData ( DesktopEnvironmentType . X11 , "Production" ) ]
18+ [ InlineData ( DesktopEnvironmentType . Wayland , "Production" ) ]
19+ internal void CreateRemoteControlHostBuilder_InDevelopment_ValidatesDependencyGraph_Linux ( DesktopEnvironmentType desktopEnvironment , string environment )
1520 {
16- // Arrange
17- var mockIpcAccessor = new Mock < IIpcClientAccessor > ( ) ;
18- var mockUserInteractionService = new Mock < IUserInteractionService > ( ) ;
19- var mockDesktopClientOptions = new Mock < IOptionsMonitor < DesktopClientOptions > > ( ) ;
20- var mockLogger = new Mock < Microsoft . Extensions . Logging . ILogger < RemoteControlHostManager > > ( ) ;
21-
22- mockDesktopClientOptions
23- . Setup ( x => x . CurrentValue )
24- . Returns ( new DesktopClientOptions { InstanceId = Guid . NewGuid ( ) . ToString ( ) } ) ;
25-
26- var hostManager = new RemoteControlHostManager (
27- mockUserInteractionService . Object ,
28- mockDesktopClientOptions . Object ,
29- mockIpcAccessor . Object ,
30- mockLogger . Object ) ;
31-
32- var requestDto = new RemoteControlRequestIpcDto (
33- SessionId : Guid . NewGuid ( ) ,
34- WebsocketUri : new Uri ( "wss://localhost:5001" ) ,
35- TargetSystemSession : 1 ,
36- TargetProcessId : 1234 ,
37- ViewerConnectionId : "test-connection-id" ,
38- DeviceId : Guid . NewGuid ( ) ,
39- NotifyUserOnSessionStart : false ,
40- RequireConsent : false ,
41- DataFolder : Path . GetTempPath ( ) ,
42- ViewerName : "Test Viewer" ) ;
43-
44- // Configure environment as Development for validation
45- Environment . SetEnvironmentVariable ( "DOTNET_ENVIRONMENT" , Environments . Development ) ;
46-
47- try
21+ switch ( desktopEnvironment )
4822 {
49- // Act - Get the builder using the internal method
50- var builder = hostManager . CreateRemoteControlHostBuilder ( requestDto ) ;
23+ case DesktopEnvironmentType . X11 :
24+ Environment . SetEnvironmentVariable ( "DISPLAY" , ":0" ) ;
25+ Environment . SetEnvironmentVariable ( "WAYLAND_DISPLAY" , null ) ;
26+ break ;
27+ case DesktopEnvironmentType . Wayland :
28+ Environment . SetEnvironmentVariable ( "WAYLAND_DISPLAY" , "wayland-0" ) ;
29+ Environment . SetEnvironmentVariable ( "DISPLAY" , null ) ;
30+ break ;
31+ }
32+ CreateRemoteControlHostBuilder_ValidatesDependencyGraph ( environment ) ;
33+ }
5134
52- // Assert - In Development, Build() validates the entire dependency graph
53- // and throws if any registered services have unresolved dependencies.
54- using var host = builder . Build ( ) ;
35+ [ MacOnlyTheory ]
36+ [ InlineData ( "Development" ) ]
37+ [ InlineData ( "Production" ) ]
38+ internal void CreateRemoteControlHostBuilder_InDevelopment_ValidatesDependencyGraph_Mac ( string environment )
39+ {
40+ CreateRemoteControlHostBuilder_ValidatesDependencyGraph ( environment ) ;
41+ }
5542
56- Assert . NotNull ( host ) ;
57- }
58- finally
59- {
60- Environment . SetEnvironmentVariable ( "DOTNET_ENVIRONMENT" , null ) ;
61- }
43+ [ WindowsOnlyTheory ]
44+ [ InlineData ( "Development" ) ]
45+ [ InlineData ( "Production" ) ]
46+ internal void CreateRemoteControlHostBuilder_InDevelopment_ValidatesDependencyGraph_Windows ( string environment )
47+ {
48+ CreateRemoteControlHostBuilder_ValidatesDependencyGraph ( environment ) ;
6249 }
6350
64- [ Fact ]
65- internal void CreateRemoteControlHostBuilder_InProduction_Succeeds ( )
51+ private void CreateRemoteControlHostBuilder_ValidatesDependencyGraph ( string environment )
6652 {
6753 // Arrange
6854 var mockIpcAccessor = new Mock < IIpcClientAccessor > ( ) ;
6955 var mockUserInteractionService = new Mock < IUserInteractionService > ( ) ;
7056 var mockDesktopClientOptions = new Mock < IOptionsMonitor < DesktopClientOptions > > ( ) ;
71- var mockLogger = new Mock < Microsoft . Extensions . Logging . ILogger < RemoteControlHostManager > > ( ) ;
57+ var mockLogger = new Mock < ILogger < RemoteControlHostManager > > ( ) ;
7258
7359 mockDesktopClientOptions
7460 . Setup ( x => x . CurrentValue )
75- . Returns ( new DesktopClientOptions { InstanceId = Guid . NewGuid ( ) . ToString ( ) } ) ;
61+ . Returns ( new DesktopClientOptions { InstanceId = $ "test- { Guid . NewGuid ( ) } " } ) ;
7662
7763 var hostManager = new RemoteControlHostManager (
7864 mockUserInteractionService . Object ,
@@ -92,16 +78,16 @@ internal void CreateRemoteControlHostBuilder_InProduction_Succeeds()
9278 DataFolder : Path . GetTempPath ( ) ,
9379 ViewerName : "Test Viewer" ) ;
9480
95- // Configure environment as Production
96- Environment . SetEnvironmentVariable ( "DOTNET_ENVIRONMENT" , Environments . Production ) ;
81+ // Configure environment as Development for validation
82+ Environment . SetEnvironmentVariable ( "DOTNET_ENVIRONMENT" , environment ) ;
9783
9884 try
9985 {
10086 // Act - Get the builder using the internal method
10187 var builder = hostManager . CreateRemoteControlHostBuilder ( requestDto ) ;
10288
103- // Assert - In Production , Build() does not validate the dependency graph,
104- // but we still verify it builds successfully .
89+ // Assert - In Development , Build() validates the entire dependency graph
90+ // and throws if any registered services have unresolved dependencies .
10591 using var host = builder . Build ( ) ;
10692
10793 Assert . NotNull ( host ) ;
0 commit comments