1
+ // SPDX-FileCopyrightText: 2017-2024 TRUMPF Laser GmbH
2
+ //
3
+ // SPDX-License-Identifier: MPL-2.0
4
+
5
+ namespace SAF . Hosting . Tests ;
6
+
7
+ using Contracts ;
8
+ using NSubstitute ;
9
+ using Xunit ;
10
+
11
+ public class ServiceHostInfoTests
12
+ {
13
+ [ Fact ]
14
+ public void IdReturnsInitializedIdWhenIdInOptionsIsNotNull ( )
15
+ {
16
+ // Arrange
17
+ var options = new ServiceHostInfoOptions { Id = "test-id" } ;
18
+ var initializeId = Substitute . For < Func < string > > ( ) ;
19
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
20
+
21
+ // Act
22
+ var id = serviceHostInfo . Id ;
23
+
24
+ // Assert
25
+ Assert . Equal ( "test-id" , id ) ;
26
+ initializeId . DidNotReceive ( ) . Invoke ( ) ;
27
+ }
28
+
29
+ [ Fact ]
30
+ public void IdInvokesInitializeIdWhenIdInOptionsIsNull ( )
31
+ {
32
+ // Arrange
33
+ var options = new ServiceHostInfoOptions { Id = null } ;
34
+ var initializeId = Substitute . For < Func < string > > ( ) ;
35
+ initializeId . Invoke ( ) . Returns ( "initialized-id" ) ;
36
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
37
+
38
+ // Act
39
+ var id = serviceHostInfo . Id ;
40
+
41
+ // Assert
42
+ Assert . Equal ( "initialized-id" , id ) ;
43
+ initializeId . Received ( 1 ) . Invoke ( ) ;
44
+ }
45
+
46
+ [ Fact ]
47
+ public void ServiceHostTypeReturnsServiceHostTypeFromOptions ( )
48
+ {
49
+ // Arrange
50
+ var options = new ServiceHostInfoOptions { ServiceHostType = "test-type" } ;
51
+ var initializeId = Substitute . For < Func < string > > ( ) ;
52
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
53
+
54
+ // Act
55
+ var serviceHostType = serviceHostInfo . ServiceHostType ;
56
+
57
+ // Assert
58
+ Assert . Equal ( "test-type" , serviceHostType ) ;
59
+ }
60
+
61
+ [ Fact ]
62
+ public void FileSystemUserBasePathReturnsFileSystemUserBasePathFromOptions ( )
63
+ {
64
+ // Arrange
65
+ var options = new ServiceHostInfoOptions { FileSystemUserBasePath = "user-base-path" } ;
66
+ var initializeId = Substitute . For < Func < string > > ( ) ;
67
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
68
+
69
+ // Act
70
+ var fileSystemUserBasePath = serviceHostInfo . FileSystemUserBasePath ;
71
+
72
+ // Assert
73
+ Assert . Equal ( "user-base-path" , fileSystemUserBasePath ) ;
74
+ }
75
+
76
+ [ Fact ]
77
+ public void FileSystemInstallationPathReturnsFileSystemInstallationPathFromOptions ( )
78
+ {
79
+ // Arrange
80
+ var options = new ServiceHostInfoOptions { FileSystemInstallationPath = "installation-path" } ;
81
+ var initializeId = Substitute . For < Func < string > > ( ) ;
82
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
83
+
84
+ // Act
85
+ var fileSystemInstallationPath = serviceHostInfo . FileSystemInstallationPath ;
86
+
87
+ // Assert
88
+ Assert . Equal ( "installation-path" , fileSystemInstallationPath ) ;
89
+ }
90
+
91
+ [ Fact ]
92
+ public void UpSinceReturnsCurrentDateTimeOffset ( )
93
+ {
94
+ // Arrange
95
+ var options = new ServiceHostInfoOptions ( ) ;
96
+ var initializeId = Substitute . For < Func < string > > ( ) ;
97
+ var serviceHostInfo = new ServiceHostInfo ( options , initializeId ) ;
98
+
99
+ // Act
100
+ var upSince = serviceHostInfo . UpSince ;
101
+
102
+ // Assert
103
+ Assert . True ( ( DateTimeOffset . Now - upSince ) . TotalSeconds < 1 ) ;
104
+ }
105
+ }
0 commit comments