Пример #1
0
        public void GetDataFromTomorrowIoTest()
        {
            var fakeSite = new Mock <IRequest>();

            fakeSite.Setup(r => r.Connected).Returns(true);
            fakeSite.Setup(r => r.Response).Returns("{\"data\":{\"timelines\":[{\"timestep\":\"current\",\"endTime\":\"2022 - 04 - 28T20: 33:00Z\",\"startTime\":\"2022 - 04 - 28T20: 33:00Z\",\"intervals\":[{\"startTime\":\"2022 - 04 - 28T20: 33:00Z\",\"values\":{\"cloudCover\":100,\"humidity\":50,\"precipitationType\":2,\"temperature\":2.31,\"windDirection\":184.5,\"windSpeed\":2.63}}]}]}}");
            TomorrowIo tomorrowIo = new TomorrowIo(fakeSite.Object);
            Weather    data       = tomorrowIo.GetData();
            var        correct    = new Weather(2.31, 36.16, 100, 50, 2.63, "S", "Snow");

            Assert.AreEqual(correct.TemperatureCelsius, data.TemperatureCelsius);
            Assert.AreEqual(correct.Humidity, data.Humidity);
            Assert.AreEqual(correct.TemperatureFahrenheit, data.TemperatureFahrenheit);
            Assert.AreEqual(correct.CloudCover, data.CloudCover);
            Assert.AreEqual(correct.WindSpeed, data.WindSpeed);
            Assert.AreEqual(correct.WindDirection, data.WindDirection);
            Assert.AreEqual(correct.Precipitation, data.Precipitation);

            fakeSite.Setup(r => r.Connected).Returns(false);
            try
            {
                tomorrowIo.GetData();
            }
            catch
            {
                Assert.Pass();
            }
            Assert.Fail();
        }
Пример #2
0
        public void CheckPrecipitationTypeTest(int type, string precipitation)
        {
            var fakeSite = new Mock <IRequest>();

            fakeSite.Setup(r => r.Connected).Returns(true);
            fakeSite.Setup(r => r.Response).Returns("{\"data\":{\"timelines\":[{\"timestep\":\"current\",\"endTime\":\"2022 - 04 - 28T20: 33:00Z\",\"startTime\":\"2022 - 04 - 28T20: 33:00Z\",\"intervals\":[{\"startTime\":\"2022 - 04 - 28T20: 33:00Z\",\"values\":{\"cloudCover\":100,\"humidity\":50,\"precipitationType\":" + Convert.ToString(type) + ",\"temperature\":2.31,\"windDirection\":184.5,\"windSpeed\":2.63}}]}]}}");
            TomorrowIo tomorrowIo = new TomorrowIo(fakeSite.Object);
            Weather    data       = tomorrowIo.GetData();

            var correct = new Weather(2.31, 36.16, 100, 50, 2.63, "S", precipitation);

            Assert.AreEqual(correct.Precipitation, data.Precipitation);

            Assert.Pass();
        }