Ejemplo n.º 1
0
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Command-line arguments</param>
        static void Main(string[] args)
        {
            if (args.Length != 3 ||
                !args[0].Equals("convert") ||
                !Uri.IsWellFormedUriString(args[1], UriKind.Absolute) ||
                string.IsNullOrEmpty(args[2]))
            {
                Console.WriteLine("Invalid arguments for file logging.");
                Console.WriteLine("Review them, please!");
                Environment.Exit(0);
            }

            List <LogFile> log = ReadLog(new StreamReader(new HttpClient().GetStreamAsync(args[1]).Result));

            #region MinhaCDN File
            //MinhaCdn minhaCdn = new MinhaCdn(log, args[2]);
            //minhaCdn.CreateLog();
            #endregion

            #region Agora File
            Agora     agora   = new Agora(log, args[2]);
            IMinhaCdn adapter = new AgoraAdapter(agora);

            Log(adapter);
            #endregion
        }
Ejemplo n.º 2
0
        public void CreateLogTest()
        {
            int count = 0;

            var path     = "./output/test/minhaCdn1.txt";
            var response = "312|200|HIT|\"GET /robots.txt HTTP/1.1\"|100.2\n" +
                           "101|200|MISS|\"POST /myImages HTTP/1.1\"|319.4\n" +
                           "199|404|MISS|\"GET /not-found HTTP/1.1\"|142.9\n" +
                           "312|200|INVALIDATE|\"GET /robots.txt HTTP/1.1\"|245.1\n";

            var messageHandler = new MockHttpMessageHandler(response, HttpStatusCode.OK);
            var httpClient     = new HttpClient(messageHandler);
            var streamReader   = new StreamReader(httpClient.GetStreamAsync("http://exempligratia.com/testing/arquivo.txt").Result);
            var log            = Program.ReadLog(streamReader);

            Agora     agora   = new Agora(log, path);
            IMinhaCdn adapter = new AgoraAdapter(agora);

            Program.Log(adapter);

            using (StreamReader streamReaderLog = File.OpenText(path))
            {
                string line;
                while ((line = streamReaderLog.ReadLine()) != null)
                {
                    count++;
                }
            }

            // Minha CDN Header: 3 lines
            Assert.AreEqual((count - 3), log.Count);
        }