public void Should_save_the_content_of_a_page() { //given string[] arguments = {"get", "-url", "http://api.openweathermap.org/data/2.5/weather?q=paris&units=metric", "-save", @"C:\Users\erwan\abc.json"}; Command c = new Command(arguments); //when UrlOperations uo = new UrlOperations(c); uo.saveContent(); string line; string readFile = ""; // Read the file System.IO.StreamReader file = new System.IO.StreamReader(c.getSave()); while((line = file.ReadLine()) != null) { readFile += line; } file.Close(); //then Assert.AreEqual(uo.getContent(), readFile + "\n"); }
public void Should_find_the_file_created() { //given string[] arguments = {"get", "-url", "http://api.openweathermap.org/data/2.5/weather?q=paris&units=metric", "-save", @"C:\Users\erwan\abc.json"}; Command c = new Command(arguments); //when UrlOperations uo = new UrlOperations(c); uo.saveContent(); //then Assert.AreEqual(File.Exists(c.getSave()), true); }
public void Should_show_the_average_loading_time_of_a_page() { //given string[] arguments = {"test", "-url", "http://api.openweathermap.org/data/2.5/weather?q=paris&units=metric", "-times", "5"}; Command c = new Command(arguments); //when UrlOperations uo = new UrlOperations(c); double[] testTimes = {12,14,5,23,14}; double times = uo.avg(testTimes); //then Assert.AreEqual(times, 13.6); }
public Command(string[] _args) { uo = new UrlOperations(this); args = _args; //create parser parser = new CMDLineParser(); if(_args.Length != 0){ urlOpt = parser.AddStringParameter("-url", "adress of the website", true); if("get".Equals(_args[0]) || "test".Equals(_args[0])){ if("get".Equals(_args[0])){ getOpt=true; saveOpt = parser.AddStringParameter("-save", "save the content of the website", false); } if("test".Equals(_args[0])){ testOpt=true; timesOpt = parser.AddIntParameter("-times", "number of time to load the website", true); avgOpt = parser.AddBoolSwitch("-avg", "average time to load the website"); } try{ //parse the command line parser.Parse(args); } catch (CMDLineParser.CMDLineParserException ex){ getHelp(); Console.WriteLine("Error: " + ex.Message); return; } //replace argument list with remaining arguments args = parser.RemainingArgs(); } else { getHelp(); Console.WriteLine("Error: Missing Required option: 'get' or 'set'"); return; } } }
public void Should_show_the_loading_time_of_a_page_five_times() { //given string[] arguments = {"test", "-url", "http://api.openweathermap.org/data/2.5/weather?q=paris&units=metric", "-times", "5"}; Command c = new Command(arguments); //when UrlOperations uo = new UrlOperations(c); double[] times = uo.testLoadingTimeContent(); //then Assert.AreEqual(times.GetLength(0), c.getTime()); }
public void Should_show_the_content_of_a_page() { //given string[] arguments = {"get", "-url", "http://api.openweathermap.org/data/2.5/weather?q=paris&units=metric"}; Command c = new Command(arguments); //when UrlOperations uo = new UrlOperations(c); string result = uo.getContent(); //then Assert.AreEqual(uo.getContent(), "{\"coord\":{\"lon\":2.35,\"lat\":48.85},\"sys\":{\"message\":0.0366,\"country\":\"FR\",\"sunrise\":1401162895,\"sunset\":1401219641},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"base\":\"cmc stations\",\"main\":{\"temp\":13.93,\"humidity\":85,\"pressure\":1013.1,\"temp_min\":12.78,\"temp_max\":15},\"wind\":{\"speed\":6.92,\"deg\":276.501},\"rain\":{\"3h\":1},\"clouds\":{\"all\":92},\"dt\":1401184765,\"id\":2988507,\"name\":\"Paris\",\"cod\":200}" + "\n"); }