Skip to content

Commit 09b7cc0

Browse files
authored
Merge pull request #66 from totpero/v6
V6 -updates
2 parents 5ec080c + a8ae143 commit 09b7cc0

File tree

162 files changed

+214489
-59741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+214489
-59741
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
namespace DeviceDetectorNET.Tests.Class.Client
1+
using System.Collections.Generic;
2+
3+
namespace DeviceDetectorNET.Tests.Class.Client
24
{
35

46
public class BrowserFixture
57
{
68
public string user_agent { get; set; }
79
public Client client { get; set; }
10+
public Dictionary<string,string> headers { get; set; }
11+
812
public class Client
913
{
1014
public string type { get; set; }
@@ -13,6 +17,7 @@ public class Client
1317
public string version { get; set; }
1418
public string engine { get; set; }
1519
public object engine_version { get; set; }
20+
public string family { get; set; }
1621
}
1722
}
1823
}

DeviceDetector.NET.Tests/Class/DeviceDetectorFixture.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class DeviceDetectorFixture
1111
public Device device { get; set; }
1212
public string os_family { get; set; }
1313
public string browser_family { get; set; }
14+
public Dictionary<string, string> headers { get; set; }
15+
public Bot bot { get; set; }
1416

1517
}
1618

@@ -38,4 +40,12 @@ public class Device
3840
public string brand { get; set; }
3941
public string model { get; set; }
4042
}
43+
44+
public class Bot
45+
{
46+
public string name { get; set; }
47+
public string category { get; set; }
48+
public string url { get; set; }
49+
50+
}
4151
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
namespace DeviceDetectorNET.Tests.Class.Client
1+
using System.Collections.Generic;
2+
3+
namespace DeviceDetectorNET.Tests.Class.Client
24
{
35
public class OsFixture
46
{
57
public string user_agent { get; set; }
68
public Os os { get; set; }
79
public string client { get; set; }
10+
public Dictionary<string,string> headers { get; set; }
811

912
public class Os
1013
{
1114
public string name { get; set; }
1215
public string short_name { get; set; }
1316
public string version { get; set; }
1417
public string platform { get; set; }
18+
public string family { get; set; }
1519
}
1620
}
1721
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using FluentAssertions;
2+
using System.Collections.Generic;
3+
using System.Reflection.PortableExecutable;
4+
using Xunit;
5+
6+
namespace DeviceDetectorNET.Tests
7+
{
8+
[Trait("Category", "ClientHints")]
9+
public class ClientHintsTest
10+
{
11+
[Fact]
12+
public void TestHeaders()
13+
{
14+
//IDictionary<string, StringValues>
15+
var headers = new Dictionary<string, string>
16+
{
17+
{"sec-ch-ua",@"""Opera"";v=""83"", "" Not;A Brand"";v=""99"", ""Chromium"";v=""98""" },
18+
{"sec-ch-ua-mobile","?0" },
19+
{"sec-ch-ua-platform","Windows" },
20+
{"sec-ch-ua-platform-version","14.0.0" },
21+
};
22+
23+
var ch = ClientHints.Factory(headers);
24+
ch.IsMobile().Should().BeFalse();
25+
26+
ch.GetOperatingSystem().Should().Be("Windows");
27+
ch.GetOperatingSystemVersion().Should().Be("14.0.0");
28+
ch.GetBrandList().Should().Equal(
29+
new Dictionary<string, string>{
30+
{ "Opera", "83" },
31+
{ " Not;A Brand", "99" },
32+
{ "Chromium", "98" },
33+
}
34+
);
35+
}
36+
37+
[Fact]
38+
public void TestHeadersHttp()
39+
{
40+
var headers = new Dictionary<string, string>
41+
{
42+
{ "HTTP_SEC_CH_UA_FULL_VERSION_LIST" , @""" Not A;Brand"";v=""99.0.0.0"", ""Chromium"";v=""98.0.4758.82"", ""Opera"";v=""98.0.4758.82""" },
43+
{ "HTTP_SEC_CH_UA" , @""" Not A;Brand"";v=""99"", ""Chromium"";v=""98"", ""Opera"";v=""84"""},
44+
{ "HTTP_SEC_CH_UA_MOBILE" , "?1"},
45+
{ "HTTP_SEC_CH_UA_MODEL" , "DN2103"},
46+
{ "HTTP_SEC_CH_UA_PLATFORM" , "Ubuntu"},
47+
{ "HTTP_SEC_CH_UA_PLATFORM_VERSION" , "3.7"},
48+
{ "HTTP_SEC_CH_UA_FULL_VERSION" , "98.0.14335.105"}
49+
};
50+
51+
var ch = ClientHints.Factory(headers);
52+
ch.IsMobile().Should().BeTrue();
53+
ch.GetOperatingSystem().Should().Be("Ubuntu");
54+
ch.GetOperatingSystemVersion().Should().Be("3.7");
55+
56+
ch.GetBrandList().Should().Equal(
57+
new Dictionary<string, string>{
58+
{ " Not A;Brand", "99.0.0.0" },
59+
{ "Chromium", "98.0.4758.82" },
60+
{ "Opera", "98.0.4758.82" },
61+
}
62+
);
63+
ch.GetModel().Should().Be("DN2103");
64+
}
65+
66+
[Fact]
67+
public void TestHeadersJavascript()
68+
{
69+
var headers = new Dictionary<string, string>
70+
{
71+
//'fullVersionList' => [
72+
// ['brand' => ' Not A;Brand', 'version' => '99.0.0.0'],
73+
// ['brand' => 'Chromium', 'version' => '99.0.4844.51'],
74+
// ['brand' => 'Google Chrome', 'version' => '99.0.4844.51'],
75+
//],
76+
{"mobile" , "false" },
77+
{"model" , "" },
78+
{"platform" , "Windows" },
79+
{ "platformVersion" , "10.0.0" },
80+
};
81+
82+
var ch = ClientHints.Factory(headers);
83+
ch.IsMobile().Should().BeFalse();
84+
ch.GetOperatingSystem().Should().Be("Windows");
85+
ch.GetOperatingSystemVersion().Should().Be("10.0.0");
86+
87+
//ch.GetBrandList().Should().Equal(
88+
// new Dictionary<string, string>{
89+
// { " Not A;Brand", "99.0.0.0" },
90+
// { "Chromium", "99.0.4844.51" },
91+
// { "Google Chrome", "99.0.4844.51" },
92+
// }
93+
// );
94+
95+
ch.GetModel().Should().Be("");
96+
97+
}
98+
99+
[Fact]
100+
public void TestIncorrectVersionListIsDiscarded()
101+
{
102+
var headers = new Dictionary<string, string>
103+
{
104+
//'fullVersionList' => [
105+
// ['brand' => ' Not A;Brand', 'version' => '99.0.0.0'],
106+
// ['brand' => 'Chromium', 'version' => '99.0.4844.51'],
107+
// ['brand' => 'Google Chrome', 'version' => '99.0.4844.51'],
108+
//],
109+
{"mobile" , "false" },
110+
{"model" , "" },
111+
{"platform" , "Windows" },
112+
{ "platformVersion" , "10.0.0" },
113+
};
114+
115+
var ch = ClientHints.Factory(headers);
116+
ch.IsMobile().Should().BeFalse();
117+
ch.GetOperatingSystem().Should().Be("Windows");
118+
ch.GetOperatingSystemVersion().Should().Be("10.0.0");
119+
120+
//ch.GetBrandList().Should().Equal(
121+
// new Dictionary<string, string>{
122+
// { " Not A;Brand", "99.0.0.0" },
123+
// { "Chromium", "99.0.4844.51" },
124+
// { "Google Chrome", "99.0.4844.51" },
125+
// }
126+
// );
127+
128+
ch.GetModel().Should().Be("");
129+
130+
}
131+
}
132+
}

DeviceDetector.NET.Tests/DeviceDetector.NET.Tests.csproj

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,190 @@
3838
</None>
3939
</ItemGroup>
4040

41+
<ItemGroup>
42+
<None Update="fixtures\bots.yml">
43+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
44+
</None>
45+
<None Update="fixtures\camera.yml">
46+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
47+
</None>
48+
<None Update="fixtures\car_browser.yml">
49+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
50+
</None>
51+
<None Update="fixtures\clienthints-app.yml">
52+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
53+
</None>
54+
<None Update="fixtures\clienthints.yml">
55+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
56+
</None>
57+
<None Update="fixtures\console.yml">
58+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
59+
</None>
60+
<None Update="fixtures\desktop.yml">
61+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
62+
</None>
63+
<None Update="fixtures\feature_phone.yml">
64+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
65+
</None>
66+
<None Update="fixtures\feed_reader.yml">
67+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
68+
</None>
69+
<None Update="fixtures\mediaplayer.yml">
70+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
</None>
72+
<None Update="fixtures\mobile_apps.yml">
73+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
74+
</None>
75+
<None Update="fixtures\peripheral.yml">
76+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
77+
</None>
78+
<None Update="fixtures\phablet.yml">
79+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
80+
</None>
81+
<None Update="fixtures\portable_media_player.yml">
82+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
83+
</None>
84+
<None Update="fixtures\smartphone-1.yml">
85+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
86+
</None>
87+
<None Update="fixtures\smartphone-10.yml">
88+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
89+
</None>
90+
<None Update="fixtures\smartphone-11.yml">
91+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
92+
</None>
93+
<None Update="fixtures\smartphone-12.yml">
94+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
95+
</None>
96+
<None Update="fixtures\smartphone-13.yml">
97+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
98+
</None>
99+
<None Update="fixtures\smartphone-14.yml">
100+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
101+
</None>
102+
<None Update="fixtures\smartphone-15.yml">
103+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
104+
</None>
105+
<None Update="fixtures\smartphone-16.yml">
106+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
107+
</None>
108+
<None Update="fixtures\smartphone-17.yml">
109+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
110+
</None>
111+
<None Update="fixtures\smartphone-18.yml">
112+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
113+
</None>
114+
<None Update="fixtures\smartphone-19.yml">
115+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
116+
</None>
117+
<None Update="fixtures\smartphone-2.yml">
118+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
119+
</None>
120+
<None Update="fixtures\smartphone-20.yml">
121+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
122+
</None>
123+
<None Update="fixtures\smartphone-21.yml">
124+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
125+
</None>
126+
<None Update="fixtures\smartphone-22.yml">
127+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
128+
</None>
129+
<None Update="fixtures\smartphone-23.yml">
130+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
131+
</None>
132+
<None Update="fixtures\smartphone-24.yml">
133+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
134+
</None>
135+
<None Update="fixtures\smartphone-25.yml">
136+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
137+
</None>
138+
<None Update="fixtures\smartphone-26.yml">
139+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
140+
</None>
141+
<None Update="fixtures\smartphone-27.yml">
142+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
143+
</None>
144+
<None Update="fixtures\smartphone-28.yml">
145+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
146+
</None>
147+
<None Update="fixtures\smartphone-29.yml">
148+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
149+
</None>
150+
<None Update="fixtures\smartphone-3.yml">
151+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
152+
</None>
153+
<None Update="fixtures\smartphone-30.yml">
154+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
155+
</None>
156+
<None Update="fixtures\smartphone-31.yml">
157+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
158+
</None>
159+
<None Update="fixtures\smartphone-4.yml">
160+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
161+
</None>
162+
<None Update="fixtures\smartphone-5.yml">
163+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
164+
</None>
165+
<None Update="fixtures\smartphone-6.yml">
166+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
167+
</None>
168+
<None Update="fixtures\smartphone-7.yml">
169+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
170+
</None>
171+
<None Update="fixtures\smartphone-8.yml">
172+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
173+
</None>
174+
<None Update="fixtures\smartphone-9.yml">
175+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
176+
</None>
177+
<None Update="fixtures\smartphone.yml">
178+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
179+
</None>
180+
<None Update="fixtures\smart_display.yml">
181+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
182+
</None>
183+
<None Update="fixtures\smart_speaker.yml">
184+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
185+
</None>
186+
<None Update="fixtures\tablet-1.yml">
187+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
188+
</None>
189+
<None Update="fixtures\tablet-2.yml">
190+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
191+
</None>
192+
<None Update="fixtures\tablet-3.yml">
193+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
194+
</None>
195+
<None Update="fixtures\tablet-4.yml">
196+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
197+
</None>
198+
<None Update="fixtures\tablet-5.yml">
199+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
200+
</None>
201+
<None Update="fixtures\tablet-6.yml">
202+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
203+
</None>
204+
<None Update="fixtures\tablet-7.yml">
205+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
206+
</None>
207+
<None Update="fixtures\tablet-8.yml">
208+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
209+
</None>
210+
<None Update="fixtures\tablet.yml">
211+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
212+
</None>
213+
<None Update="fixtures\tv-1.yml">
214+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
215+
</None>
216+
<None Update="fixtures\tv.yml">
217+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
218+
</None>
219+
<None Update="fixtures\unknown.yml">
220+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
221+
</None>
222+
<None Update="fixtures\wearable.yml">
223+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
224+
</None>
225+
</ItemGroup>
226+
41227
</Project>

0 commit comments

Comments
 (0)