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 UrlOperations(Command _c) { c = _c; client = new WebClient(); sw = new Stopwatch(); }
public static void Main(string[] args) { Command c = new Command(args); c.execute(); }
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"); }