示例#1
0
        static void Main(string[] args)
        {
            var      console         = new ConsoleOutput();
            var      storage         = new StoredResults(console);
            var      downloader      = new SeleniumWebDownloader();
            var      charsCounter    = new CharsCounter();
            var      sinceLastUpdate = TimeSpan.FromMinutes(1);
            var      results         = new List <Dictionary <char, int> >();
            DateTime lastUpdate      = DateTime.Now;

            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                if (sinceLastUpdate >= TimeSpan.FromMinutes(0.5))
                {
                    results = storage.Load();
                    var headers    = downloader.DownloadHeaders("https://www.finai.pl/blog");
                    var charsCount = charsCounter.CountChars(headers);
                    if (charsCount != null)
                    {
                        results.Add(charsCount);
                    }
                    if (results.Count > 5)
                    {
                        results.RemoveAt(0);
                    }
                    storage.Save(results);
                    console.WriteAllChars(results);
                    lastUpdate = DateTime.Now;
                }
                sinceLastUpdate = DateTime.Now - lastUpdate;
            }
        }
        public void SeleniumWebDownloader_Download_ShouldReturn20Items()
        {
            var downloader = new SeleniumWebDownloader();
            var items      = downloader.DownloadHeaders("https://www.finai.pl/blog");

            Assert.IsTrue(items.Count == 20);
        }
        public void CharsCounter_CountChars_ShouldReturnCounter()
        {
            var downloader     = new SeleniumWebDownloader();
            var items          = downloader.DownloadHeaders("https://www.finai.pl/blog");
            var counter        = new CharsCounter();
            var lettersCounted = counter.CountChars(items);

            CollectionAssert.AllItemsAreUnique(lettersCounted);
        }