-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLTEConfigTests.cs
242 lines (200 loc) · 8.94 KB
/
LTEConfigTests.cs
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using hio_dotnet.Common.Config;
using hio_dotnet.Common.Enums;
using hio_dotnet.Common.Enums.LTE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hio_dotnet.Tests.Common
{
public class LTEConfigTests
{
[Fact]
public void ParseLine_ShouldParseValidBoolTestConfig()
{
var config = new LTEConfig();
config.ParseLine("lte config test true");
Assert.True(config.Test);
}
[Fact]
public void ParseLine_ShouldParseValidEnumAntennaConfig()
{
var config = new LTEConfig();
config.ParseLine("lte config antenna external");
Assert.Equal(AntennaType.External, config.Antenna);
config = new LTEConfig();
config.ParseLine("lte config antenna ext");
Assert.Equal(AntennaType.External, config.Antenna);
config = new LTEConfig();
config.Antenna = AntennaType.External;
config.ParseLine("lte config antenna internal");
Assert.Equal(AntennaType.Internal, config.Antenna);
config = new LTEConfig();
config.Antenna = AntennaType.External;
config.ParseLine("lte config antenna int");
Assert.Equal(AntennaType.Internal, config.Antenna);
}
[Fact]
public void ParseLine_ShouldParseValidIntPlmnIdConfig()
{
var config = new LTEConfig();
config.ParseLine("lte config plmnid 23003");
Assert.Equal(23003, config.PlmnId);
}
[Fact]
public void ParseLine_ShouldParseValidStringApnConfig()
{
var config = new LTEConfig();
config.ParseLine("lte config apn testapn");
Assert.Equal("testapn", config.Apn);
}
[Fact]
public void ParseLine_ShouldThrowExceptionOnInvalidLine()
{
var config = new LTEConfig();
Assert.Throws<ArgumentException>(() => config.ParseLine("lrw config adr true"));
}
[Fact]
public void ParseLine_ShouldHandleEmptyString()
{
var config = new LTEConfig();
Assert.Throws<ArgumentNullException>(() => config.ParseLine(""));
}
[Fact]
public void ParseLine_ShouldHandleNullString()
{
var config = new LTEConfig();
Assert.Throws<ArgumentNullException>(() => config.ParseLine(null));
}
[Fact]
public void ParseLine_ShouldHandleInvalidEnumValueGracefully()
{
var config = new LTEConfig();
Assert.Throws<InvalidOperationException>(() => config.ParseLine("lte config antenna unknownvalue"));
}
[Fact]
public void ParseLine_ShouldHandleInvalidBooleanValueGracefully()
{
var config = new LTEConfig();
Assert.Throws<FormatException>(() => config.ParseLine("lte config test notabool"));
}
[Fact]
public void ParseLine_ShouldHandleInvalidIntegerValueGracefully()
{
var config = new LTEConfig();
Assert.Throws<FormatException>(() => config.ParseLine("lte config plmnid notanint"));
}
[Fact]
public void ParseAllLines()
{
var config = new LTEConfig();
config.ParseLine("lte config test true");
Assert.Equal(config.Test, true);
config.ParseLine("lte config nb-iot-mode true");
Assert.Equal(config.NbIotMode, true);
config.ParseLine("lte config lte-m-mode true");
Assert.Equal(config.LteMMode, true);
config.ParseLine("lte config autoconn true");
Assert.Equal(config.AutoConn, true);
config.ParseLine("lte config clksync true");
Assert.Equal(config.ClkSync, true);
config.ParseLine("lte config plmnid 1234");
Assert.Equal(config.PlmnId, 1234);
config.ParseLine("lte config port 4321");
Assert.Equal(config.Port, 4321);
config.ParseLine("lte config antenna ext");
Assert.Equal(config.Antenna, AntennaType.External);
config.ParseLine("lte config auth chap");
Assert.Equal(config.Authorization, LTEAuthType.CHAP);
config.ParseLine("lte config apn hardwario");
Assert.Equal(config.Apn, "hardwario");
config.ParseLine("lte config username name");
Assert.Equal(config.Username, "name");
config.ParseLine("lte config password pass");
Assert.Equal(config.Password, "pass");
config.ParseLine("lte config addr 127.0.0.1");
Assert.Equal(config.Address, "127.0.0.1");
}
[Fact]
public void GetWholeConfig_ShouldHandleDefaultValues()
{
var config = new LTEConfig();
var expectedConfig = "lte config test false" + Environment.NewLine +
"lte config nb-iot-mode false" + Environment.NewLine +
"lte config lte-m-mode true" + Environment.NewLine +
"lte config autoconn false" + Environment.NewLine +
"lte config clksync false" + Environment.NewLine +
"lte config plmnid 0" + Environment.NewLine +
"lte config port 0" + Environment.NewLine +
"lte config antenna int" + Environment.NewLine +
"lte config auth none" + Environment.NewLine +
"lte config apn default_apn" + Environment.NewLine +
"lte config username " + Environment.NewLine +
"lte config password " + Environment.NewLine +
"lte config addr 0.0.0.0";
Assert.Equal(expectedConfig, config.GetWholeConfig().Trim());
}
[Fact]
public void FluentInterface_ShouldSetPropertiesCorrectly()
{
var config = new LTEConfig()
.WithTest(true)
.WithAntenna(AntennaType.External)
.WithNbIotMode(true)
.WithLteMMode(false)
.WithAutoConn(true)
.WithPlmnId(23003)
.WithApn("testapn")
.WithAuth(LTEAuthType.CHAP)
.WithUsername("testuser")
.WithPassword("password123")
.WithAddress("192.168.1.1")
.WithPort(8080);
Assert.True(config.Test);
Assert.Equal(AntennaType.External, config.Antenna);
Assert.True(config.NbIotMode);
Assert.False(config.LteMMode);
Assert.True(config.AutoConn);
Assert.Equal(23003, config.PlmnId);
Assert.Equal("testapn", config.Apn);
Assert.Equal(LTEAuthType.CHAP, config.Authorization);
Assert.Equal("testuser", config.Username);
Assert.Equal("password123", config.Password);
Assert.Equal("192.168.1.1", config.Address);
Assert.Equal(8080, config.Port);
}
[Fact]
public void GetWholeConfig_ShouldGenerateCorrectConfigString()
{
var config = new LTEConfig()
.WithTest(true)
.WithAntenna(AntennaType.External)
.WithNbIotMode(true)
.WithLteMMode(false)
.WithAutoConn(true)
.WithClkSync(true)
.WithPlmnId(23003)
.WithApn("testapn")
.WithAuth(LTEAuthType.PAP)
.WithUsername("user")
.WithPassword("pass")
.WithAddress("192.168.1.1")
.WithPort(8080);
var expectedConfig = "lte config test true" + Environment.NewLine +
"lte config nb-iot-mode true" + Environment.NewLine +
"lte config lte-m-mode false" + Environment.NewLine +
"lte config autoconn true" + Environment.NewLine +
"lte config clksync true" + Environment.NewLine +
"lte config plmnid 23003" + Environment.NewLine +
"lte config port 8080" + Environment.NewLine +
"lte config antenna ext" + Environment.NewLine +
"lte config auth pap" + Environment.NewLine +
"lte config apn testapn" + Environment.NewLine +
"lte config username user" + Environment.NewLine +
"lte config password pass" + Environment.NewLine +
"lte config addr 192.168.1.1";
Assert.Equal(expectedConfig, config.GetWholeConfig().Trim());
}
}
}