diff --git a/Directory.Build.props b/Directory.Build.props index 8cee08b..8af7813 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -30,4 +30,10 @@ 00240000048000009400000006020000002400005253413100040000010001003d5c022c088a46d41d5a5bf7591f3a3dcba30f76b0f43a312b6e45bb419d32283175cbd8bfd83134b123da6db83479e50596fb6bbe0e8c6cef50c01c64a0861c963daaf6905920f44ffe1ce44b3cfcb9c23779f34bc90c7b04e74e36a19bb58af3a69456d49b56993969dba9f8e9e935c2757844a11066d1091477f10cd923b7 + + + + + diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index cefdedf..15c05b8 100644 --- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -6,23 +6,22 @@ using MyCSharp.HttpUserAgentParser.DependencyInjection; using Xunit; -namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.DependencyInjection +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.DependencyInjection; + +public class HttpUserAgentParserDependencyInjectionOptionsExtensionsTests { - public class HttpUserAgentParserDependencyInjectionOptionsExtensionsTests + [Fact] + public void AddHttpUserAgentParserAccessor() { - [Fact] - public void AddHttpUserAgentParserAccessor() - { - ServiceCollection services = new(); - HttpUserAgentParserDependencyInjectionOptions options = new(services); + ServiceCollection services = new(); + HttpUserAgentParserDependencyInjectionOptions options = new(services); - options.AddHttpUserAgentParserAccessor(); + options.AddHttpUserAgentParserAccessor(); - services.Count.Should().Be(1); + services.Count.Should().Be(1); - services[0].ServiceType.Should().Be(); - services[0].ImplementationType.Should().Be(); - services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); - } + services[0].ServiceType.Should().Be(); + services[0].ImplementationType.Should().Be(); + services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs index 2e77dff..ccaf46b 100644 --- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs @@ -2,34 +2,36 @@ using FluentAssertions; using Microsoft.AspNetCore.Http; -using Moq; using MyCSharp.HttpUserAgentParser.Providers; using MyCSharp.HttpUserAgentParser.TestHelpers; +using NSubstitute; using Xunit; -namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests +namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests; + +public class HttpUserAgentParserAccessorTests { - public class HttpUserAgentParserAccessorTests + private readonly IHttpUserAgentParserProvider _parserMock = Substitute.For(); + + [Theory] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] + public void Get(string userAgent) { - [Theory] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] - public void Get(string userAgent) - { - HttpUserAgentInformation userAgentInformation = HttpUserAgentInformation.Parse(userAgent); - - Mock parserMock = new(); - { - parserMock.Setup(x => x.Parse(userAgent)).Returns(userAgentInformation); - } - - HttpContext httpContext = HttpContextTestHelpers.GetHttpContext(userAgent); - - HttpUserAgentParserAccessor accessor = new HttpUserAgentParserAccessor(parserMock.Object); - HttpUserAgentInformation? info = accessor.Get(httpContext); - - info.Should().NotBeNull(); - info.Should().Be(userAgentInformation); - parserMock.Verify(x => x.Parse(userAgent), Times.Once); - } + // arrange + HttpUserAgentInformation userAgentInformation = HttpUserAgentInformation.Parse(userAgent); + _parserMock.Parse(userAgent).Returns(userAgentInformation); + + // act + HttpContext httpContext = HttpContextTestHelpers.GetHttpContext(userAgent); + + HttpUserAgentParserAccessor accessor = new(_parserMock); + HttpUserAgentInformation? info = accessor.Get(httpContext); + + // assert + info.Should().NotBeNull(); + info.Should().Be(userAgentInformation); + + // verify + _parserMock.Received(1).Parse(userAgent); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj index a7721ca..75a3204 100644 --- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj @@ -9,7 +9,7 @@ - + all diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs index 5c6ff2b..215ae1c 100644 --- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests.cs @@ -6,25 +6,24 @@ using MyCSharp.HttpUserAgentParser.Providers; using Xunit; -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.DependencyInjection +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.DependencyInjection; + +public class HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests { - public class HttpUserAgentParserMemoryCacheServiceCollectionExtensionssTests + [Fact] + public void AddHttpUserAgentMemoryCachedParser() { - [Fact] - public void AddHttpUserAgentMemoryCachedParser() - { - ServiceCollection services = new(); + ServiceCollection services = new(); - services.AddHttpUserAgentMemoryCachedParser(); + services.AddHttpUserAgentMemoryCachedParser(); - services.Count.Should().Be(2); + services.Count.Should().Be(2); - services[0].ImplementationInstance.Should().BeOfType(); - services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); + services[0].ImplementationInstance.Should().BeOfType(); + services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); - services[1].ServiceType.Should().Be(); - services[1].ImplementationType.Should().Be(); - services[1].Lifetime.Should().Be(ServiceLifetime.Singleton); - } + services[1].ServiceType.Should().Be(); + services[1].ImplementationType.Should().Be(); + services[1].Lifetime.Should().Be(ServiceLifetime.Singleton); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs index c50435b..9397352 100644 --- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderOptionsTests.cs @@ -4,51 +4,50 @@ using Microsoft.Extensions.Caching.Memory; using Xunit; -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; + +public class HttpUserAgentParserMemoryCachedProviderOptionsTests { - public class HttpUserAgentParserMemoryCachedProviderOptionsTests + [Fact] + public void Ctor() { - [Fact] - public void Ctor() - { - MemoryCacheOptions cacheOptions = new(); - MemoryCacheEntryOptions cacheEntryOptions = new(); + MemoryCacheOptions cacheOptions = new(); + MemoryCacheEntryOptions cacheEntryOptions = new(); - HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions, cacheEntryOptions); + HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions, cacheEntryOptions); - options.CacheOptions.Should().Be(cacheOptions); - options.CacheEntryOptions.Should().Be(cacheEntryOptions); - } + options.CacheOptions.Should().Be(cacheOptions); + options.CacheEntryOptions.Should().Be(cacheEntryOptions); + } - [Fact] - public void Ctor_MemoryCacheOptions() - { - MemoryCacheOptions cacheOptions = new(); + [Fact] + public void Ctor_MemoryCacheOptions() + { + MemoryCacheOptions cacheOptions = new(); - HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions); + HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheOptions); - options.CacheOptions.Should().Be(cacheOptions); - options.CacheEntryOptions.Should().NotBeNull(); - } + options.CacheOptions.Should().Be(cacheOptions); + options.CacheEntryOptions.Should().NotBeNull(); + } - [Fact] - public void Ctor_MemoryCacheEntryOptions() - { - MemoryCacheEntryOptions cacheEntryOptions = new(); + [Fact] + public void Ctor_MemoryCacheEntryOptions() + { + MemoryCacheEntryOptions cacheEntryOptions = new(); - HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheEntryOptions); + HttpUserAgentParserMemoryCachedProviderOptions options = new(cacheEntryOptions); - options.CacheOptions.Should().NotBeNull(); - options.CacheEntryOptions.Should().Be(cacheEntryOptions); - } + options.CacheOptions.Should().NotBeNull(); + options.CacheEntryOptions.Should().Be(cacheEntryOptions); + } - [Fact] - public void Ctor_Empty() - { - HttpUserAgentParserMemoryCachedProviderOptions options = new(); + [Fact] + public void Ctor_Empty() + { + HttpUserAgentParserMemoryCachedProviderOptions options = new(); - options.CacheOptions.Should().NotBeNull(); - options.CacheEntryOptions.Should().NotBeNull(); - } + options.CacheOptions.Should().NotBeNull(); + options.CacheEntryOptions.Should().NotBeNull(); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderTests.cs b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderTests.cs index 337e66f..ce7e481 100644 --- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/HttpUserAgentParserMemoryCachedProviderTests.cs @@ -3,40 +3,39 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests +namespace MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests; + +public class HttpUserAgentParserMemoryCachedProviderTests { - public class HttpUserAgentParserMemoryCachedProviderTests + [Fact] + public void Parse() { - [Fact] - public void Parse() - { - HttpUserAgentParserMemoryCachedProviderOptions cachedProviderOptions = new(); - HttpUserAgentParserMemoryCachedProvider provider = new(cachedProviderOptions); + HttpUserAgentParserMemoryCachedProviderOptions cachedProviderOptions = new(); + HttpUserAgentParserMemoryCachedProvider provider = new(cachedProviderOptions); - // create first - string userAgentOne = - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62"; + // create first + string userAgentOne = + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62"; - HttpUserAgentInformation infoOne = provider.Parse(userAgentOne); + HttpUserAgentInformation infoOne = provider.Parse(userAgentOne); - infoOne.Name.Should().Be("Edge"); - infoOne.Version.Should().Be("90.0.818.62"); + infoOne.Name.Should().Be("Edge"); + infoOne.Version.Should().Be("90.0.818.62"); - // check duplicate + // check duplicate - HttpUserAgentInformation infoDuplicate = provider.Parse(userAgentOne); + HttpUserAgentInformation infoDuplicate = provider.Parse(userAgentOne); - infoDuplicate.Name.Should().Be("Edge"); - infoDuplicate.Version.Should().Be("90.0.818.62"); + infoDuplicate.Name.Should().Be("Edge"); + infoDuplicate.Version.Should().Be("90.0.818.62"); - // create second + // create second - string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0"; + string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0"; - HttpUserAgentInformation infoTwo = provider.Parse(userAgentTwo); + HttpUserAgentInformation infoTwo = provider.Parse(userAgentTwo); - infoTwo.Name.Should().Be("Firefox"); - infoTwo.Version.Should().Be("41.0"); - } + infoTwo.Name.Should().Be("Firefox"); + infoTwo.Version.Should().Be("41.0"); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj index 529ae03..68858e3 100644 --- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj @@ -10,7 +10,6 @@ - all diff --git a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs index 7d79450..768ffa0 100644 --- a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs +++ b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs @@ -8,7 +8,7 @@ public static class HttpContextTestHelpers { public static HttpContext GetHttpContext(string userAgent) { - DefaultHttpContext context = new DefaultHttpContext(); + DefaultHttpContext context = new(); context.Request.Headers["User-Agent"] = userAgent; return context; diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs index 1d00751..ffb6699 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs @@ -2,22 +2,21 @@ using FluentAssertions; using Microsoft.Extensions.DependencyInjection; -using Moq; using MyCSharp.HttpUserAgentParser.DependencyInjection; +using NSubstitute; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection +namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection; + +public class UserAgentParserDependencyInjectionOptionsTests { - public class UserAgentParserDependencyInjectionOptionsTests - { - [Fact] - public void Ctor_Should_Set_Property() - { - Mock scMock = new(); + private readonly IServiceCollection scMock = Substitute.For(); - HttpUserAgentParserDependencyInjectionOptions options = new(scMock.Object); + [Fact] + public void Ctor_Should_Set_Property() + { + HttpUserAgentParserDependencyInjectionOptions options = new(scMock); - options.Services.Should().BeEquivalentTo(scMock.Object); - } + options.Services.Should().BeEquivalentTo(scMock); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs index 89625ea..c5ec4e5 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserServiceCollectionExtensionsTests.cs @@ -6,52 +6,51 @@ using MyCSharp.HttpUserAgentParser.Providers; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection +namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection; + +public class HttpUserAgentParserMemoryCacheServiceCollectionExtensions { - public class HttpUserAgentParserMemoryCacheServiceCollectionExtensions + public class TestHttpUserAgentParserProvider : IHttpUserAgentParserProvider + { + public HttpUserAgentInformation Parse(string userAgent) => throw new System.NotImplementedException(); + } + + [Fact] + public void AddHttpUserAgentParser() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentParser(); + + services.Count.Should().Be(1); + services[0].ServiceType.Should().Be(); + services[0].ImplementationType.Should().Be(); + services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); + } + + [Fact] + public void AddHttpUserAgentCachedParser() + { + ServiceCollection services = new(); + + services.AddHttpUserAgentCachedParser(); + + services.Count.Should().Be(1); + services[0].ServiceType.Should().Be(); + services[0].ImplementationType.Should().Be(); + services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); + } + + [Fact] + public void AddHttpUserAgentParser_With_Generic() { - public class TestHttpUserAgentParserProvider : IHttpUserAgentParserProvider - { - public HttpUserAgentInformation Parse(string userAgent) => throw new System.NotImplementedException(); - } - - [Fact] - public void AddHttpUserAgentParser() - { - ServiceCollection services = new(); - - services.AddHttpUserAgentParser(); - - services.Count.Should().Be(1); - services[0].ServiceType.Should().Be(); - services[0].ImplementationType.Should().Be(); - services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); - } - - [Fact] - public void AddHttpUserAgentCachedParser() - { - ServiceCollection services = new(); - - services.AddHttpUserAgentCachedParser(); - - services.Count.Should().Be(1); - services[0].ServiceType.Should().Be(); - services[0].ImplementationType.Should().Be(); - services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); - } - - [Fact] - public void AddHttpUserAgentParser_With_Generic() - { - ServiceCollection services = new(); - - services.AddHttpUserAgentParser(); - - services.Count.Should().Be(1); - services[0].ServiceType.Should().Be(); - services[0].ImplementationType.Should().Be(); - services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); - } + ServiceCollection services = new(); + + services.AddHttpUserAgentParser(); + + services.Count.Should().Be(1); + services[0].ServiceType.Should().Be(); + services[0].ImplementationType.Should().Be(); + services[0].Lifetime.Should().Be(ServiceLifetime.Singleton); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs index bcf937e..c392ee7 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs @@ -3,49 +3,48 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentInformationExtensionsTests { - public class HttpUserAgentInformationExtensionsTests + [Theory] + [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155", HttpUserAgentType.Browser, true)] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62", HttpUserAgentType.Browser, false)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", HttpUserAgentType.Robot, false)] + [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", HttpUserAgentType.Robot, false)] + [InlineData("Invalid user agent", HttpUserAgentType.Unknown, false)] + public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobile) { - [Theory] - [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155", HttpUserAgentType.Browser, true)] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62", HttpUserAgentType.Browser, false)] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", HttpUserAgentType.Robot, false)] - [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", HttpUserAgentType.Robot, false)] - [InlineData("Invalid user agent", HttpUserAgentType.Unknown, false)] - public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobile) + HttpUserAgentInformation info = HttpUserAgentInformation.Parse(userAgent); + + if (expectedType == HttpUserAgentType.Browser) + { + info.IsType(HttpUserAgentType.Browser).Should().Be(true); + info.IsType(HttpUserAgentType.Robot).Should().Be(false); + info.IsType(HttpUserAgentType.Unknown).Should().Be(false); + + info.IsBrowser().Should().Be(true); + info.IsRobot().Should().Be(false); + } + else if (expectedType == HttpUserAgentType.Robot) { - HttpUserAgentInformation info = HttpUserAgentInformation.Parse(userAgent); - - if (expectedType == HttpUserAgentType.Browser) - { - info.IsType(HttpUserAgentType.Browser).Should().Be(true); - info.IsType(HttpUserAgentType.Robot).Should().Be(false); - info.IsType(HttpUserAgentType.Unknown).Should().Be(false); - - info.IsBrowser().Should().Be(true); - info.IsRobot().Should().Be(false); - } - else if (expectedType == HttpUserAgentType.Robot) - { - info.IsType(HttpUserAgentType.Browser).Should().Be(false); - info.IsType(HttpUserAgentType.Robot).Should().Be(true); - info.IsType(HttpUserAgentType.Unknown).Should().Be(false); - - info.IsBrowser().Should().Be(false); - info.IsRobot().Should().Be(true); - } - else if (expectedType == HttpUserAgentType.Unknown) - { - info.IsType(HttpUserAgentType.Browser).Should().Be(false); - info.IsType(HttpUserAgentType.Robot).Should().Be(false); - info.IsType(HttpUserAgentType.Unknown).Should().Be(true); - - info.IsBrowser().Should().Be(false); - info.IsRobot().Should().Be(false); - } - - info.IsMobile().Should().Be(isMobile); + info.IsType(HttpUserAgentType.Browser).Should().Be(false); + info.IsType(HttpUserAgentType.Robot).Should().Be(true); + info.IsType(HttpUserAgentType.Unknown).Should().Be(false); + + info.IsBrowser().Should().Be(false); + info.IsRobot().Should().Be(true); } + else if (expectedType == HttpUserAgentType.Unknown) + { + info.IsType(HttpUserAgentType.Browser).Should().Be(false); + info.IsType(HttpUserAgentType.Robot).Should().Be(false); + info.IsType(HttpUserAgentType.Unknown).Should().Be(true); + + info.IsBrowser().Should().Be(false); + info.IsRobot().Should().Be(false); + } + + info.IsMobile().Should().Be(isMobile); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 8b78c40..3c11fa3 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -4,69 +4,68 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentInformationTests { - public class HttpUserAgentInformationTests + [Theory] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] + public void Parse(string userAgent) { - [Theory] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] - public void Parse(string userAgent) - { - HttpUserAgentInformation ua1 = HttpUserAgentParser.Parse(userAgent); - HttpUserAgentInformation ua2 = HttpUserAgentInformation.Parse(userAgent); + HttpUserAgentInformation ua1 = HttpUserAgentParser.Parse(userAgent); + HttpUserAgentInformation ua2 = HttpUserAgentInformation.Parse(userAgent); - ua1.Should().BeEquivalentTo(ua2); - } + ua1.Should().BeEquivalentTo(ua2); + } - [Theory] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] - public void CreateForRobot(string userAgent) - { + [Theory] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] + public void CreateForRobot(string userAgent) + { - HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForRobot(userAgent, "Chrome"); + HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForRobot(userAgent, "Chrome"); - ua.UserAgent.Should().Be(userAgent); - ua.Type.Should().Be(HttpUserAgentType.Robot); - ua.Platform.Should().Be(null); - ua.Name.Should().Be("Chrome"); - ua.Version.Should().Be(null); - ua.MobileDeviceType.Should().Be(null); - } + ua.UserAgent.Should().Be(userAgent); + ua.Type.Should().Be(HttpUserAgentType.Robot); + ua.Platform.Should().Be(null); + ua.Name.Should().Be("Chrome"); + ua.Version.Should().Be(null); + ua.MobileDeviceType.Should().Be(null); + } - [Theory] - [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155")] - public void CreateForBrowser(string userAgent) - { - HttpUserAgentPlatformInformation platformInformation = - new HttpUserAgentPlatformInformation(new Regex(""), "Android", HttpUserAgentPlatformType.Android); + [Theory] + [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155")] + public void CreateForBrowser(string userAgent) + { + HttpUserAgentPlatformInformation platformInformation = + new HttpUserAgentPlatformInformation(new Regex(""), "Android", HttpUserAgentPlatformType.Android); - HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForBrowser(userAgent, - platformInformation, "Edge", "46.3.4.5155", "Android"); + HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForBrowser(userAgent, + platformInformation, "Edge", "46.3.4.5155", "Android"); - ua.UserAgent.Should().Be(userAgent); - ua.Type.Should().Be(HttpUserAgentType.Browser); - ua.Platform.Should().Be(platformInformation); - ua.Name.Should().Be("Edge"); - ua.Version.Should().Be("46.3.4.5155"); - ua.MobileDeviceType.Should().Be("Android"); - } + ua.UserAgent.Should().Be(userAgent); + ua.Type.Should().Be(HttpUserAgentType.Browser); + ua.Platform.Should().Be(platformInformation); + ua.Name.Should().Be("Edge"); + ua.Version.Should().Be("46.3.4.5155"); + ua.MobileDeviceType.Should().Be("Android"); + } - [Theory] - [InlineData("Invalid user agent")] - public void CreateForUnknown(string userAgent) - { - HttpUserAgentPlatformInformation platformInformation = - new(new Regex(""), "Batman", HttpUserAgentPlatformType.Linux); + [Theory] + [InlineData("Invalid user agent")] + public void CreateForUnknown(string userAgent) + { + HttpUserAgentPlatformInformation platformInformation = + new(new Regex(""), "Batman", HttpUserAgentPlatformType.Linux); - HttpUserAgentInformation ua = - HttpUserAgentInformation.CreateForUnknown(userAgent, platformInformation, null); + HttpUserAgentInformation ua = + HttpUserAgentInformation.CreateForUnknown(userAgent, platformInformation, null); - ua.UserAgent.Should().Be(userAgent); - ua.Type.Should().Be(HttpUserAgentType.Unknown); - ua.Platform.Should().Be(platformInformation); - ua.Name.Should().Be(null); - ua.Version.Should().Be(null); - ua.MobileDeviceType.Should().Be(null); - } + ua.UserAgent.Should().Be(userAgent); + ua.Type.Should().Be(HttpUserAgentType.Unknown); + ua.Platform.Should().Be(platformInformation); + ua.Name.Should().Be(null); + ua.Version.Should().Be(null); + ua.MobileDeviceType.Should().Be(null); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index e97775a..9867023 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -3,150 +3,149 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentParserTests { - public class HttpUserAgentParserTests + [Theory] + // IE + [InlineData("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)", "Internet Explorer", "7.0", "Windows Vista", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", "Internet Explorer", "8.0", "Windows XP", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)", "Internet Explorer", "8.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0)", "Internet Explorer", "9.0", "Windows Vista", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)", "Internet Explorer", "9.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", "Internet Explorer", "10.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)", "Internet Explorer", "10.0", "Windows 8", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 6.2; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 8", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 8.1", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + // Chrome + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] + [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Linux", HttpUserAgentPlatformType.Linux, null)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] + [InlineData("Mozilla/5.0 (iPad; CPU OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPad")] + [InlineData("Mozilla/5.0 (iPod; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPod")] + [InlineData("Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] + [InlineData("Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] + [InlineData("Mozilla/5.0 (Linux; Android 10; LM-Q720) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] + // Safari + [InlineData("Mozilla/5.0 (Windows; U; Windows NT 10.0; en-US) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/11.0 Safari/605.1.15", "Safari", "11.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15", "Safari", "14.1", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1", "Safari", "14.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] + [InlineData("Mozilla/5.0 (iPod touch; CPU iPhone 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1", "Safari", "14.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPod")] + // Edge + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.51", "Edge", "90.0.818.51", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.51", "Edge", "90.0.818.51", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] + [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155", "Edge", "46.3.4.5155", "Android", HttpUserAgentPlatformType.Android, "Android")] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.13 Mobile/15E148 Safari/605.1.15", "Edge", "46.3.13", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64; Xbox; Xbox One) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edge/44.18363.8131", "Edge", "44.18363.8131", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + // Firefox + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11.3; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] + [InlineData("Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Linux", HttpUserAgentPlatformType.Linux, null)] + [InlineData("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Linux", HttpUserAgentPlatformType.Linux, null)] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15", "Firefox", "33.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] + [InlineData("Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/88.0", "Firefox", "88.0", "Android", HttpUserAgentPlatformType.Android, "Android")] + // Opera + [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Windows 10", HttpUserAgentPlatformType.Windows, null)] + [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] + [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Linux", HttpUserAgentPlatformType.Linux, null)] + [InlineData("Mozilla/5.0 (Linux; Android 10; VOG-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 OPR/63.0.3216.58473", "Opera", "63.0.3216.58473", "Android", HttpUserAgentPlatformType.Android, "Android")] + public void BrowserTests(string ua, string name, string version, string platformName, HttpUserAgentPlatformType platformType, string mobileDeviceType) { - [Theory] - // IE - [InlineData("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; Trident/4.0;)", "Internet Explorer", "7.0", "Windows Vista", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)", "Internet Explorer", "8.0", "Windows XP", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)", "Internet Explorer", "8.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0)", "Internet Explorer", "9.0", "Windows Vista", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)", "Internet Explorer", "9.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", "Internet Explorer", "10.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)", "Internet Explorer", "10.0", "Windows 8", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 7", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 6.2; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 8", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 8.1", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko", "Internet Explorer", "11.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - // Chrome - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] - [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36", "Chrome", "90.0.4430.212", "Linux", HttpUserAgentPlatformType.Linux, null)] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] - [InlineData("Mozilla/5.0 (iPad; CPU OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPad")] - [InlineData("Mozilla/5.0 (iPod; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/90.0.4430.78 Mobile/15E148 Safari/604.1", "Chrome", "90.0.4430.78", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPod")] - [InlineData("Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] - [InlineData("Mozilla/5.0 (Linux; Android 10; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] - [InlineData("Mozilla/5.0 (Linux; Android 10; LM-Q720) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36", "Chrome", "90.0.4430.210", "Android", HttpUserAgentPlatformType.Android, "Android")] - // Safari - [InlineData("Mozilla/5.0 (Windows; U; Windows NT 10.0; en-US) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/11.0 Safari/605.1.15", "Safari", "11.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15", "Safari", "14.1", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1", "Safari", "14.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] - [InlineData("Mozilla/5.0 (iPod touch; CPU iPhone 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1", "Safari", "14.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPod")] - // Edge - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.51", "Edge", "90.0.818.51", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.51", "Edge", "90.0.818.51", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] - [InlineData("Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 EdgA/46.3.4.5155", "Edge", "46.3.4.5155", "Android", HttpUserAgentPlatformType.Android, "Android")] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 EdgiOS/46.3.13 Mobile/15E148 Safari/605.1.15", "Edge", "46.3.13", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64; Xbox; Xbox One) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edge/44.18363.8131", "Edge", "44.18363.8131", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - // Firefox - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11.3; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] - [InlineData("Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Linux", HttpUserAgentPlatformType.Linux, null)] - [InlineData("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0", "Firefox", "88.0", "Linux", HttpUserAgentPlatformType.Linux, null)] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 11_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15", "Firefox", "33.0", "iOS", HttpUserAgentPlatformType.IOS, "Apple iPhone")] - [InlineData("Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/88.0", "Firefox", "88.0", "Android", HttpUserAgentPlatformType.Android, "Android")] - // Opera - [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Windows 10", HttpUserAgentPlatformType.Windows, null)] - [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] - [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Linux", HttpUserAgentPlatformType.Linux, null)] - [InlineData("Mozilla/5.0 (Linux; Android 10; VOG-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 OPR/63.0.3216.58473", "Opera", "63.0.3216.58473", "Android", HttpUserAgentPlatformType.Android, "Android")] - public void BrowserTests(string ua, string name, string version, string platformName, HttpUserAgentPlatformType platformType, string mobileDeviceType) - { - HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua); + HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua); - uaInfo.Name.Should().Be(name); - uaInfo.Version.Should().Be(version); - uaInfo.UserAgent.Should().Be(ua); + uaInfo.Name.Should().Be(name); + uaInfo.Version.Should().Be(version); + uaInfo.UserAgent.Should().Be(ua); - uaInfo.Type.Should().Be(HttpUserAgentType.Browser); + uaInfo.Type.Should().Be(HttpUserAgentType.Browser); - HttpUserAgentPlatformInformation platform = uaInfo.Platform.GetValueOrDefault(); - platform.PlatformType.Should().Be(platformType); - platform.Name.Should().Be(platformName); + HttpUserAgentPlatformInformation platform = uaInfo.Platform.GetValueOrDefault(); + platform.PlatformType.Should().Be(platformType); + platform.Name.Should().Be(platformName); - uaInfo.MobileDeviceType.Should().Be(mobileDeviceType); + uaInfo.MobileDeviceType.Should().Be(mobileDeviceType); - uaInfo.IsBrowser().Should().Be(true); - uaInfo.IsMobile().Should().Be(mobileDeviceType is not null); - uaInfo.IsRobot().Should().Be(false); - } + uaInfo.IsBrowser().Should().Be(true); + uaInfo.IsMobile().Should().Be(mobileDeviceType is not null); + uaInfo.IsRobot().Should().Be(false); + } - [Theory] - // Google https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers - [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", "APIs Google")] - [InlineData("Mediapartners-Google", "Mediapartners Google")] - [InlineData("Mozilla/5.0 (Linux; Android 5.0; SM-G920A) AppleWebKit (KHTML, like Gecko) Chrome Mobile Safari (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", "AdsBot Google Mobile")] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", "AdsBot Google Mobile")] - [InlineData("AdsBot-Google (+http://www.google.com/adsbot.html)", "AdsBot Google")] - [InlineData("Googlebot-Image/1.0", "Googlebot")] - [InlineData("Googlebot-News", "Googlebot")] - [InlineData("Googlebot-Video/1.0", "Googlebot")] - [InlineData("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot")] - [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/1.2.3 Safari/537.36", "Googlebot")] - [InlineData("Googlebot/2.1 (+http://www.google.com/bot.html)", "Googlebot")] - [InlineData("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.2.3 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot")] - [InlineData("Mediapartners-Google/2.1; +http://www.google.com/bot.html)", "Mediapartners Google")] - [InlineData("FeedFetcher-Google; (+http://www.google.com/feedfetcher.html)", "FeedFetcher-Google")] - [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 (compatible; Google-Read-Aloud; +https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers)", "Google-Read-Aloud")] - [InlineData("Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36 (compatible; Google-Read-Aloud; +https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers)", "Google-Read-Aloud")] - [InlineData("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012; DuplexWeb-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Mobile Safari/537.36", "DuplexWeb-Google")] - [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 Google Favicon", "Google Favicon")] - [InlineData("Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19", "Google Web Light")] - [InlineData("Mozilla/5.0 (X11; Linux x86_64; Storebot-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36", "Storebot-Google")] - [InlineData("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012; Storebot-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36", "Storebot-Google")] - // Bing - [InlineData("Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] - [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] - [InlineData("Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] - [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/1.2.3.4 Safari/537.36 Edg/1.2.3.4", "BingBot")] - [InlineData("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.2.3.4  Mobile Safari/537.36 Edg/1.2.3.4 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] - [InlineData("Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", "Baiduspider")] - [InlineData("Mozilla/5.0 (compatible; MJ12bot/v1.4.5; http://www.majestic12.co.uk/bot.php?+)", "Majestic")] - [InlineData("Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)", "Slurp")] - [InlineData("Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +http://megaindex.com/crawler)", "MegaIndex")] - [InlineData("Mozilla/5.0 (compatible; AhrefsBot/5.2; +http://ahrefs.com/robot/)", "Ahrefs")] - [InlineData("Mozilla/5.0 (compatible; SemrushBot/7~bl; +http://www.semrush.com/bot.html)", "SEMRush")] - [InlineData("Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)", "OpenSite")] - [InlineData("Mozilla/5.0 (X11; U; Linux Core i7-4980HQ; de; rv:32.0; compatible; JobboerseBot; http://www.jobboerse.com/bot.htm) Gecko/20100101 Firefox/38.0", "Jobboerse")] - [InlineData("Mozilla/5.0 (compatible; MJ12bot/v1.4.8; http://mj12bot.com/)", "Majestic")] - [InlineData("Mozilla/5.0 (compatible; SemrushBot/2~bl; +http://www.semrush.com/bot.html)", "SEMRush")] - [InlineData("Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "YandexBot")] - [InlineData("Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)", "YandexImages")] - [InlineData("Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)", "Slurp")] - [InlineData("msnbot/1.0 (+http://search.msn.com/msnbot.htm)", "MSNBot")] - [InlineData("msnbot/2.0b (+http://search.msn.com/msnbot.htm)", "MSNBot")] - [InlineData("Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot/)", "Ahrefs")] - [InlineData("Mozilla/5.0 (compatible; seoscanners.net/1; +spider@seoscanners.net)", "SEO Scanners")] - [InlineData("Mozilla/5.0 (compatible; SEOkicks-Robot; +http://www.seokicks.de/robot.html)", "SEOkicks")] - [InlineData("facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", "Facebook")] - [InlineData("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b", "Bing Preview")] - [InlineData("CheckMarkNetwork/1.0 (+http://www.checkmarknetwork.com/spider.html)", "CheckMark")] - [InlineData("Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)", "BLEXBot")] - [InlineData("Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/Fast/2.0; +http://go.mail.ru/help/robots)", "Mail.ru")] - [InlineData("Mozilla/5.0 (compatible; adscanner/)", "AdScanner")] - [InlineData("Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)", "Sistrix")] - [InlineData("Mozilla/5.0 (Linux; Android 7.0;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; PetalBot;+https://aspiegel.com/petalbot)", "PetalBot")] - public void BotTests(string ua, string name) - { - HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua); + [Theory] + // Google https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers + [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", "APIs Google")] + [InlineData("Mediapartners-Google", "Mediapartners Google")] + [InlineData("Mozilla/5.0 (Linux; Android 5.0; SM-G920A) AppleWebKit (KHTML, like Gecko) Chrome Mobile Safari (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", "AdsBot Google Mobile")] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", "AdsBot Google Mobile")] + [InlineData("AdsBot-Google (+http://www.google.com/adsbot.html)", "AdsBot Google")] + [InlineData("Googlebot-Image/1.0", "Googlebot")] + [InlineData("Googlebot-News", "Googlebot")] + [InlineData("Googlebot-Video/1.0", "Googlebot")] + [InlineData("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot")] + [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/1.2.3 Safari/537.36", "Googlebot")] + [InlineData("Googlebot/2.1 (+http://www.google.com/bot.html)", "Googlebot")] + [InlineData("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.2.3 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot")] + [InlineData("Mediapartners-Google/2.1; +http://www.google.com/bot.html)", "Mediapartners Google")] + [InlineData("FeedFetcher-Google; (+http://www.google.com/feedfetcher.html)", "FeedFetcher-Google")] + [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 (compatible; Google-Read-Aloud; +https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers)", "Google-Read-Aloud")] + [InlineData("Mozilla/5.0 (Linux; Android 7.0; SM-G930V Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36 (compatible; Google-Read-Aloud; +https://developers.google.com/search/docs/advanced/crawling/overview-google-crawlers)", "Google-Read-Aloud")] + [InlineData("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012; DuplexWeb-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Mobile Safari/537.36", "DuplexWeb-Google")] + [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 Google Favicon", "Google Favicon")] + [InlineData("Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19", "Google Web Light")] + [InlineData("Mozilla/5.0 (X11; Linux x86_64; Storebot-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36", "Storebot-Google")] + [InlineData("Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012; Storebot-Google/1.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Mobile Safari/537.36", "Storebot-Google")] + // Bing + [InlineData("Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] + [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] + [InlineData("Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] + [InlineData("Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/1.2.3.4 Safari/537.36 Edg/1.2.3.4", "BingBot")] + [InlineData("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/1.2.3.4  Mobile Safari/537.36 Edg/1.2.3.4 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "BingBot")] + [InlineData("Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", "Baiduspider")] + [InlineData("Mozilla/5.0 (compatible; MJ12bot/v1.4.5; http://www.majestic12.co.uk/bot.php?+)", "Majestic")] + [InlineData("Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)", "Slurp")] + [InlineData("Mozilla/5.0 (compatible; MegaIndex.ru/2.0; +http://megaindex.com/crawler)", "MegaIndex")] + [InlineData("Mozilla/5.0 (compatible; AhrefsBot/5.2; +http://ahrefs.com/robot/)", "Ahrefs")] + [InlineData("Mozilla/5.0 (compatible; SemrushBot/7~bl; +http://www.semrush.com/bot.html)", "SEMRush")] + [InlineData("Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)", "OpenSite")] + [InlineData("Mozilla/5.0 (X11; U; Linux Core i7-4980HQ; de; rv:32.0; compatible; JobboerseBot; http://www.jobboerse.com/bot.htm) Gecko/20100101 Firefox/38.0", "Jobboerse")] + [InlineData("Mozilla/5.0 (compatible; MJ12bot/v1.4.8; http://mj12bot.com/)", "Majestic")] + [InlineData("Mozilla/5.0 (compatible; SemrushBot/2~bl; +http://www.semrush.com/bot.html)", "SEMRush")] + [InlineData("Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "YandexBot")] + [InlineData("Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)", "YandexImages")] + [InlineData("Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; http://help.yahoo.com/help/us/ysearch/slurp)", "Slurp")] + [InlineData("msnbot/1.0 (+http://search.msn.com/msnbot.htm)", "MSNBot")] + [InlineData("msnbot/2.0b (+http://search.msn.com/msnbot.htm)", "MSNBot")] + [InlineData("Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://ahrefs.com/robot/)", "Ahrefs")] + [InlineData("Mozilla/5.0 (compatible; seoscanners.net/1; +spider@seoscanners.net)", "SEO Scanners")] + [InlineData("Mozilla/5.0 (compatible; SEOkicks-Robot; +http://www.seokicks.de/robot.html)", "SEOkicks")] + [InlineData("facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)", "Facebook")] + [InlineData("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b", "Bing Preview")] + [InlineData("CheckMarkNetwork/1.0 (+http://www.checkmarknetwork.com/spider.html)", "CheckMark")] + [InlineData("Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)", "BLEXBot")] + [InlineData("Mozilla/5.0 (compatible; Linux x86_64; Mail.RU_Bot/Fast/2.0; +http://go.mail.ru/help/robots)", "Mail.ru")] + [InlineData("Mozilla/5.0 (compatible; adscanner/)", "AdScanner")] + [InlineData("Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)", "Sistrix")] + [InlineData("Mozilla/5.0 (Linux; Android 7.0;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; PetalBot;+https://aspiegel.com/petalbot)", "PetalBot")] + public void BotTests(string ua, string name) + { + HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua); - uaInfo.Name.Should().Be(name); - uaInfo.Version.Should().Be(null); - uaInfo.UserAgent.Should().Be(ua); + uaInfo.Name.Should().Be(name); + uaInfo.Version.Should().Be(null); + uaInfo.UserAgent.Should().Be(ua); - uaInfo.Type.Should().Be(HttpUserAgentType.Robot); + uaInfo.Type.Should().Be(HttpUserAgentType.Robot); - uaInfo.Platform.Should().Be(null); - uaInfo.MobileDeviceType.Should().Be(null); + uaInfo.Platform.Should().Be(null); + uaInfo.MobileDeviceType.Should().Be(null); - uaInfo.IsBrowser().Should().Be(false); - uaInfo.IsMobile().Should().Be(false); - uaInfo.IsRobot().Should().Be(true); - } + uaInfo.IsBrowser().Should().Be(false); + uaInfo.IsMobile().Should().Be(false); + uaInfo.IsRobot().Should().Be(true); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs index 5b0ba67..c394d6f 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformInformationTests.cs @@ -4,22 +4,21 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentPlatformInformationTests { - public class HttpUserAgentPlatformInformationTests + [Theory] + [InlineData("Batman", HttpUserAgentPlatformType.Android)] + [InlineData("Robin", HttpUserAgentPlatformType.Windows)] + public void Ctor(string name, HttpUserAgentPlatformType platform) { - [Theory] - [InlineData("Batman", HttpUserAgentPlatformType.Android)] - [InlineData("Robin", HttpUserAgentPlatformType.Windows)] - public void Ctor(string name, HttpUserAgentPlatformType platform) - { - Regex regex = new(""); + Regex regex = new(""); - HttpUserAgentPlatformInformation info = new(regex, name, platform); + HttpUserAgentPlatformInformation info = new(regex, name, platform); - info.Regex.Should().Be(regex); - info.Name.Should().Be(name); - info.PlatformType.Should().Be(platform); - } + info.Regex.Should().Be(regex); + info.Name.Should().Be(name); + info.PlatformType.Should().Be(platform); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs index cf37a88..5a0b9eb 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentPlatformTypeTests.cs @@ -3,24 +3,23 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentPlatformTypeTests { - public class HttpUserAgentPlatformTypeTests + [Theory] + [InlineData(HttpUserAgentPlatformType.Unknown, 0)] + [InlineData(HttpUserAgentPlatformType.Generic, 1)] + [InlineData(HttpUserAgentPlatformType.Windows, 2)] + [InlineData(HttpUserAgentPlatformType.Linux, 3)] + [InlineData(HttpUserAgentPlatformType.Unix, 4)] + [InlineData(HttpUserAgentPlatformType.IOS, 5)] + [InlineData(HttpUserAgentPlatformType.MacOS, 6)] + [InlineData(HttpUserAgentPlatformType.BlackBerry, 7)] + [InlineData(HttpUserAgentPlatformType.Android, 8)] + [InlineData(HttpUserAgentPlatformType.Symbian, 9)] + public void TestValue(HttpUserAgentPlatformType type, byte value) { - [Theory] - [InlineData(HttpUserAgentPlatformType.Unknown, 0)] - [InlineData(HttpUserAgentPlatformType.Generic, 1)] - [InlineData(HttpUserAgentPlatformType.Windows, 2)] - [InlineData(HttpUserAgentPlatformType.Linux, 3)] - [InlineData(HttpUserAgentPlatformType.Unix, 4)] - [InlineData(HttpUserAgentPlatformType.IOS, 5)] - [InlineData(HttpUserAgentPlatformType.MacOS, 6)] - [InlineData(HttpUserAgentPlatformType.BlackBerry, 7)] - [InlineData(HttpUserAgentPlatformType.Android, 8)] - [InlineData(HttpUserAgentPlatformType.Symbian, 9)] - public void TestValue(HttpUserAgentPlatformType type, byte value) - { - ((byte)type == value).Should().Be(true); - } + ((byte)type == value).Should().Be(true); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs index 64feaaf..1953f9d 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentTypeTests.cs @@ -3,17 +3,16 @@ using FluentAssertions; using Xunit; -namespace MyCSharp.HttpUserAgentParser.UnitTests +namespace MyCSharp.HttpUserAgentParser.UnitTests; + +public class HttpUserAgentTypeTests { - public class HttpUserAgentTypeTests + [Theory] + [InlineData(HttpUserAgentType.Unknown, 0)] + [InlineData(HttpUserAgentType.Browser, 1)] + [InlineData(HttpUserAgentType.Robot, 2)] + public void TestValue(HttpUserAgentType type, byte value) { - [Theory] - [InlineData(HttpUserAgentType.Unknown, 0)] - [InlineData(HttpUserAgentType.Browser, 1)] - [InlineData(HttpUserAgentType.Robot, 2)] - public void TestValue(HttpUserAgentType type, byte value) - { - ((byte)type == value).Should().Be(true); - } + ((byte)type == value).Should().Be(true); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj index 7e47a28..56815d6 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj @@ -1,4 +1,4 @@ - + Exe @@ -9,7 +9,7 @@ - + all