Beispiel #1
0
        public void FiveDigitNumberTest()
        {
            //Arrange
            CurrencyNumbersToWords model = new CurrencyNumbersToWords();

            model.CurrencyNumber = "45 100";

            //Act
            UnitTesConverterService.ConverterServiceReference.ServiceClient svc = new UnitTesConverterService.ConverterServiceReference.ServiceClient();
            var output = svc.ConvertCurrencyNumbersToWords(model.CurrencyNumber);

            //Assertfourty-five thousand one hundred  dollars
            Assert.AreEqual(output.Result, "fourty-five thousand one hundred dollars");
        }
Beispiel #2
0
        public void MaxAllowedNumberTest()
        {
            //Arrange
            CurrencyNumbersToWords model = new CurrencyNumbersToWords();

            model.CurrencyNumber = "999 999 999,99";

            //Act
            ServiceClient svc    = new ServiceClient();
            var           output = svc.ConvertCurrencyNumbersToWords(model.CurrencyNumber);

            //Assert
            Assert.AreEqual(output.Result, "nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine dollars and ninety-nine cents");
        }
Beispiel #3
0
    public CurrencyNumbersToWords ConvertCurrencyNumbersToWords(string currencyNumber)
    {
        CurrencyNumbersToWords response = new CurrencyNumbersToWords();
        string isNegative = "";

        try
        {
            string number = currencyNumber.Replace(',', '.').Trim().Replace(" ", "");

            if (number.Contains('.'))
            {
                number = Convert.ToDouble(number).ToString(".00");
            }
            else
            {
                number = Convert.ToDouble(number).ToString();
            }

            if (number.Contains("-"))
            {
                isNegative = "Minus ";
                number     = number.Substring(1, number.Length - 1);
            }
            if (number == "0")
            {
                response.Result = "zero dollar";
            }
            else
            {
                response.Result = (isNegative + ConvertToWords(number)).ToLower();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        return(response);
    }