Пример #1
0
        public void Calculator(string hasChanged)
        {
            try
            {
                //Sees if user wants to calculate from base value or quote value.
                //Checks if the values in the textboxes are correct for calling the calculate method.
                if ("BaseValue" == hasChanged && BaseValue != "." && BaseValue != "")
                {
                    QuoteValue = CurrenciesCalculator.CalculateQuoteValue(BaseValue, Rate).
                                 ToString(CultureInfo.GetCultureInfo("en-US"));
                }

                else if ("QuoteValue" == hasChanged && QuoteValue != "." && QuoteValue != "")
                {
                    BaseValue = CurrenciesCalculator.CalculateBaseValue(QuoteValue, Rate).
                                ToString(CultureInfo.GetCultureInfo("en-US"));
                }
                //If not, it clears them.
                else
                {
                    BaseValue  = "";
                    QuoteValue = "";
                }
            }
            catch (OverflowException)
            {
                MessageBox.Show("The input value is out of the accepted range.", "Error");
                BaseValue  = "";
                QuoteValue = "";
            }
            catch (FormatException)
            {
                MessageBox.Show($"The input value is invalid. Use only digits or point  \".\" as decimal separator. "
                                + $"For example: 15.34 ", "Error");
                BaseValue  = "";
                QuoteValue = "";
            }
            catch (DivideByZeroException)
            {
                MessageBox.Show("Couldn't retrieve the requested results (rate = 0).", "Error");
            }
            catch (Exception)
            {
                MessageBox.Show("Couldn't retrieve the requested results.", "Error");
            }
        }
Пример #2
0
 public void CalculateQuoteValue_ShouldThrowFormatException()
 {
     Assert.Throws <FormatException>(() => CurrenciesCalculator.CalculateQuoteValue("a", 0.5M));
 }
Пример #3
0
 public void CalculateQuoteValue_ShouldThrowOverflowException()
 {
     Assert.Throws <OverflowException>(() => CurrenciesCalculator.CalculateQuoteValue("99999999999999999999999999", 999999999999999));
 }
Пример #4
0
        [InlineData("7.578945", 4.2437, 32.1628)] // result is 32.162768 etc, but it is rounded.


        public void CalculateQuoteValue_ShouldCalculate(string baseValue, decimal rate, decimal expected)
        {
            decimal actual = CurrenciesCalculator.CalculateQuoteValue(baseValue, rate);

            Assert.Equal(expected, actual);
        }