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)
            {
                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);
        }
        public void Parse(string userAgent)
        {
            HttpUserAgentInformation ua1 = HttpUserAgentParser.Parse(userAgent);
            HttpUserAgentInformation ua2 = HttpUserAgentInformation.Parse(userAgent);

            ua1.Should().BeEquivalentTo(ua2);
        }
        public void Parse(string userAgent)
        {
            HttpUserAgentParserDefaultProvider provider = new();

            HttpUserAgentInformation providerUserAgentInfo = provider.Parse(userAgent);
            HttpUserAgentInformation userAgentInfo         = HttpUserAgentInformation.Parse(userAgent);

            providerUserAgentInfo.Should().BeEquivalentTo(userAgentInfo);
        }
        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.Type.Should().Be(HttpUserAgentType.Robot);

            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);
        }
        public void Get(string userAgent)
        {
            HttpUserAgentInformation userAgentInformation = HttpUserAgentInformation.Parse(userAgent);

            Mock <IHttpContextAccessor> httpMock = new();
            {
                DefaultHttpContext context = new DefaultHttpContext();
                context.Request.Headers["User-Agent"] = userAgent;
                httpMock.Setup(_ => _.HttpContext).Returns(context);
            }
            Mock <IHttpUserAgentParserProvider> parserMock = new();
            {
                parserMock.Setup(x => x.Parse(userAgent)).Returns(userAgentInformation);
            }

            HttpUserAgentParserAccessor accessor = new HttpUserAgentParserAccessor(httpMock.Object, parserMock.Object);
            HttpUserAgentInformation    info     = accessor.Get();

            info.Should().Be(userAgentInformation);
            parserMock.Verify(x => x.Parse(userAgent), Times.Once);
        }
        public void BrowserTests(string ua, string name, string version, string platformName, HttpUserAgentPlatformType platformType, string mobileDeviceType)
        {
            HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua);

            uaInfo.Name.Should().Be(name);
            uaInfo.Version.Should().Be(version);
            uaInfo.UserAgent.Should().Be(ua);

            uaInfo.Type.Should().Be(HttpUserAgentType.Browser);

            HttpUserAgentPlatformInformation platform = uaInfo.Platform.GetValueOrDefault();

            platform.PlatformType.Should().Be(platformType);
            platform.Name.Should().Be(platformName);

            uaInfo.MobileDeviceType.Should().Be(mobileDeviceType);

            uaInfo.IsBrowser().Should().Be(true);
            uaInfo.IsMobile().Should().Be(mobileDeviceType is not null);
            uaInfo.IsRobot().Should().Be(false);
        }