Skip to content

Commit 4e68900

Browse files
committed
1 parent d9ec8ee commit 4e68900

File tree

101 files changed

+9941
-3483
lines changed

Some content is hidden

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

101 files changed

+9941
-3483
lines changed

DeviceDetector.NET.CacheBuilder/CacheBuilder.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
1+
using System.Collections.Generic;
42
using System.Linq;
53
using System.Threading.Tasks;
64
using Microsoft.Extensions.Logging;
75

86
namespace DeviceDetector.Net.CacheBuilder
97
{
10-
public class CacheBuilder
8+
public class CacheBuilder(IEnumerable<string> userAgentStrings, bool skipBotDetection, ILogger logger)
119
{
12-
public IEnumerable<string> UserAgentStrings { get; }
13-
public bool SkipBotDetection { get; }
14-
public ILogger Logger { get; }
15-
16-
public CacheBuilder(IEnumerable<string> userAgentStrings, bool skipBotDetection, ILogger logger)
17-
{
18-
UserAgentStrings = userAgentStrings;
19-
SkipBotDetection = skipBotDetection;
20-
Logger = logger;
21-
}
10+
public IEnumerable<string> UserAgentStrings { get; } = userAgentStrings;
11+
public bool SkipBotDetection { get; } = skipBotDetection;
12+
public ILogger Logger { get; } = logger;
2213

2314
public void BuildCache()
2415
{

DeviceDetector.NET.RegexEngine.PCRE/PCRERegexEngine.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,39 @@
22
using System.Linq;
33
using PCRE;
44

5-
namespace DeviceDetectorNET.RegexEngine.PCRE
5+
namespace DeviceDetectorNET.RegexEngine.PCRE;
6+
7+
public class PcreRegexEngine: IRegexEngine
68
{
7-
public class PcreRegexEngine: IRegexEngine
9+
public bool Match(string input, string pattern)
810
{
9-
public bool Match(string input, string pattern)
10-
{
11-
var match = PcreRegex.Match(input, pattern);
12-
return match.Success;
13-
}
11+
var match = PcreRegex.Match(input, pattern);
12+
return match.Success;
13+
}
1414

15-
public IEnumerable<string> Matches(string input, string pattern)
16-
{
17-
var matches = PcreRegex.Matches(input, pattern, PcreOptions.IgnoreCase);
18-
return matches.SelectMany(m => m.Groups.Select(g => g.Value));
19-
}
15+
public IEnumerable<string> Matches(string input, string pattern)
16+
{
17+
var matches = PcreRegex.Matches(input, pattern, PcreOptions.IgnoreCase);
18+
return matches.SelectMany(m => m.Groups.Select(g => g.Value));
19+
}
2020

21-
public IEnumerable<string> MatchesUniq(string input, string pattern)
21+
public IEnumerable<string> MatchesUniq(string input, string pattern)
22+
{
23+
var matches = PcreRegex.Matches(input, pattern, PcreOptions.IgnoreCase);
24+
foreach (var match in matches)
2225
{
23-
var matches = PcreRegex.Matches(input, pattern, PcreOptions.IgnoreCase);
24-
foreach (var match in matches)
26+
foreach (var group in match.Groups)
2527
{
26-
foreach (var group in match.Groups)
28+
if (!match.Value.Equals(group.Value))
2729
{
28-
if (!match.Value.Equals(group.Value))
29-
{
30-
yield return group.Value;
31-
}
30+
yield return group.Value;
3231
}
3332
}
3433
}
34+
}
3535

36-
public string Replace(string input, string pattern, string replacement)
37-
{
38-
return PcreRegex.Replace(input, pattern, replacement);
39-
}
36+
public string Replace(string input, string pattern, string replacement)
37+
{
38+
return PcreRegex.Replace(input, pattern, replacement);
4039
}
4140
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace DeviceDetectorNET.Tests.Class;
4+
5+
public class TypeMethodFixture
6+
{
7+
public string user_agent { get; set; }
8+
public Tuple<bool,bool,bool,bool,bool,bool> check { get; set; }
9+
}

DeviceDetector.NET.Tests/DeviceDetectorTest.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public void TestIsParsed()
207207
[InlineData("tablet-8")]
208208
[InlineData("tablet-9")]
209209
[InlineData("tablet-10")]
210+
[InlineData("tablet-11")]
210211
[InlineData("tv")]
211212
[InlineData("tv-1")]
212213
[InlineData("tv-2")]
@@ -398,11 +399,11 @@ public void TestGetInfoFromUaBot()
398399
{
399400
Name = "Googlebot",
400401
Category = "Search bot",
401-
Url = "http://www.google.com/bot.html",
402+
Url = "https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers",
402403
Producer = new Producer
403404
{
404405
Name = "Google Inc.",
405-
Url = "http://www.google.com"
406+
Url = "https://www.google.com/"
406407
}
407408
}
408409
};
@@ -443,29 +444,21 @@ public void TestInvalidMagicMethod()
443444
[Fact]
444445
public void TestTypeMethods()
445446
{
446-
var userAgents = new List<Tuple<string, bool, bool, bool>> {
447-
new("Googlebot/2.1 (http://www.googlebot.com/bot.html)", true, false, false),
448-
new("Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36", false, true, false),
449-
new("Mozilla/5.0 (Linux; Android 4.4.3; Build/KTU84L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.117 Mobile Safari/537.36", false, true, false),
450-
new("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)", false, false, true),
451-
new("Mozilla/3.01 (compatible;)", false, false, false),
452-
// Mobile only browsers:
453-
new("Opera/9.80 (J2ME/MIDP; Opera Mini/9.5/37.8069; U; en) Presto/2.12.423 Version/12.16", false, true, false),
454-
new("Mozilla/5.0 (X11; U; Linux i686; th-TH@calendar=gregorian) AppleWebKit/534.12 (KHTML, like Gecko) Puffin/1.3.2665MS Safari/534.12", false, true, false),
455-
new("Mozilla/5.0 (Linux; Android 4.4.4; MX4 Pro Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36; 360 Aphone Browser (6.9.7)", false, true, false),
456-
new("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; xx) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17 Skyfire/6DE", false, true, false),
457-
// useragent containing non unicode chars
458-
new("Mozilla/5.0 (Linux; U; Android 4.1.2; ru-ru; PMP7380D3G Build/JZO54K) AppleWebKit/534.30 (KHTML, как Gecko) Version/4.0 Safari/534.30", false, true, false),
459-
};
447+
var path = $"{Utils.CurrentDirectory()}\\{@"Parser\fixtures\type-methods.yml"}";
448+
var parser = new YamlParser<List<TypeMethodFixture>>();
449+
var fixtureData = parser.ParseFile(path);
460450

461-
foreach (var item in userAgents)
451+
foreach (var item in fixtureData)
462452
{
463-
var dd = new DeviceDetector(item.Item1);
453+
var dd = new DeviceDetector(item.user_agent);
464454
dd.DiscardBotInformation();
465455
dd.Parse();
466-
dd.IsBot().Should().Be(item.Item2);
467-
dd.IsMobile().Should().Be(item.Item3);
468-
dd.IsDesktop().Should().Be(item.Item4);
456+
dd.IsBot().Should().Be(item.check.Item1);
457+
dd.IsMobile().Should().Be(item.check.Item2);
458+
dd.IsDesktop().Should().Be(item.check.Item3);
459+
dd.IsTablet().Should().Be(item.check.Item4);
460+
dd.IsTv().Should().Be(item.check.Item5);
461+
dd.IsWearable().Should().Be(item.check.Item6);
469462
}
470463
}
471464
[Fact]

DeviceDetector.NET.Tests/Parser/BotTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public void TestGetInfoFromUaBot()
1616

1717
Name = "Googlebot",
1818
Category = "Search bot",
19-
Url = "http://www.google.com/bot.html",
19+
Url = "https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers",
2020
Producer = new Producer
2121
{
2222
Name = "Google Inc.",
23-
Url = "http://www.google.com"
23+
Url = "https://www.google.com/"
2424
}
2525
};
2626

0 commit comments

Comments
 (0)