コード例 #1
0
 /// <summary>
 /// Converts a cash amount to the account currency
 /// </summary>
 /// <param name="cashAmount">The <see cref="CashAmount"/> instance to convert</param>
 /// <returns>A new <see cref="CashAmount"/> instance denominated in the account currency</returns>
 public CashAmount ConvertToAccountCurrency(CashAmount cashAmount)
 {
     throw new InvalidOperationException($"This method purposefully throws as a proof that a " +
                                         $"test does not depend on {nameof(ICurrencyConverter)}.If this exception is encountered, " +
                                         $"it means the test DOES depend on {nameof(ICurrencyConverter)} and should be properly " +
                                         $"updated to use a real implementation of {nameof(ICurrencyConverter)}.");
 }
コード例 #2
0
        /// <summary>
        /// Converts a cash amount to the account currency.
        /// This implementation can only handle cash amounts in units of the account currency.
        /// </summary>
        /// <param name="cashAmount">The <see cref="CashAmount"/> instance to convert</param>
        /// <returns>A new <see cref="CashAmount"/> instance denominated in the account currency</returns>
        public CashAmount ConvertToAccountCurrency(CashAmount cashAmount)
        {
            if (!string.Equals(cashAmount.Currency, _accountCurrency, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException($"The {nameof(IdentityCurrencyConverter)} can only handle CashAmounts in units of the account currency");
            }

            return(cashAmount);
        }
コード例 #3
0
        /// <summary>
        /// Converts a cash amount to the account currency
        /// </summary>
        /// <param name="cashAmount">The <see cref="CashAmount"/> instance to convert</param>
        /// <returns>A new <see cref="CashAmount"/> instance denominated in the account currency</returns>
        public CashAmount ConvertToAccountCurrency(CashAmount cashAmount)
        {
            if (cashAmount.Currency == AccountCurrency)
            {
                return(cashAmount);
            }

            var amount = Convert(cashAmount.Amount, cashAmount.Currency, AccountCurrency);

            return(new CashAmount(amount, AccountCurrency));
        }