コード例 #1
0
        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;
            }
        }
コード例 #2
0
        public void TestKelvinToFahrenheit()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(278.15);
            Assert.AreEqual(41.0, temperatureConverter.KelvinToFahrenheit());
        }
コード例 #3
0
        public void TestKelvinToCelcius()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(345.15);
            Assert.AreEqual(72.0, temperatureConverter.KelvinToCelcius());
        }
コード例 #4
0
        public void TestFahrenheitToKelvin()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(41.0);
            Assert.AreEqual(278.15, temperatureConverter.FahrenheitToKelvin());
        }
コード例 #5
0
        public void TestFahrenheitToCelcius()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(41.0);
            Assert.AreEqual(5.0, temperatureConverter.FahrenheitToCelcius());
        }
コード例 #6
0
        public void TestCelciusToKelvin()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(10.0);
            Assert.AreEqual(283.15, temperatureConverter.CelciusToKelvin());
        }
コード例 #7
0
        public void TestCelciusToFahrenheit()
        {
            var temperatureConverter = new TemperatureConverter();

            temperatureConverter.SetTemperature(12.0);
            Assert.AreEqual(53.6, temperatureConverter.CelciusToFahrenheit());
        }
コード例 #8
0
 public FormTemperature()
 {
     InitializeComponent();
     AddUnitsToComboBox(comboBoxConvertFrom);
     AddUnitsToComboBox(comboBoxConvertTo);
     _temperatureConverter = new TemperatureConverter();
     _temperatureConverter.SetTemperature(0);
     textBoxValue.Text = "0";
 }