private void btnConvert_Click(object sender, EventArgs e) { double valueFromTextBox; try { if (String.IsNullOrEmpty(textBoxValue.Text)) { throw new Exception("Field cannot be empty"); } labelError.Text = ""; Double.TryParse(textBoxValue.Text, out valueFromTextBox); _temperatureConverter.SetTemperature(Double.Parse(textBoxValue.Text)); if (comboBoxConvertFrom.SelectedItem == null || comboBoxConvertTo.SelectedItem == null) { throw new ArgumentNullException(null, "Pick a unit!"); } labelResult.Text = Math.Round(_temperatureConverter.HandleConverter( comboBoxConvertFrom.SelectedItem.ToString(), comboBoxConvertTo.SelectedItem.ToString()), 2).ToString(); } catch (ArgumentNullException ex) { labelError.Text = ex.Message; } catch (Exception ex) { labelError.Text = ex.Message; } }
public void TestKelvinToFahrenheit() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(278.15); Assert.AreEqual(41.0, temperatureConverter.KelvinToFahrenheit()); }
public void TestKelvinToCelcius() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(345.15); Assert.AreEqual(72.0, temperatureConverter.KelvinToCelcius()); }
public void TestFahrenheitToKelvin() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(41.0); Assert.AreEqual(278.15, temperatureConverter.FahrenheitToKelvin()); }
public void TestFahrenheitToCelcius() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(41.0); Assert.AreEqual(5.0, temperatureConverter.FahrenheitToCelcius()); }
public void TestCelciusToKelvin() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(10.0); Assert.AreEqual(283.15, temperatureConverter.CelciusToKelvin()); }
public void TestCelciusToFahrenheit() { var temperatureConverter = new TemperatureConverter(); temperatureConverter.SetTemperature(12.0); Assert.AreEqual(53.6, temperatureConverter.CelciusToFahrenheit()); }
public FormTemperature() { InitializeComponent(); AddUnitsToComboBox(comboBoxConvertFrom); AddUnitsToComboBox(comboBoxConvertTo); _temperatureConverter = new TemperatureConverter(); _temperatureConverter.SetTemperature(0); textBoxValue.Text = "0"; }