public void CurrencyConversion_From_USD_To_MXN_Fails() { var result = CurrencyConversion.Convert( 42, CurrencyType.USD, CurrencyType.MXN); Assert.IsTrue(result.IsError); }
public void CurrencyConversion_From_CAD_To_MXN_Succeeds() { var result = CurrencyConversion.Convert( 42, CurrencyType.CAD, CurrencyType.MXN) .AssertOk(); Assert.AreEqual(420, result.Amount); }
public void CurrencyConversion_From_USD_To_CAD_Succeeds() { var result = CurrencyConversion.Convert( 42, CurrencyType.USD, CurrencyType.CAD) .AssertOk(); Assert.AreEqual(84, result.Amount); }
public async Task Convert(string amountInput, string fromInput, string ignoreThis, string toInput) { bool validFrom = Enum.TryParse(fromInput.ToUpper(), out CoinType from); bool validTo = Enum.TryParse(toInput.ToUpper(), out CoinType to); bool validAmount = double.TryParse(amountInput, out double amount); if (!validFrom) { await ReplyAsync(string.Format("'{0}' is not a valid currency", fromInput)); } else if (!validTo) { await ReplyAsync(string.Format("'{0}' is not a valid currency", toInput)); } else if (!validAmount || amount < 0) { await ReplyAsync("The amount you gave is invalid"); } else if (amount % 1 != 0) { await ReplyAsync("Please use whole numbers, you can't have half a coin. Convert to smaller coin values if you need to"); } else if (amount >= 1000000000000000) { await ReplyAsync("The amount you gave is too large"); } else { ConversionResult result = CurrencyConversion.Convert(from, to, amount); string reply = string.Format("{0:n0} {1} is {2:n0} {3}", amount, from.ToTileString(), result.result, result.resultCurrency.ToTileString()); List <string> remainders = new List <string>(); for (int i = result.remainders.Length - 1; i >= 0; i--) { if (result.remainders[i] != 0) { remainders.Add(string.Format("{0:n0} {1}", result.remainders[i], ((CoinType)i).ToTileString())); } } if (remainders.Count > 0) { for (int i = 0; i < remainders.Count - 1; i++) { reply += ", " + remainders[i]; } reply += " and " + remainders[remainders.Count - 1]; } await ReplyAsync(reply); } }