Exemple #1
0
        public void Temperature_Typical_Converts(decimal actualTemperature, decimal expectedTemperature, UnitType fromUnitType, UnitType toUnitType)
        {
            // arrange
            var address = new Address();
            var weatherServiceMock = new Mock<IWeatherService>();
            var fahrenheitWeather = new WeatherInfoModel { UnitType = fromUnitType, Temperature = actualTemperature, };
            weatherServiceMock.Setup(m => m.GetCurrentWeatherByLocation(It.IsAny<decimal>(), It.IsAny<decimal>())).Returns(fahrenheitWeather);

            var weather = new Weather(UnitType.Fahrenheit, address, weatherServiceMock.Object);

            // act
            var currentWeather = weather.GetCurrentWeather();
            currentWeather = weather.ConvertTo(toUnitType, currentWeather);

            // assert
            Assert.That(currentWeather.Temperature, Is.EqualTo(expectedTemperature), "Wrong Temperature");

        }
Exemple #2
0
 public WeatherInfoModel ConvertTo(UnitType unitType, WeatherInfoModel model)
 {
     switch (unitType)
     {
         case UnitType.Celsius:
             _unitType = model.UnitType = UnitType.Celsius;
             var celsius = (model.Temperature - 32) / 1.8m;
             model.Temperature = celsius;
             return model;
         case UnitType.Fahrenheit:
             _unitType = model.UnitType = UnitType.Fahrenheit;
             var fahrenheit = model.Temperature * 1.8m + 32;
             model.Temperature = fahrenheit;
             return model;
         default:
             throw new ArgumentOutOfRangeException("Unsupported Unit Type");
     }
 }
Exemple #3
0
        public WeatherInfoModel ConvertTo(UnitType unitType, WeatherInfoModel model)
        {
            switch (unitType)
            {
            case UnitType.Celsius:
                _unitType = model.UnitType = UnitType.Celsius;
                var celsius = (model.Temperature - 32) / 1.8m;
                model.Temperature = celsius;
                return(model);

            case UnitType.Fahrenheit:
                _unitType = model.UnitType = UnitType.Fahrenheit;
                var fahrenheit = model.Temperature * 1.8m + 32;
                model.Temperature = fahrenheit;
                return(model);

            default:
                throw new ArgumentOutOfRangeException("Unsupported Unit Type");
            }
        }