Пример #1
0
        public void RequestsDelayTest()
        {
            var mock = new Mock <IWebServiceHandler>();

            mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest);
            mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData);

            WebWeather weather = new WebWeather(mock.Object);

            weather.FetchWeatherData();
            System.Threading.Thread.Sleep(100);
            weather.FetchWeatherData();

            mock.Verify(mock => mock.ParseJSONObject(It.IsAny <string>()), Times.Once());

            Assert.Pass();
        }
Пример #2
0
        public void FetchWeatherDataTest()
        {
            var mock = new Mock <IWebServiceHandler>();

            mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest);
            mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData);

            WebWeather weather = new WebWeather(mock.Object);

            var data = weather.FetchWeatherData();

            Assert.NotNull(data);
            Assert.AreEqual(HumidityData.Humidity, data.Humidity);
        }
Пример #3
0
        public void ErrorHandlingTest()
        {
            var mock = new Mock <IWebServiceHandler>();

            mock.Setup(x => x.GetServiceRequestInfo()).Returns(UnauthorizedRequest);

            WebWeather weather = new WebWeather(mock.Object);

            weather.FetchWeatherData();

            var status = weather.GetLastLog();

            Assert.NotNull(status);
            Assert.AreEqual(FetchWeatherStatus.Error, status.Status);
        }
Пример #4
0
        public void LastLogBehaviourTest()
        {
            var mock = new Mock <IWebServiceHandler>();

            mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest);
            mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns(HumidityData);

            WebWeather weather = new WebWeather(mock.Object);

            Assert.Null(weather.GetLastLog());
            weather.FetchWeatherData();

            var status = weather.GetLastLog();

            Assert.NotNull(status);
            Assert.AreEqual(FetchWeatherStatus.Success, status.Status);
        }
Пример #5
0
        public void ParseErrorDataTest()
        {
            var mock = new Mock <IWebServiceHandler>();

            mock.Setup(x => x.GetServiceRequestInfo()).Returns(NormalRequest);
            mock.Setup(x => x.ParseJSONObject(It.IsAny <string>())).Returns((WeatherDataContainer?)null);

            WebWeather weather = new WebWeather(mock.Object);

            var data = weather.FetchWeatherData();

            Assert.Null(data);

            var log = weather.GetLastLog();

            Assert.NotNull(log);
            Assert.AreEqual(FetchWeatherStatus.Error, log.Status);
        }