コード例 #1
0
        public void TestPostPreheatDroptests()
        {
            var userAgentAnalyzer =
                UserAgentAnalyzer
                .NewBuilder()
                .ImmediateInitialization()
                // Without .preheat(100)
                .DropTests()
                .HideMatcherLoadStats()
                .WithField("AgentName")
                .Build();

            userAgentAnalyzer.NumberOfTestCases.Should().Be(0);

            userAgentAnalyzer =
                UserAgentAnalyzer
                .NewBuilder()
                .ImmediateInitialization()
                .Preheat(100)     // With .preheat(100)
                .DropTests()
                .HideMatcherLoadStats()
                .WithField("AgentName")
                .Build();
            userAgentAnalyzer.NumberOfTestCases.Should().Be(0);
        }
コード例 #2
0
 public void GlobalSetup()
 {
     uaa = UserAgentAnalyzer.NewBuilder()
           .WithoutCache()
           .HideMatcherLoadStats()
           .Build();
     uaa.Parse((string)null);
 }
コード例 #3
0
        public void TestDualBuilderUsageNoSecondInstance()
        {
            var builder = UserAgentAnalyzer.NewBuilder().DelayInitialization();

            builder.Build().Should().NotBeNull("We should get a first instance from a single builder.");
            // And calling build() again should fail with an exception
            var a = new Action(() => builder.Build());

            a.Should().Throw <Exception>();
        }
コード例 #4
0
        public void TestDualBuilderUsageUseSetterAfterBuild()
        {
            var builder = UserAgentAnalyzer.NewBuilder().DelayInitialization();

            builder.Build().Should().NotBeNull("We should get a first instance from a single builder.");

            // And calling a setter after the build() should fail with an exception
            var a = new Action(() => builder.WithCache(1234));

            a.Should().Throw <Exception>();
        }
コード例 #5
0
        public void TestLoadMoreResources()
        {
            var builder = UserAgentAnalyzer.NewBuilder().DelayInitialization().WithField("DeviceClass");

            var uaa = builder.Build();

            builder.Should().NotBeNull("We should get a first instance from a single builder.");

            uaa.InitializeMatchers();
            var a = new Action(() => uaa.LoadResources("Something extra"));

            a.Should().Throw <Exception>();
        }
コード例 #6
0
        /// <summary>
        /// I run the the test in the input file and I check that it throws the expected exteption message.
        /// </summary>
        /// <param name="inputFilename">The inputFilename<see cref="string"/></param>
        /// <param name="message">The message<see cref="string"/></param>
        private void RunTest(string inputFilename, string message)
        {
            var uaaB = UserAgentAnalyzer
                       .NewBuilder()
                       .DropDefaultResources()
                       .KeepTests()
                       .AddResources($"{Config.RESOURCES_PATH}{Path.DirectorySeparatorChar}YamlParsingTests", inputFilename)
                       .DelayInitialization();


            var a = new Action(() => { uaaB.Build(); });

            a.Should().Throw <InvalidParserConfigurationException>().Where(e => e.Message.Contains(message));
        }
コード例 #7
0
        public void TestAskingForImpossibleField()
        {
            var uaa = UserAgentAnalyzer
                      .NewBuilder()
                      .WithoutCache()
                      .HideMatcherLoadStats()
                      .DelayInitialization()
                      .WithField("FirstNonexistentField")
                      .WithField("DeviceClass")
                      .WithField("SecondNonexistentField");
            var a = new Action(() => uaa.Build());

            a.Should().Throw <InvalidParserConfigurationException>().WithMessage("We cannot provide these fields: [FirstNonexistentField] [SecondNonexistentField]");
        }
コード例 #8
0
        public void TestLimitedFieldsDirect()
        {
            var builder           = UserAgentAnalyzer.NewBuilder();
            var userAgentAnalyzer = builder
                                    .Preheat(100)
                                    .Preheat()
                                    .HideMatcherLoadStats()
                                    .ShowMatcherLoadStats()
                                    .WithAllFields()
                                    .WithField("DeviceClass")
                                    .WithField("AgentNameVersionMajor")
                                    .WithUserAgentMaxLength(1234)
                                    .Build();

            userAgentAnalyzer.GetUserAgentMaxLength().Should().Be(1234);

            this.RunTestCase(userAgentAnalyzer);
        }
コード例 #9
0
        public void TestPreheatNoTests()
        {
            var userAgentAnalyzer =
                UserAgentAnalyzer
                .NewBuilder()
                .KeepTests()
                .HideMatcherLoadStats()
                .WithField("AgentName")
                .Build();

            userAgentAnalyzer.NumberOfTestCases.Should().BeGreaterThan(100);
            userAgentAnalyzer.PreHeat(0).Should().Be(0);
            userAgentAnalyzer.PreHeat(-1).Should().Be(0);
            userAgentAnalyzer.PreHeat(1000000000L).Should().Be(0);

            userAgentAnalyzer.DropTests();
            userAgentAnalyzer.NumberOfTestCases.Should().Be(0);
            userAgentAnalyzer.PreHeat().Should().Be(0);
        }
コード例 #10
0
        public void TestLoadOnlyCustomRules()
        {
            var userAgentAnalyzer =
                UserAgentAnalyzer
                .NewBuilder()
                .WithoutCache()
                .HideMatcherLoadStats()
                .AddResources(Config.RESOURCES_PATH, "ExtraLoadedRule1.yaml")
                .WithField("ExtraValue2")
                .WithField("ExtraValue1")
                .AddResources(Config.RESOURCES_PATH, "ExtraLoadedRule2.yaml")
                .Build();

            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("ExtraValue1").Should().Be("One");
            parsedAgent.GetValue("ExtraValue2").Should().Be("Two");
        }
コード例 #11
0
        public void TestLoadOnlyCompanyCustomFormatRules()
        {
            var userAgentAnalyzer =
                UserAgentAnalyzer
                .NewBuilder()
                .WithoutCache()
                .HideMatcherLoadStats()
                .DropDefaultResources()
                .AddResources(Config.RESOURCES_PATH, "CompanyInternalUserAgents.yaml")
                .WithFields("ApplicationName", "ApplicationVersion")
                .WithFields("ApplicationInstance", "ApplicationGitCommit")
                .WithField("ServerName")
                .Build();

            var parsedAgent = userAgentAnalyzer.Parse("TestApplication/1.2.3 (node123.datacenter.example.nl; 1234; d71922715c2bfe29343644b14a4731bf5690e66e)");

            // The requested fields
            parsedAgent.GetValue("ApplicationName").Should().Be("TestApplication");
            parsedAgent.GetValue("ApplicationVersion").Should().Be("1.2.3");
            parsedAgent.GetValue("ApplicationInstance").Should().Be("1234");
            parsedAgent.GetValue("ApplicationGitCommit").Should().Be("d71922715c2bfe29343644b14a4731bf5690e66e");
            parsedAgent.GetValue("ServerName").Should().Be("node123.datacenter.example.nl");
        }