Skip to content

Commit b95b215

Browse files
committed
- Swapped the Architecture and OS Type fields.
1 parent 3b3c683 commit b95b215

File tree

2 files changed

+85
-85
lines changed

2 files changed

+85
-85
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/UserAgent.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ internal static class UserAgent
3333
/// <para>
3434
/// The format is pipe ('|') delimited into 7 parts:
3535
///
36-
/// <code>1|MS-MDS|{Driver Version}|{OS Type}|{Arch}|{OS Info}|{Runtime Info}</code>
36+
/// <code>1|MS-MDS|{Driver Version}|{Arch}|{OS Type}|{OS Info}|{Runtime Info}</code>
3737
/// </para>
3838
/// <para>
3939
/// The <c>{Driver Version}</c> part is the version of the driver,
4040
/// sourced from the MDS NuGet package version in SemVer 2.0 format.
4141
/// Maximum length is 24 characters.
4242
/// </para>
4343
/// <para>
44+
/// The <c>{Arch}</c> part will be the process architecture, either
45+
/// the bare metal hardware architecture or the virtualized
46+
/// architecture. See
47+
/// <see cref="RuntimeInformation.ProcessArchitecture">
48+
/// ProcessArchitecture
49+
/// </see>
50+
/// for possible values. Maximum length is 10 characters.
51+
/// </para>
52+
/// <para>
4453
/// The <c>{OS Type}</c> part will be one of the following strings:
4554
/// <list type="bullet">
4655
/// <item><description>Windows</description></item>
@@ -50,15 +59,6 @@ internal static class UserAgent
5059
/// <item><description>Unknown</description></item>
5160
/// </list>
5261
/// </para>
53-
/// <para>
54-
/// The <c>{Arch}</c> part will be the process architecture, either
55-
/// the bare metal hardware architecture or the virtualized
56-
/// architecture. See
57-
/// <see cref="RuntimeInformation.ProcessArchitecture">
58-
/// ProcessArchitecture
59-
/// </see>
60-
/// for possible values. Maximum length is 10 characters.
61-
/// </para>
6262
/// <para>
6363
/// The <c>{OS Info}</c> part will be sourced from the the
6464
/// <see cref="RuntimeInformation.OSDescription">
@@ -90,7 +90,7 @@ internal static class UserAgent
9090
/// <item><description>Hyphen ('-')</description></item>
9191
/// </list>
9292
/// </para>
93-
/// <para>
93+
/// <para>
9494
/// All known exceptions are caught and handled by injecting the
9595
/// fallback value of "Unknown". However, no effort is made to
9696
/// catch all exceptions, for example process-fatal memory
@@ -146,8 +146,8 @@ static UserAgent()
146146
PayloadVersion,
147147
DriverName,
148148
System.ThisAssembly.NuGetPackageVersion,
149-
osType,
150149
RuntimeInformation.ProcessArchitecture,
150+
osType,
151151
RuntimeInformation.OSDescription,
152152
RuntimeInformation.FrameworkDescription);
153153

@@ -178,12 +178,12 @@ static UserAgent()
178178
/// <param name="driverVersion">
179179
/// The value of the driver version part.
180180
/// </param>
181-
/// <param name="osType">
182-
/// The value of the OS Type part.
183-
/// </param>
184181
/// <param name="arch">
185182
/// The value of the Architecture part.
186183
/// </param>
184+
/// <param name="osType">
185+
/// The value of the OS Type part.
186+
/// </param>
187187
/// <param name="osInfo">
188188
/// The value of the OS Info part.
189189
/// </param>
@@ -199,8 +199,8 @@ internal static string Build(
199199
string payloadVersion,
200200
string driverName,
201201
string driverVersion,
202-
string osType,
203202
Architecture arch,
203+
string osType,
204204
string osInfo,
205205
string runtimeInfo)
206206
{
@@ -231,13 +231,13 @@ internal static string Build(
231231
name.Append(Truncate(Clean(driverVersion), MaxLenDriverVersion));
232232
name.Append('|');
233233

234-
// Add the OS Type, truncating to its max length.
235-
name.Append(Truncate(Clean(osType), MaxLenOsType));
236-
name.Append('|');
237-
238234
// Add the Architecture, truncating to its max length.
239235
name.Append(Truncate(Clean(arch.ToString()), MaxLenArch));
240236
name.Append('|');
237+
238+
// Add the OS Type, truncating to its max length.
239+
name.Append(Truncate(Clean(osType), MaxLenOsType));
240+
name.Append('|');
241241

242242
// Add the OS Info, truncating to its max length.
243243
name.Append(Truncate(Clean(osInfo), MaxLenOsInfo));
@@ -411,8 +411,8 @@ internal static string Truncate(string value, ushort maxLength)
411411
private const ushort MaxLenPayloadVersion = 2;
412412
private const ushort MaxLenDriverName = 12;
413413
private const ushort MaxLenDriverVersion = 24;
414-
private const ushort MaxLenOsType = 10;
415414
private const ushort MaxLenArch = 10;
415+
private const ushort MaxLenOsType = 10;
416416
private const ushort MaxLenOsInfo = 44;
417417
private const ushort MaxLenRuntimeInfo = 44;
418418

src/Microsoft.Data.SqlClient/tests/UnitTests/UserAgentTests.cs

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,20 @@ public void Value_Runtime_Parts()
7272
//
7373
// The format should be:
7474
//
75-
// 1|MS-MDS|{Driver Version}|{OS Type}|{Arch}|{OS Info}|{Runtime Info}
75+
// 1|MS-MDS|{Driver Version}|{Arch}|{OS Type}|{OS Info}|{Runtime Info}
7676
//
7777
var parts = value.Split('|');
7878
Assert.Equal(7, parts.Length);
7979
Assert.Equal("1", parts[0]);
8080
Assert.Equal("MS-MDS", parts[1]);
8181
Assert.Equal(System.ThisAssembly.NuGetPackageVersion, parts[2]);
82+
83+
// Architecture must be non-empty and 10 characters or less.
84+
Assert.True(parts[3] == "Unknown" || parts[3].Length > 0);
85+
Assert.True(parts[3].Length <= 10);
8286

8387
// Check the OS Type against the guaranteed values.
84-
var osType = parts[3];
88+
var osType = parts[4];
8589
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
8690
{
8791
Assert.Equal("Windows", osType);
@@ -105,10 +109,6 @@ public void Value_Runtime_Parts()
105109
Assert.Equal("Unknown", osType);
106110
}
107111

108-
// Architecture must be non-empty and 10 characters or less.
109-
Assert.True(parts[4] == "Unknown" || parts[4].Length > 0);
110-
Assert.True(parts[4].Length <= 10);
111-
112112
// OS Info must be non-empty and 44 characters or less.
113113
Assert.True(parts[5] == "Unknown" || parts[5].Length > 0);
114114
Assert.True(parts[5].Length <= 44);
@@ -162,15 +162,15 @@ public void Ucs2Bytes_Runtime_Parts()
162162
[InlineData(4, "2|A|")]
163163
[InlineData(5, "2|A|B")]
164164
[InlineData(6, "2|A|B|")]
165-
[InlineData(7, "2|A|B|C")]
166-
[InlineData(8, "2|A|B|C|")]
167-
[InlineData(9, "2|A|B|C|X")]
168-
[InlineData(10, "2|A|B|C|X6")]
169-
[InlineData(11, "2|A|B|C|X64")]
170-
[InlineData(12, "2|A|B|C|X64|")]
171-
[InlineData(13, "2|A|B|C|X64|D")]
172-
[InlineData(14, "2|A|B|C|X64|D|")]
173-
[InlineData(15, "2|A|B|C|X64|D|E")]
165+
[InlineData(7, "2|A|B|X")]
166+
[InlineData(8, "2|A|B|X6")]
167+
[InlineData(9, "2|A|B|X64")]
168+
[InlineData(10, "2|A|B|X64|")]
169+
[InlineData(11, "2|A|B|X64|C")]
170+
[InlineData(12, "2|A|B|X64|C|")]
171+
[InlineData(13, "2|A|B|X64|C|D")]
172+
[InlineData(14, "2|A|B|X64|C|D|")]
173+
[InlineData(15, "2|A|B|X64|C|D|E")]
174174
public void Build_Truncate_Overall(ushort maxLen, string expected)
175175
{
176176
Assert.Equal(
@@ -180,8 +180,8 @@ public void Build_Truncate_Overall(ushort maxLen, string expected)
180180
payloadVersion: "2",
181181
driverName: "A",
182182
driverVersion: "B",
183-
osType: "C",
184183
Architecture.X64,
184+
osType: "C",
185185
osInfo: "D",
186186
runtimeInfo: "E"));
187187
}
@@ -196,13 +196,13 @@ public void Build_Truncate_Payload_Version()
196196
Assert.Equal(
197197
"P",
198198
UserAgent.Build(
199-
1, "PV", "A", "B", "C", Architecture.X64, "D", "E"));
199+
1, "PV", "A", "B", Architecture.X64, "C", "D", "E"));
200200

201201
// The payload version is longer than its per-field max length of 2.
202202
Assert.Equal(
203-
"12|A|B|C|X64|D|E",
203+
"12|A|B|X64|C|D|E",
204204
UserAgent.Build(
205-
128, "1234", "A", "B", "C", Architecture.X64, "D", "E"));
205+
128, "1234", "A", "B", Architecture.X64, "C", "D", "E"));
206206
}
207207

208208
/// <summary>
@@ -215,13 +215,13 @@ public void Build_Truncate_Driver_Name()
215215
Assert.Equal(
216216
"2|DriverNa",
217217
UserAgent.Build(
218-
10, "2", "DriverName", "B", "C", Architecture.X64, "D", "E"));
218+
10, "2", "DriverName", "B", Architecture.X64, "C", "D", "E"));
219219

220220
// The driver name is longer than its per-field max length of 12.
221221
Assert.Equal(
222-
"2|LongDriverNa|B|C|X64|D|E",
222+
"2|LongDriverNa|B|X64|C|D|E",
223223
UserAgent.Build(
224-
128, "2", "LongDriverName", "B", "C", Architecture.X64,
224+
128, "2", "LongDriverName", "B", Architecture.X64, "C",
225225
"D", "E"));
226226
}
227227

@@ -235,35 +235,15 @@ public void Build_Truncate_Driver_Version()
235235
Assert.Equal(
236236
"2|A|DriverVe",
237237
UserAgent.Build(
238-
12, "2", "A", "DriverVersion", "C", Architecture.X64, "D",
238+
12, "2", "A", "DriverVersion", Architecture.X64, "C", "D",
239239
"E"));
240240

241241
// The driver version is longer than its per-field max length of 24.
242242
Assert.Equal(
243-
"2|A|ReallyLongDriverVersionS|C|X64|D|E",
243+
"2|A|ReallyLongDriverVersionS|X64|C|D|E",
244244
UserAgent.Build(
245-
128, "2", "A", "ReallyLongDriverVersionString", "C",
246-
Architecture.X64, "D", "E"));
247-
}
248-
249-
/// <summary>
250-
/// Test the Build() function when it truncates the OS Type.
251-
/// </summary>
252-
[Fact]
253-
public void Build_Truncate_OS_Type()
254-
{
255-
// The OS Type puts the overall length over the max.
256-
Assert.Equal(
257-
"2|A|B|LongOs",
258-
UserAgent.Build(
259-
12, "2", "A", "B", "LongOsName", Architecture.X64, "D", "E"));
260-
261-
// The OS Type is longer than its per-field max length of 10.
262-
Assert.Equal(
263-
"2|A|B|VeryLongOs|X64|D|E",
264-
UserAgent.Build(
265-
128, "2", "A", "B", "VeryLongOsName", Architecture.X64, "D",
266-
"E"));
245+
128, "2", "A", "ReallyLongDriverVersionString",
246+
Architecture.X64, "C", "D", "E"));
267247
}
268248

269249
/// <summary>
@@ -274,22 +254,42 @@ public void Build_Truncate_Arch()
274254
{
275255
// The Architecture puts the overall length over the max.
276256
Assert.Equal(
277-
"2|A|B|C|Arm6",
257+
"2|A|B|Arm6",
278258
UserAgent.Build(
279-
12, "2", "A", "B", "C", Architecture.Arm64, "D", "E"));
259+
10, "2", "A", "B", Architecture.Arm64, "C", "D", "E"));
280260

281261
// There are no Architecture enum values defined in .NET Framework
282262
// with a length longer than 10, so we can only check truncation
283263
// in .NET.
284264
#if NET
285265
// The Architecture is longer than its per-field max length of 10.
286266
Assert.Equal(
287-
"2|A|B|C|LoongArch6|D|E",
267+
"2|A|B|LoongArch6|C|D|E",
288268
UserAgent.Build(
289-
128, "2", "A", "B", "C", Architecture.LoongArch64, "D", "E"));
269+
128, "2", "A", "B", Architecture.LoongArch64, "C", "D", "E"));
290270
#endif
291271
}
292272

273+
/// <summary>
274+
/// Test the Build() function when it truncates the OS Type.
275+
/// </summary>
276+
[Fact]
277+
public void Build_Truncate_OS_Type()
278+
{
279+
// The OS Type puts the overall length over the max.
280+
Assert.Equal(
281+
"2|A|B|X64|LongOs",
282+
UserAgent.Build(
283+
16, "2", "A", "B", Architecture.X64, "LongOsName", "D", "E"));
284+
285+
// The OS Type is longer than its per-field max length of 10.
286+
Assert.Equal(
287+
"2|A|B|X64|VeryLongOs|D|E",
288+
UserAgent.Build(
289+
128, "2", "A", "B", Architecture.X64, "VeryLongOsName", "D",
290+
"E"));
291+
}
292+
293293
/// <summary>
294294
/// Test the Build() function when it truncates the OS Info.
295295
/// </summary>
@@ -298,15 +298,15 @@ public void Build_Truncate_OS_Info()
298298
{
299299
// The OS Info puts the overall length over the max.
300300
Assert.Equal(
301-
"2|A|B|C|X64|LongOsI",
301+
"2|A|B|X64|C|LongOsI",
302302
UserAgent.Build(
303-
19, "2", "A", "B", "C", Architecture.X64, "LongOsInfo", "E"));
303+
19, "2", "A", "B", Architecture.X64, "C", "LongOsInfo", "E"));
304304

305305
// The OS Type is longer than its per-field max length of 44.
306306
Assert.Equal(
307-
"2|A|B|C|X64|01234567890123456789012345678901234567890123|E",
307+
"2|A|B|X64|C|01234567890123456789012345678901234567890123|E",
308308
UserAgent.Build(
309-
128, "2", "A", "B", "C", Architecture.X64,
309+
128, "2", "A", "B", Architecture.X64, "C",
310310
"01234567890123456789012345678901234567890123456789",
311311
"E"));
312312
}
@@ -319,16 +319,16 @@ public void Build_Truncate_Runtime_Info()
319319
{
320320
// The Runtime Info puts the overall length over the max.
321321
Assert.Equal(
322-
"2|A|B|C|X64|D|LongRunt",
322+
"2|A|B|X64|C|D|LongRunt",
323323
UserAgent.Build(
324-
22, "2", "A", "B", "C", Architecture.X64, "D",
324+
22, "2", "A", "B", Architecture.X64, "C", "D",
325325
"LongRuntimeInfo"));
326326

327327
// The Runtime Type is longer than its per-field max length of 44.
328328
Assert.Equal(
329-
"2|A|B|C|X64|D|01234567890123456789012345678901234567890123",
329+
"2|A|B|X64|C|D|01234567890123456789012345678901234567890123",
330330
UserAgent.Build(
331-
128, "2", "A", "B", "C", Architecture.X64, "D",
331+
128, "2", "A", "B", Architecture.X64, "C", "D",
332332
"01234567890123456789012345678901234567890123456789"));
333333
}
334334

@@ -348,11 +348,11 @@ public void Build_Truncate_Most()
348348
"A01234567890123456789",
349349
// Driver version > 24 chars.
350350
"B012345678901234567890123456789",
351-
// OS Type > 10 chars.
352-
"C01234567890123456789",
353351
// Architecture isn't truncated (because .NET Framework
354352
// doesn't have any enum values long enough).
355353
Architecture.X64,
354+
// OS Type > 10 chars.
355+
"C01234567890123456789",
356356
// OS Info > 44 chars.
357357
"D01234567890123456789012345678901234567890123456789",
358358
// Runtime Info > 44 chars.
@@ -362,8 +362,8 @@ public void Build_Truncate_Most()
362362
"12|" +
363363
"A01234567890|" +
364364
"B01234567890123456789012|" +
365-
"C012345678|" +
366365
"X64|" +
366+
"C012345678|" +
367367
"D0123456789012345678901234567890123456789012|" +
368368
"E0123456789012345678901234567890123456789012",
369369
name);
@@ -388,10 +388,10 @@ public void Build_Truncate_All()
388388
"A01234567890123456789",
389389
// Driver version > 24 chars.
390390
"B012345678901234567890123456789",
391-
// OS Type > 10 chars.
392-
"C01234567890123456789",
393391
// Architecture > 10 chars.
394392
Architecture.LoongArch64,
393+
// OS Type > 10 chars.
394+
"C01234567890123456789",
395395
// OS Info > 44 chars.
396396
"D01234567890123456789012345678901234567890123456789",
397397
// Runtime Info > 44 chars.
@@ -401,8 +401,8 @@ public void Build_Truncate_All()
401401
"12|" +
402402
"A01234567890|" +
403403
"B01234567890123456789012|" +
404-
"C012345678|" +
405404
"LoongArch6|" +
405+
"C012345678|" +
406406
"D0123456789012345678901234567890123456789012|" +
407407
"E0123456789012345678901234567890123456789012",
408408
name);

0 commit comments

Comments
 (0)