Exemple #1
0
        public void WeatherInfoCustomAttribute()
        {
            CsvParser <WeatherInfo> pastWeather = new CsvParser <WeatherInfo>();

            CsvCorrespondenceAttr <WeatherInfo> .MakeAttributeCorrespondence(pastWeather, typeof(WeatherInfo)); // this makes the correspondence between ctorArgs, fieldArgs and paramArgs

            IEnumerable <WeatherInfo> items = pastWeather
                                              .Load(sample1)
                                              .Parse();

            DateTime[] dates =
            {
                DateTime.Parse("2019-01-01"),
                DateTime.Parse("2019-01-02"),
                DateTime.Parse("2019-01-03"),
                DateTime.Parse("2019-01-04")
            };

            int[]    temps = new int[] { 17, 18, 16, 16 };
            double[] prec  = new double[] { 0.0, 0.0, 0.0, 0.1 };
            string[] desc  = new string[] { "Partly cloudy", "Partly cloudy", "Sunny", "Partly cloudy" };

            Assert.AreEqual(4, items.Count());

            int idx = 0;

            foreach (WeatherInfo wi in items)
            {
                Assert.AreEqual(temps[idx], wi.TempC);
                Assert.AreEqual(dates[idx], wi.Date);
                Assert.AreEqual(prec[idx], wi.PrecipMM);
                Assert.AreEqual(desc[idx++], wi.Desc);
            }

            ////date
            //Assert.AreEqual(17, ((WeatherInfo)items[0]).TempC);
            //Assert.AreEqual(18, ((WeatherInfo)items[1]).TempC);
            //Assert.AreEqual(16, ((WeatherInfo)items[2]).TempC);
            //Assert.AreEqual(16, ((WeatherInfo)items[3]).TempC);

            ////tempC
            //Assert.AreEqual(dates[0], ((WeatherInfo)items[0]).Date);
            //Assert.AreEqual(dates[1], ((WeatherInfo)items[1]).Date);
            //Assert.AreEqual(dates[2], ((WeatherInfo)items[2]).Date);
            //Assert.AreEqual(dates[3], ((WeatherInfo)items[3]).Date);

            ////PrecipMM
            //Assert.AreEqual(0.0, ((WeatherInfo)items[0]).PrecipMM);
            //Assert.AreEqual(0.0, ((WeatherInfo)items[1]).PrecipMM);
            //Assert.AreEqual(0.0, ((WeatherInfo)items[2]).PrecipMM);
            //Assert.AreEqual(0.1, ((WeatherInfo)items[3]).PrecipMM);

            ////Desc
            //Assert.AreEqual("Partly cloudy", ((WeatherInfo)items[0]).Desc);
            //Assert.AreEqual("Partly cloudy", ((WeatherInfo)items[1]).Desc);
            //Assert.AreEqual("Sunny", ((WeatherInfo)items[2]).Desc);
            //Assert.AreEqual("Partly cloudy", ((WeatherInfo)items[3]).Desc);
        }
Exemple #2
0
        public void LocationInfoCustomAttribute()
        {
            const string WEATHER_KEY  = "1368ef2d6f8a41d19a4171602191205";
            const string WEATHER_HOST = "http://api.worldweatheronline.com/premium/v1/";
            const string SEARCH       = WEATHER_HOST + "search.ashx?query={0}&format=tab&key=" + WEATHER_KEY;

            req = new HttpRequest();

            string path = SEARCH.Replace("{0}", "oporto");

            string body = req.GetBody(path);

            CsvParser <LocationInfo> location = new CsvParser <LocationInfo>('\t');

            CsvCorrespondenceAttr <LocationInfo> .MakeAttributeCorrespondence(location, typeof(LocationInfo)); // this makes the correspondence between ctorArgs, fieldArgs and paramArgs

            IEnumerable <LocationInfo> locationInfo = location
                                                      .Load(body)
                                                      .Remove(4)
                                                      .RemoveEmpties()
                                                      .Parse();

            Assert.AreEqual(6, locationInfo.Count());
        }