示例#1
0
        public void NoSpacesPerformanceTest()
        {
            NoSpacesTest();
            HttpResultCleaner agodaCleaner = new HttpResultCleaner(new DefaultCleaner(
                                                                       new NoSpaces("<auth><user>{templValue:user}</user><pass>{templValue:pass}</pass></auth>"),
                                                                       null,
                                                                       null));
            int clearCount = 1000000;
            var timer      = Stopwatch.StartNew();

            for (int i = 1; i < clearCount; i++)
            {
                var             rndStringUsr    = Path.GetRandomFileName();
                var             rndStringPass   = Path.GetRandomFileName();
                AgodaHttpResult agodaHttpResult = new AgodaHttpResult
                {
                    Url          = "<auth><user>" + rndStringUsr + "</user><pass>" + rndStringPass + "</pass></auth>",
                    RequestBody  = rndStringUsr,
                    ResponseBody = rndStringPass
                };
                agodaHttpResult = (AgodaHttpResult)agodaCleaner.Clean(agodaHttpResult);
                Assert.AreEqual(agodaHttpResult.Url, "<auth><user>" + new String('X', rndStringUsr.Length) + "</user><pass>" + new String('X', rndStringUsr.Length) + "</pass></auth>");
            }
            timer.Stop();
            using (FileStream fs = new FileInfo("NoSpacesPerformanceTestResult.txt").OpenWrite())
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine("Time for {0} cleans: {1} ms", clearCount, timer.Elapsed.TotalMilliseconds);
                }
            }
        }
        public void HttpResultCleanerThreadingTest()
        {
            HttpResultCleaner resCleaner = new HttpResultCleaner(new DefaultCleaner(
                                                                     new NoSpaces("http://test.com?user={templValue:user}&pass={templValue:pass}"),
                                                                     new NoSpaces("<auth><user>{templValue:user}</user><pass>{templValue:pass}</pass></auth>"),
                                                                     new SomeSeparators("<auth user='******' pass='******'>")));

            for (int j = 0; j < 100; j++)
            {
                new Thread(() =>
                {
                    for (int i = 1; i < 10000; i++)
                    {
                        var rndStringUsr  = Path.GetRandomFileName();
                        var rndStringPass = Path.GetRandomFileName();
                        AgodaHttpResult agodaHttpResult = new AgodaHttpResult
                        {
                            Url          = "http://test.com?user="******"&pass="******"<auth><user>" + rndStringUsr + "</user><pass>" + rndStringPass + "</pass></auth>",
                            ResponseBody = "<auth user='******' pass='******'>"
                        };
                        agodaHttpResult = (AgodaHttpResult)resCleaner.Clean(agodaHttpResult);
                        Assert.AreEqual(agodaHttpResult.Url,
                                        "http://test.com?user="******"&pass="******"<auth><user>" + new String('X', rndStringUsr.Length) + "</user><pass>" +
                                        new String('X', rndStringUsr.Length) + "</pass></auth>");
                        Assert.AreEqual(agodaHttpResult.ResponseBody,
                                        "<auth user='******'X', rndStringUsr.Length) + "' pass='******'X', rndStringUsr.Length) + "'>");
                    }
                }).Start();
            }
        }