Esempio n. 1
0
        static void Main(string[] args)
        {
            // Storage
            byte[] bytes;

            // New weather
            var weather = new WeatherData
            {
                Summary       = "Sunny",
                TemperatureF  = 70,
                DateTimeStamp = Timestamp.FromDateTime(DateTime.UtcNow)
            };

            // Save to buffer
            using (var memoryStream = new MemoryStream())
            {
                weather.WriteTo(memoryStream);
                bytes = memoryStream.ToArray();
            }

            // Copy from buffer
            var weatherCopy = WeatherData.Parser.ParseFrom(bytes);

            // Perform deep-comparison on equality
            var areEqual = weather.Equals(weatherCopy);

            Console.WriteLine($"Original Weather and copy are equal: {areEqual}");
        }
Esempio n. 2
0
        public async Task <ActionResult> Details()
        {
            try
            {
                var showWeather = new WeatherData();
                showWeather.name = TempData["CityName"].ToString();
                TempData.Remove("CityName");
                showWeather = await Seed.PopulateWeatherModel(showWeather.name);

                if (!showWeather.Equals(null))
                {
                    return(View(showWeather));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (NullReferenceException)
            {
                return(NotFound());
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Esempio n. 3
0
        public void GetWeatherDataGeoTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new GeoCoordinations(35, 139));
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?lat=35&lon=139&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Esempio n. 4
0
        public void GetWeatherDataIdTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(524901);
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?id=524901&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Esempio n. 5
0
        public void GetWeatherDataLocTest()
        {
            IWeatherDataService n      = new WeatherDataServiceFactory().GetWeatherDataService(1);
            WeatherData         target = n.GetWeatherData(new Location("Haifa", "il"));
            WeatherData         wd     = GetWeatherDataForTest("http://api.openweathermap.org/data/2.5/forecast?q=haifa,il&mode=xml");

            //compare the two WeatherData objects
            Assert.IsTrue(wd.Equals(target));
        }
Esempio n. 6
0
        private static void Main(string[] args)
        {
            WeatherData data1 = new WeatherData()
            {
                Temperature = 28.5,
                Humidity    = 100,
                Pressure    = 1
            };

            WeatherData data2 = new WeatherData()
            {
                Temperature = 29.5,
                Humidity    = 10,
                Pressure    = 2
            };

            Console.WriteLine(data1.Equals(data2));
            if (data1.Equals(data2))
            {
                Console.WriteLine("data1 等於 data2");
            }
            else
            {
                Console.WriteLine("data1 不等於 data2");

                if (data1.Temperature != data2.Temperature)
                {
                    Console.WriteLine("溫度不相等");
                }
                if (data1.Humidity != data2.Humidity)
                {
                    Console.WriteLine("溼度發生變化");
                }
                if (data1.Pressure != data2.Pressure)
                {
                    Console.WriteLine("壓力發生變化");
                }
            }
        }
        public void GetWeatherDataValueTest()
        {
            // get the weather data in London using the GetWeatherData function
            WeatherDataServiceFactory factory        = new WeatherDataServiceFactory();
            IWeatherDataService       weatherService = factory.GetWeatherDataService(WeatherDataServiceFactory.ServiceType.OpenWeatherMap);
            Location    locationTest      = new Location("London", "UK");
            WeatherData weatherDataToTest = weatherService.GetWeatherData(locationTest);
            // get the weather data in London from the website
            string      url        = "http://api.openweathermap.org/data/2.5/weather?q=" + locationTest.City + "," + locationTest.Country + "&mode=xml";
            WeatherData weatherSrc = GetWeatherByUrlForTesting(url);

            Assert.IsTrue(weatherSrc.Equals(weatherDataToTest));
        }