Ejemplo n.º 1
0
        /// <summary>
        /// This is an helper method to test if the created <see cref="UserAgentAnalyzer"/> works as exected.
        /// </summary>
        /// <param name="userAgentAnalyzer">The userAgentAnalyzer<see cref="UserAgentAnalyzerDirect"/></param>
        private void RunTestCase(AbstractUserAgentAnalyzerDirect userAgentAnalyzer)
        {
            var parsedAgent = userAgentAnalyzer.Parse("Mozilla/5.0 (Linux; Android 7.0; Nexus 6 Build/NBD90Z) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.124 Mobile Safari/537.36");

            // The requested fields
            parsedAgent.GetValue("DeviceClass").Should().Be("Phone");               // Phone
            parsedAgent.GetValue("AgentNameVersionMajor").Should().Be("Chrome 53"); // Chrome 53

            // The fields that are internally needed to build the requested fields
            parsedAgent.GetValue("AgentName").Should().Be("Chrome");           // Chrome
            parsedAgent.GetValue("AgentVersion").Should().Be("53.0.2785.124"); // 53.0.2785.124
            parsedAgent.GetValue("AgentVersionMajor").Should().Be("53");       // 53

            long min1 = -1;

            // The rest must be at confidence -1 (i.e. no rules fired)
            parsedAgent.GetConfidence("DeviceName").Should().Be(min1);                   // Nexus 6
            parsedAgent.GetConfidence("DeviceBrand").Should().Be(min1);                  // Google
            parsedAgent.GetConfidence("OperatingSystemClass").Should().Be(min1);         // Mobile
            parsedAgent.GetConfidence("OperatingSystemName").Should().Be(min1);          // Android
            parsedAgent.GetConfidence("OperatingSystemVersion").Should().Be(min1);       // 7.0
            parsedAgent.GetConfidence("OperatingSystemNameVersion").Should().Be(min1);   // Android 7.0
            parsedAgent.GetConfidence("OperatingSystemVersionBuild").Should().Be(min1);  // NBD90Z
            parsedAgent.GetConfidence("LayoutEngineClass").Should().Be(min1);            // Browser
            parsedAgent.GetConfidence("LayoutEngineName").Should().Be(min1);             // Blink
            parsedAgent.GetConfidence("LayoutEngineVersion").Should().Be(min1);          // 53.0
            parsedAgent.GetConfidence("LayoutEngineVersionMajor").Should().Be(min1);     // 53
            parsedAgent.GetConfidence("LayoutEngineNameVersion").Should().Be(min1);      // Blink 53.0
            parsedAgent.GetConfidence("LayoutEngineNameVersionMajor").Should().Be(min1); // Blink 53
            parsedAgent.GetConfidence("AgentClass").Should().Be(min1);                   // Browser
            parsedAgent.GetConfidence("AgentNameVersion").Should().Be(min1);             // Chrome 53.0.2785.124
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Informs about parsed values in path.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="value">The value.</param>
 /// <param name="ctx">The context node.</param>
 public void Inform(string path, string value, IParseTree ctx)
 {
     this.Values.Add(path);
     this.Values.Add($"{path}=\"{value}\"");
     this.Values.Add($"{path}{{\"{AbstractUserAgentAnalyzerDirect.FirstCharactersForPrefixHash(value, AbstractUserAgentAnalyzerDirect.MAX_PREFIX_HASH_MATCH)}\"");
 }