public void ParseLineSuccess()
        {
            ISiteCredentialParser parser = ObjectFactory.GetInstance <ISiteCredentialParser>();

            Site site = null;

            foreach (string line in lines.Keys)
            {
                site = parser.ParseLine(line);
                Assert.AreEqual(site.ToString(), lines[line]);
            }
        }
        public void ParseFileSuccess()
        {
            //Create file
            System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true);

            foreach (string line in lines.Keys)
            {
                file.WriteLine(line);
            }
            file.Close();

            //test parser
            ISiteCredentialParser parser = ObjectFactory.GetInstance <ISiteCredentialParser>();

            parser.ParseFile(fileName);

            //delete file
            File.Delete(fileName);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Configure simple DI container
            Configure();

            //Get parser and website checker instances
            ISiteCredentialParser parser         = ObjectFactory.GetInstance <ISiteCredentialParser>();
            IWebSiteChecker       webSiteChecker = ObjectFactory.GetInstance <IWebSiteChecker>();

            //If there are arguments, take first as filename. Would be a bit more sophisticated in real life of course.
            if (args.Length != 0)
            {
                fileName = args[0];
            }

            //Parse file
            List <Site> sites = parser.ParseFile(fileName);

            //And order results. I didn't put that in service not to generate not neeeded overhead. Not always we need sorted list.
            sites = sites.OrderBy(p => p.Name).ToList();

            //While printing each Site details we will count total credentials.
            //Could be done by var totalCredentials = (from s in sites select s.LoginCredentials.Count).Sum(); but we must pass the list anyway.
            int totalCredentials = 0;

            //Print results
            foreach (Site site in sites)
            {
                Console.WriteLine(
                    String.Format("{0}\tIsOnline: {1}", site.ToString(), webSiteChecker.IsOnline(site.Url).ToString())
                    );

                totalCredentials += site.LoginCredentials.Count;
            }

            //Empty line and total number of credentials
            Console.WriteLine();
            Console.WriteLine("Total number of credentials: " + totalCredentials);

            Console.ReadLine();
        }
        public void ParseFileMissingFile()
        {
            ISiteCredentialParser parser = ObjectFactory.GetInstance <ISiteCredentialParser>();

            parser.ParseFile("");
        }
        public void ParseLineThrowsArgumentException()
        {
            ISiteCredentialParser parser = ObjectFactory.GetInstance <ISiteCredentialParser>();

            Site site = parser.ParseLine("test");
        }