-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientInfoTest.cs
More file actions
162 lines (126 loc) · 4.24 KB
/
ClientInfoTest.cs
File metadata and controls
162 lines (126 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using Xunit;
namespace LabTracker.Tests;
public class ClientInfoTest
{
[Fact]
public void GetClientId_WhenBothMacAndHostnameNull_ShouldReturnUnknown()
{
// Arrange
var clientInfo = new ClientInfo(null, "192.168.1.100", null, 30);
// Act
var result = clientInfo.GetClientId();
// Assert
Assert.Equal("Unknown", result);
}
[Fact]
public void IsIdle_WhenIdleTimeGreaterThanMax_ShouldReturnTrue()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 600);
// Act
var result = clientInfo.IsIdle(maxIdleSeconds: 300);
// Assert
Assert.True(result);
}
[Fact]
public void IsIdle_WhenIdleTimeLessThanMax_ShouldReturnFalse()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 150);
// Act
var result = clientInfo.IsIdle(maxIdleSeconds: 300);
// Assert
Assert.False(result);
}
[Fact]
public void IsIdle_WhenIdleTimeIsNull_ShouldReturnFalse()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", null);
// Act
var result = clientInfo.IsIdle(maxIdleSeconds: 300);
// Assert
Assert.False(result);
}
[Fact]
public void DisplayName_WhenHostnameExists_ShouldReturnHostname()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 30);
// Act
var result = clientInfo.DisplayName;
// Assert
Assert.Equal("laptop", result);
}
[Fact]
public void DisplayName_WhenHostnameNullButMacExists_ShouldReturnMac()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", null, 30);
// Act
var result = clientInfo.DisplayName;
// Assert
Assert.Equal("AA:BB:CC:DD:EE:FF", result);
}
[Fact]
public void DisplayName_WhenBothHostnameAndMacNull_ShouldReturnUnknown()
{
// Arrange
var clientInfo = new ClientInfo(null, "192.168.1.100", null, 30);
// Act
var result = clientInfo.DisplayName;
// Assert
Assert.Equal("Unknown", result);
}
[Fact]
public void ToString_WhenHostnameExists_ShouldFormatWithHostname()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 30);
// Act
var result = clientInfo.ToString();
// Assert
Assert.Equal("AA:BB:CC:DD:EE:FF(laptop)", result);
}
[Fact]
public void ToString_WhenHostnameNullButMacExists_ShouldReturnMacOnly()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", null, 30);
// Act
var result = clientInfo.ToString();
// Assert
Assert.Equal("AA:BB:CC:DD:EE:FF", result);
}
[Fact]
public void ToString_WhenMacIsNull_ShouldReturnUnknownClient()
{
// Arrange
var clientInfo = new ClientInfo(null, "192.168.1.100", "laptop", 30);
// Act
var result = clientInfo.ToString();
// Assert
Assert.Equal("Unknown Client", result);
}
[Fact]
public void Constructor_ShouldSetAllProperties()
{
// Arrange & Act
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 30);
// Assert
Assert.Equal("AA:BB:CC:DD:EE:FF", clientInfo.Mac);
Assert.Equal("192.168.1.100", clientInfo.Ip);
Assert.Equal("laptop", clientInfo.Hostname);
Assert.Equal(30, clientInfo.IdleTime);
}
[Fact]
public void IsIdle_WhenIdleTimeEqualsMax_ShouldReturnFalse()
{
// Arrange
var clientInfo = new ClientInfo("AA:BB:CC:DD:EE:FF", "192.168.1.100", "laptop", 300);
// Act
var result = clientInfo.IsIdle(maxIdleSeconds: 300);
// Assert
Assert.False(result);
}
}