public void IfReturnWeather() { //Arrange Mock <IOpenWeatherServiceClient> client = new Mock <IOpenWeatherServiceClient>(); Mock <IGlobalWeatherServiceClient> globalClient = new Mock <IGlobalWeatherServiceClient>(); var weather = new WeatherOpenServiceResponse() { Dt = DateTime.Now, Coord = new Coord() { Lat = 1, Lon = 2 }, visibility = "Good" }; client.Setup(x => x.GetWeather(It.IsAny <string>())).Returns <string>((code) => weather); var finder = new OpenWeatherFinder(globalClient.Object, client.Object); //Act var result = finder.GetWeather("United Kingdom", "London"); //Asset Assert.AreEqual(result.Time, weather.Dt, "Time does not match."); Assert.IsTrue(result.Location.Contains(weather.Coord.Lat.ToString()), "Coordination does not match."); Assert.IsTrue(result.Visibility == weather.visibility, "Visibility does not match"); }
public Weather ConverToWeather(WeatherOpenServiceResponse data) { var separator = " -- "; var weather = new Weather() { Time = data.Dt, Location = data.Coord?.Lat + separator + data.Coord?.Lon, Wind = data.Wind?.Degree + separator + data.Wind?.Speed, Visibility = data.visibility, SkyConditions = data.Weather?.Select(x => x.Description + separator + x.Main).Aggregate((i, j) => i + separator + j), Temprature = (data.Main == null) ? 0 : data.Main.Temp, DewPoint = data.Main?.TempMin + separator + data.Main?.TempMax, RelativeHumidity = (data.Main == null) ? 0 : data.Main.Humidity, Pressure = (data.Main == null) ? 0 : data.Main.Pressure }; return(weather); }