public void TestGetStoryJsonStory()
        {
            //Testing that the following Json is returned:

            /*
             * {
             *  "by" : "dhouston",
             *  "descendants" : 71,
             *   "id" : 8863,
             *  "kids" : [ 8952, 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055, 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907, 8894, 8878, 8870, 8980, 8934, 8876 ],
             *  "score" : 111,
             *  "time" : 1175714200,
             *  "title" : "My YC app: Dropbox - Throw away your USB drive",
             *  "type" : "story",
             *  "url" : "http://www.getdropbox.com/u/2/screencast.html"
             *  }
             */
            TrueLayerHackerNews.TrueLayerHackerNews trueLayerHackerNews = new TrueLayerHackerNews.TrueLayerHackerNews();
            WebClient          webclient = new WebClient();
            RetrieveStoryModel rsm       = trueLayerHackerNews.getStoryJson("8863");

            Assert.AreEqual(rsm.Id, 8863);
            Assert.AreEqual(rsm.Descendants, 71);
            Assert.AreEqual(rsm.hackerNewsType, "story");
        }
        public void TestReturnStoryModel100()
        {
            TrueLayerHackerNews.TrueLayerHackerNews trueLayerHackerNews = new TrueLayerHackerNews.TrueLayerHackerNews();

            trueLayerHackerNews.returnStoryModels(100);

            Assert.AreEqual(trueLayerHackerNews.storyList.Count, 100);
        }
        public void TestGetTopStories()
        {
            //Test that running the get top stories return a list of 500 strings
            const string testUrl = "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty";

            TrueLayerHackerNews.TrueLayerHackerNews trueLayerHackerNews = new TrueLayerHackerNews.TrueLayerHackerNews();
            WebClient webclient = new WebClient();

            List <string> returnList = trueLayerHackerNews.getObejctFromAPI <List <string> >(testUrl);

            Assert.AreEqual(returnList.Count, 500);
        }
Пример #4
0
        static void Main(string[] args)
        {
            TrueLayerHackerNews trueLayerHackerNews = new TrueLayerHackerNews();
            int  numberOfStories = 0;
            bool inputCorrect    = false;

            //Checking user input
            while (!inputCorrect)
            {
                /*bool firstTest = args.Length != 2;
                 * bool secondTest = args[0] == "--posts";
                 * bool thirdTest = !Int32.TryParse(args[1], out numberOfStories);
                 * bool fouthTest = numberOfStories > 100; */
                if (args.Length != 2 || args[0] != "--posts" || !Int32.TryParse(args[1], out numberOfStories) || numberOfStories > 100)
                {
                    Console.WriteLine("Please enter a valid format of arguments in the following format:");
                    Console.WriteLine("--posts n \n Where posts how many posts to print. N = positive integer <= 100");
                    Console.WriteLine("Please enter new args");
                    args = Console.ReadLine().Split(" ");
                }
                else
                {
                    inputCorrect = true;
                }
            }
            Console.WriteLine("Your json file is being created please stand by...");

            trueLayerHackerNews.returnStoryModels(numberOfStories);


            string TestPath = AppDomain.CurrentDomain.BaseDirectory + numberOfStories + "HackerNewsStories.json";

            trueLayerHackerNews.writeJSONtoFile(TestPath);

            Console.WriteLine("Your file has been created at been create at " + TestPath);
            Console.WriteLine("press any button followed by enter to exit the program");
            Console.ReadLine();
        }